Is your issue related to zod or zodios ? This might be out-of-scope for us.
Are you using a Swagger v2 input schema ? This is not supported and should migrate to OpenAPI V3+. You can do so by using the official Swagger Editor: https://editor.swagger.io/ using the Edit -> Convert to OpenAPI 3.0 menu
Do you really need runtime validation ? If not, you might be interested in typed-openapi
Describe the bug
A clear and concise description of what the bug is.
I am trying to generate zod schema from openapi json file where property type as const and it's generates z.unknown()
Minimal reproduction
Either paste your input OpenAPI schema reduced to the relevant part here
OR paste a link to the online playground (hit cmd+s or click in the Actions > Save) to generate a shareable link
Read before opening
Describe the bug A clear and concise description of what the bug is.
I am trying to generate zod schema from openapi json file where property
type
asconst
and it's generatesz.unknown()
Minimal reproduction
"components": { "schemas": { "Pet": { "type": "object", "required": ["id", "name"], "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" }, "tag": { "type": "string" }, "type": { "const": "BULLDOG", "title": "Type of dog" } } },
RESULT:
const Pet = z .object({ id: z.number().int(), name: z.string(), tag: z.string().optional(), type: z.unknown().optional() }) .passthrough();
Expected behavior A clear and concise description of what you expected to happen. Ideally, what the generated code would look like.
Should be:
z.literal("BULLDOG").optional()
Additional context Add any other context about the problem here.
LINK to Playground