-
-
Notifications
You must be signed in to change notification settings - Fork 91
Open
Labels
Description
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
akshay5995, ilyabo and gmunguia