I am trying to handle unrepresentable for json schema. However, I am not able to access the metadata defined in the original schema.
I checked the code and it seems like ctx.zodSchema is a new copy instead of original schema. It would be much simpler if metadata is also injected into the context.
zod: ^4.6.5
Example
import { z } from "zod";
const schema = z.number().transform(v => `${v}`).meta({ title: "foo" });
console.log(schema.meta());
console.log(z.globalRegistry.get(schema));
schema.toJSONSchema({ unrepresentable: ctx => {
console.log(schema === ctx.zodSchema)
console.log(z.globalRegistry.get(ctx.zodSchema));
return "any"
}});
Result
node a.js
{ title: 'foo' }
{ title: 'foo' }
false
undefined
I am trying to handle unrepresentable for json schema. However, I am not able to access the metadata defined in the original schema.
I checked the code and it seems like
ctx.zodSchemais a new copy instead of original schema. It would be much simpler if metadata is also injected into the context.zod:
^4.6.5Example
Result