Closed
Description
Description
Given the below schemas:
const foo = z.object({
prop: z.string().default("fooPropDefault"),
});
const bar = z.interface({
prop1: z.string().default("barProp1Default"),
"prop2?": z.string().default("barProp2Default"),
});
const fooInputJsonSchema = z.toJSONSchema(foo, { io: "input" });
const fooOutputJsonSchema = z.toJSONSchema(foo, { io: "output" });
const barInputJsonSchema = z.toJSONSchema(bar, { io: "input" });
const barOutputJsonSchema = z.toJSONSchema(bar, { io: "output" });
When generating to JSON Schema (via z.toJSONSchema(...)
), each optional field is expected to not be required
in input schema, and required
for the output schema.
Actual Result
// foo-input.json
{
"type": "object",
"properties": {
"prop": {
"type": "string",
"default": "fooPropDefault"
}
},
"required": [
"prop" // incorrect
]
}
// bar-input.json
{
"type": "object",
"properties": {
"prop1": {
"type": "string",
"default": "barProp1Default"
},
"prop2": {
"type": "string",
"default": "barProp2Default"
}
},
"required": [
"prop1" // incorrect
]
}
// bar-output.json
{
"type": "object",
"properties": {
"prop1": {
"type": "string",
"default": "barProp1Default"
},
"prop2": {
"type": "string",
"default": "barProp2Default"
}
},
"required": [
"prop1",
// missing prop2
]
}
Metadata
Metadata
Assignees
Labels
No labels