Closed
Description
Issue Description
Given the below schemas:
const fooSchema = z.string().meta({
id: "BaseSchema",
});
const objectWithDefaultFoo = z.object({
foo: fooSchema.default("bar"),
}).meta({
id: "ObjectWithDefaultFoo",
});
const jsonSchema = z.toJSONSchema(objectWithDefaultFoo);
I would expect the JSON Schema to be:
{
"id": "ObjectWithDefaultFoo",
"type": "object",
"properties": {
"foo": {
"$ref": "#/$defs/BaseSchema"
"default": "bar",
}
},
"required": [
"foo"
],
"$defs": {
"BaseSchema": {
"id": "BaseSchema",
"type": "string"
}
}
}
Actual Result
Instead, the "foo" subschema seems to redeclare an inline schema with the id "BaseSchema", rather than pointing to "$defs/BaseSchema".
{
"id": "ObjectWithDefaultFoo",
"type": "object",
"properties": {
"foo": {
"id": "BaseSchema", // this is wrong
"default": "bar",
"type": "string"
}
},
"required": [
"foo"
],
"$defs": {
"BaseSchema": {
"id": "BaseSchema",
"type": "string"
}
}
}
Metadata
Metadata
Assignees
Labels
No labels