Skip to content

v0.28.0

Choose a tag to compare

@github-actions github-actions released this 02 Nov 19:43
· 47 commits to main since this release
74d5121

The fork's fourth stable release, from the same commit as v0.28.0-rc.3.

Compared with v0.27.0, the generated code decodes integers exactly, reads schemas and merges allOf and anyOf as JSON Schema defines them, checks several things the generator skipped, and reads format: duration as ISO 8601. The tests now run the JSON-Schema-Test-Suite's draft-07 tests through generated code, and compare the generated code with a reference validator, on the fixtures and every week on SchemaStore's schemas. They found most of the defects below. The README lists every difference from upstream.

Changed types:

  • format: duration is a types.Duration from this module's pkg/types, read and written as an ISO 8601 duration such as PT1H30M, where a time.Duration field rejected every JSON string. JSON can also give a number of nanoseconds, and YAML a duration in Go's syntax, such as 1h30m, as for a time.Duration. It is written to JSON as a string, not a number.
  • An anyOf or oneOf on a primitive whose branches only check its values, such as {"type": "string", "oneOf": [{"const": "a"}, {"const": "b"}]}, keeps its type; the anyOf was interface{}. A declared one does too, so an optional field of it becomes a pointer, and the unused types generated for its enum branches, with their constants, are gone.
  • In a struct merged from an anyOf, a property's Go type follows the object's own schema for it, or, for a property that only branches declare, the first branch that declares it, holding what the others declare in it.
  • A type list of two types without null, such as ["integer", "string"], kept only its last type at the root, in a definition and for the values of a map. Where no union wrapper holds both, it is interface{} with a warning.

Accepted now, which v0.27.0 rejected:

  • In JSON, a zero with any exponent, such as 0e99, and values near the int64 limits. A bound with a fraction lets through the integers it allows: maximum: 2.5 lets 2 through.
  • In YAML, a number for a string value of AdditionalProperties, as for a declared string property.
  • A document that one anyOf branch accepts where another branch's keywords bound every instance, null for a definition without a type that an anyOf had given its parent's type, and a value of either type of a two-type list.
  • An ISO 8601 duration, in JSON and YAML.

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

  • In YAML, a float that holds no integer, or one past the Go type's range, for an integer; yaml.v3 decoded 2.5 as 2. In AdditionalProperties, 2.5 or 1e300 for an integer, which were truncated or wrapped. An integer that a bound with a fraction, or one beyond 2^53, excludes, such as 2 for minimum: 2.5.
  • maxLength: 0 and maxItems: 0, which read as no limit; an integer's multipleOf with a fraction, such as 2 for 2.5; values inside an allOf nested in an allOf; and an anyOf object's keywords on a property that a branch declares as well.
  • A required name that no property declares, and an anyOf or oneOf on a primitive as above: a value must match a branch of the anyOf, and exactly one branch of the oneOf.
  • Under --validate-null-types, null for a definition used directly that a nullable union also refers to, and for a property whose $ref points into another file and excludes it.

Fixes and warnings:

  • In JSON, a decode that fails on an integer written 2.0 is retried with only those numbers written again, so a json.RawMessage keeps its form, and an error names a number as the input writes it.
  • Schemas with counts written 2.0 or 2e0, such as minItems, and files that are only true or false, load. A count that holds no integer is an error that names the keyword.
  • A property that a schema declares under the name additionalProperties, as Kubernetes' CRD schema does, decodes like any other.
  • Generated code compiles for an integer's multipleOf below 1, a default of a named pointer type, and an anyOf with a branch declared as a pointer or as interface{}. Such an anyOf admits every value and is left unchecked, with a warning.
  • Keywords on a schema with no type that becomes interface{}, such as pattern, minimum or required, get a fidelity warning.

Built with Go 1.26.10 and checked with govulncheck before it was published.

Changelog

  • 37fbf56 Merge pull request #66 from plheide/docs/readme-image-tag
  • ea93e8f Merge pull request #67 from plheide/test/v028-suite-conformance
  • 267d0c9 Merge pull request #68 from plheide/test/v028-differential
  • aae6f9f Merge pull request #69 from plheide/test/v028-corpus
  • 5a42d6c Merge pull request #70 from plheide/fix/v028-integers
  • 75fad42 Merge pull request #72 from plheide/fix/v028-merging
  • 74d5121 Merge pull request #73 from plheide/fix/v028-checks
  • de456af docs(fork): name v0.27.0 in the container image example
  • 7710827 feat: warn about keywords on a schema with no type
  • 7b76db7 fix: check a null through a $ref into another file
  • f9641fd fix: check an anyOf or oneOf of a primitive's values
  • 1d3b6c6 fix: check required names that no property declares
  • d34f2a3 fix: compile an anyOf with a branch declared as a pointer or interface{}
  • 61fc94f fix: decode integral numbers exactly, also in YAML and map values
  • 36bb873 fix: document a merged property as an anyOf branch does
  • 0ed83b7 fix: merge nested allOfs, and anyOfs without changing what they read
  • 1406e30 fix: read an integer's bounds as the schema writes them
  • a2800d4 fix: read and write format duration as ISO 8601
  • baff035 fix: read counts, multipleOf, type lists and boolean schemas as defined
  • 88da153 fix: write a default of a named pointer type through a variable