Repository navigation
v0.28.0
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: durationis atypes.Durationfrom this module'spkg/types, read and written as an ISO 8601 duration such asPT1H30M, where atime.Durationfield rejected every JSON string. JSON can also give a number of nanoseconds, and YAML a duration in Go's syntax, such as1h30m, as for atime.Duration. It is written to JSON as a string, not a number.- An
anyOforoneOfon a primitive whose branches only check its values, such as{"type": "string", "oneOf": [{"const": "a"}, {"const": "b"}]}, keeps its type; theanyOfwasinterface{}. A declared one does too, so an optional field of it becomes a pointer, and the unused types generated for itsenumbranches, 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 isinterface{}with a warning.
Accepted now, which v0.27.0 rejected:
- In JSON, a zero with any exponent, such as
0e99, and values near theint64limits. A bound with a fraction lets through the integers it allows:maximum: 2.5lets 2 through. - In YAML, a number for a string value of
AdditionalProperties, as for a declared string property. - A document that one
anyOfbranch accepts where another branch's keywords bound every instance,nullfor a definition without a type that ananyOfhad 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.5as 2. InAdditionalProperties,2.5or1e300for an integer, which were truncated or wrapped. An integer that a bound with a fraction, or one beyond 2^53, excludes, such as 2 forminimum: 2.5. maxLength: 0andmaxItems: 0, which read as no limit; an integer'smultipleOfwith a fraction, such as 2 for2.5; values inside anallOfnested in anallOf; and ananyOfobject's keywords on a property that a branch declares as well.- A
requiredname that no property declares, and ananyOforoneOfon a primitive as above: a value must match a branch of theanyOf, and exactly one branch of theoneOf. - Under
--validate-null-types,nullfor a definition used directly that a nullable union also refers to, and for a property whose$refpoints into another file and excludes it.
Fixes and warnings:
- In JSON, a decode that fails on an integer written
2.0is retried with only those numbers written again, so ajson.RawMessagekeeps its form, and an error names a number as the input writes it. - Schemas with counts written
2.0or2e0, such asminItems, and files that are onlytrueorfalse, 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
multipleOfbelow 1, a default of a named pointer type, and ananyOfwith a branch declared as a pointer or asinterface{}. Such ananyOfadmits every value and is left unchecked, with a warning. - Keywords on a schema with no
typethat becomesinterface{}, such aspattern,minimumorrequired, 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