asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
993 stars 60 forks source link

Support for z.undefined() #196

Closed tonyxiao closed 10 months ago

tonyxiao commented 1 year ago
error Error: Unknown schema ZodUndefined. Please assign it a manual 'type'.
    at createManualTypeSchema (webpack-internal:///(api)/../../node_modules/.pnpm/zod-openapi@2.11.0_zod@3.21.4/node_modules/zod-openapi/lib-commonjs/index.js:194:11)

Getting this error currently

AGalabov commented 1 year ago

@tonyxiao any idea what the generated type should be? I also don't see the usecase for it - i.e in the OpenAPI world a parameter/body field being undefined (and validated as such) is the equivalent of it not being present at all. So I am not sure what you are trying to achieve.

Would you be able to share an example usage?

And as a short term fix - if you know what type you would want in your documentation - you can always specify it manually with z.undefined().openapi({ type: 'whatever-you-want-here' })