middleware icon indicating copy to clipboard operation
middleware copied to clipboard

[zod-openapi] Support ZodLazy

Open Shyrogan opened this issue 7 months ago • 4 comments

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 using ZodSchema.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)])
);

Shyrogan avatar Jul 15 '24 13:07 Shyrogan