middleware
middleware copied to clipboard
[zod-openapi] Support ZodLazy
Similarly to how zod-openapi
does it:
https://github.com/samchungy/zod-openapi/tree/master?tab=readme-ov-file#supported-zod-schema
Currently, we get the following error:
Unknown zod object type, please specify
type
and other OpenAPI props usingZodSchema.openapi
.
A good example of usage would be the JSON schema from Zod's documentation:
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
type Literal = z.infer<typeof literalSchema>;
type Json = Literal | { [key: string]: Json } | Json[];
const jsonSchema: z.ZodType<Json> = z.lazy(() =>
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
);