Closed as not planned
Description
To reproduce, use https://github.com/Firfi/zod-to-json-schema-preprocess-bug
For such code as
const idParser = z.preprocess(
(uuid) => {
if (typeof uuid !== 'string') throw new Error(`Expected string, got ${typeof uuid}: ${uuid}`);
const [type, id] = uuid.split('SEPARATOR');
return { type, id };
}, z.object({ type: z.string(), id: z.string() }));
zodToJsonSchema(idParser)
will be evaluated all right, however
if I do
const idParser2 = z.object({
id: idParser
})
zodToJsonSchema(idParser2)
starts passing undefined
into preprocess (as my uuid
var)
I wonder if that's expected behaviour and why it happens only when a parser is used inside z.object