We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"additionalProperties": false
See also: #64, #65.
Reproduction:
const left = z.union([ z.object({ field1: z.number() }), z.object({ field3: z.string() }), ]); const right = z.object({ field2: z.boolean() }); const intersection = z.intersection(left, right); const schema = zodToJsonSchema(intersection);
Generates the following schema:
{ "allOf": [ { "anyOf": [ { "type": "object", "properties": { "field1": { "type": "number" } }, "required": ["field1"], "additionalProperties": false }, { "type": "object", "properties": { "field3": { "type": "string" } }, "required": ["field3"], "additionalProperties": false } ] }, { "type": "object", "properties": { "field2": { "type": "boolean" } }, "required": ["field2"] } ], "$schema": "http://json-schema.org/draft-07/schema#" }
Because of "additionalProperties": false, no object can be successfully validated against this schema: https://www.jsonschemavalidator.net/s/ddO3vtM2
Compared to schema with removed additionalProperties: https://www.jsonschemavalidator.net/s/UO8HV6Lz
additionalProperties
The text was updated successfully, but these errors were encountered:
We are experiencing the same issue. Is there a known workaround?
Sorry, something went wrong.
Currently I'm just removing additionalProperties: false from generated schemas:
additionalProperties: false
function deepRemoveKeys(obj, exclude) { if (obj instanceof Array) { return obj.map((i) => deepRemoveKeys(i, exclude)); } if (typeof obj === "object") { return Object.fromEntries( Object.entries(obj) .filter( ([k, v]) => !(k in exclude && (exclude[k] === undefined || exclude[k] === v)) ) .map(([k, v]) => [k, deepRemoveKeys(v, exclude)]) ); } return obj; } const schema = deepRemoveKeys(zodToJsonSchema(obj), { additionalProperties: false });
allOf
No branches or pull requests
See also: #64, #65.
Reproduction:
Generates the following schema:
Because of
"additionalProperties": false
, no object can be successfully validated against this schema:https://www.jsonschemavalidator.net/s/ddO3vtM2
Compared to schema with removed
additionalProperties
:https://www.jsonschemavalidator.net/s/UO8HV6Lz
The text was updated successfully, but these errors were encountered: