v3.0.0
Breaking
-
(
t.object
) AddadditionalProperties: false
by default when properties are defined (#5): bc4dc26
This is breaking because whenadditionalProperties
is left unspecified, JSON schema treats it asadditionalProperties: true
.
It was changed to match the "schema" concept, in that users generally only want to allow the properties known/defined in their schema. To allow extra properties, simply addadditionalProperties: true
in the options parameter:// Accept any object t.object(); //-> { type: "object" } // Accept an object of defined shape t.object({ name: t.string(), }); //-> { //-> type: "object", //-> additionalProperties: false, // << //-> required: ["name"], //-> properties: { //-> name: { type: "string" } //-> } //-> } // Accept an object of given shape, but allow extra properties t.object({ name: t.string(), }, { additionalProperties: true, }); //-> { //-> type: "object", //-> additionalProperties: true, // << //-> required: ["name"], //-> properties: { //-> name: { type: "string" } //-> } //-> }
-
(
t.tuple
) Modify JSON schema output to enforce tuple length (#7): bf3663a
While this could be classified as a patch fix, it's technically breaking as the default2.x
output generated looser JSON schema tuple definitions which, by default, allowed for fewer and/or extra items to still be considered valid. This doesn't match the TypeScript (or most languages') concept of a tuple, so this release'st.tuple()
default output has been changed.
However,minItems
andmaxItems
are still configurable thru options if you wish to change them.t.tuple([t.string(), t.number()]); // Before (2.x) // Allows any array length //-> { //-> type: "array", //-> prefixItems: [ //-> { type: "string" }, //-> { type: "number" }, //-> }] //-> } // After (3.0) // Requires 2 items //-> { //-> type: "array", //-> prefixItems: [ //-> { type: "string" }, //-> { type: "number" }, //-> }], //-> minItems: 2, //-> maxItems: 2 //-> }
Chores
- Add
zod-to-json-schema
to benchmark: 4a27c67
Full Changelog: v2.1.0...v3.0.0