Skip to content

v0.27.0

Choose a tag to compare

@github-actions github-actions released this 27 Oct 20:26
· 71 commits to main since this release
eb68045

The fork's third stable release, from the same commit as v0.27.0-rc.4.

Compared with v0.26.0, the generated code decodes integers that JSON Schema accepts, checks the values that arrays and maps hold, writes output that its schema accepts, and the generator reports the keywords it does not check. The README lists every difference from upstream.

New in the generated code:

  • A property whose const is a string, a number, an integer or a boolean has an exported, untyped constant named after the struct and the field, such as ConfigSchema for a $schema URL.
  • A required array or object whose type excludes null is written to JSON as [] or {} when it is nil. encoding/json wrote null, which the schema rejects.
  • --use-number (opt-in, Config.UseNumber) decodes the numbers of untyped values from JSON as json.Number, at any depth, which keeps integers beyond 2^53 exact.
  • A property with typed additionalProperties and a default starts as an empty value of its own Go type, such as Headers{}. The code generated for it did not compile for a declared map type, a map of another element type, or a struct.

Accepted now, which v0.26.0 rejected:

  • An integer written with a fraction or an exponent, such as 2.0 or 1e2, is decoded from JSON, as JSON Schema counts it as an integer.
  • A nested array is held to its own minItems and maxItems, not to the property's.
  • A const that a float64 rounds, such as 9007199254740993, is kept as written, so the const itself is no longer rejected, in YAML or by the check of an integer property.

New checks, which reject input that v0.26.0 accepted:

  • The keywords of the values that arrays and maps hold are checked at every depth: minLength, maxLength, pattern, minimum, maximum and their exclusive forms, multipleOf and const.
  • uniqueItems is checked. Items are compared as JSON, so 1 and 1.0 are equal, and numbers exactly, so integers beyond 2^53 stay distinct.
  • A const on a schema that declares no type is checked, as JSON. A number that merely rounds to it, such as 1.0000000000000000001 for 1, fails where the number is read exactly: in a JSON property, and in an element under --use-number.
  • A struct merged from an anyOf checks the object's own keywords, except those of a property that a branch declares as well, which a fidelity warning reports.
  • A conditional discriminator also compiles when it is keyed on a property that a nested object holds, such as meta.status. Where the discriminator is absent, an if that requires it is false, so its else applies, and one that does not is true, vacuously, so its then applies.

New warnings:

  • A type that declares a keyword that no generated code checks is reported once, such as schema fidelity: type Config does not enforce all it declares: minProperties, propertyNames not checked. This covers contains (with minContains and maxContains), dependentRequired and dependentSchemas (and draft 07's dependencies), maxProperties, minProperties, patternProperties, propertyNames, unevaluatedItems and unevaluatedProperties. A type that falls back to interface{} names them among what it drops.

Built with Go 1.26.10 and checked with govulncheck before it was published, as v0.26.0 was.

Install with go install github.com/plheide/go-jsonschema@v0.27.0, from the assets below, or as the plheide/go-jsonschema or ghcr.io/plheide/go-jsonschema image.

The fork is a staging area for work offered upstream. FORK.md lists what isn't offered yet.

Changelog

  • 880adc4 Merge pull request #61 from plheide/fix/v027-decoding
  • 83d1789 Merge pull request #62 from plheide/fix/v027-checks
  • 0af93ce Merge pull request #63 from plheide/fix/v027-conditionals
  • ef09cdc Merge pull request #64 from plheide/fix/v027-producer
  • eb68045 Merge pull request #65 from plheide/fix/v027-visibility
  • ed708c1 feat: check the values arrays and maps hold, at every depth
  • 7d8e7c5 feat: check uniqueItems
  • 49bf01d feat: compile a conditional keyed on a property a nested object holds
  • d791ff8 feat: compile an if that holds vacuously on an absent discriminator
  • e8a3ea8 feat: declare a constant for each property's const
  • 8ac78b7 feat: decode untyped numbers exactly with --use-number
  • ff7fae9 fix: check the object's own keywords on a struct merged from an anyOf
  • a8cc3f9 fix: compare a const beyond float64's precision exactly
  • c288920 fix: decode an integer written 2.0 or 1e2 from JSON
  • d7d7a94 fix: warn about keywords that no generated code checks
  • 7e51b31 fix: write a map property's default as a value of its own type
  • 53d3231 fix: write a required array or object left nil as empty, not null