asteasolutions/zod-to-openapi

Coerce drops required option on output

Closed this issue · 3 comments

When using coerce the required option is no longer there when outputting openapi.json

Input:
image

Output:
image

This is probably due to .isNullable() being true on the zod object and is maybe the correct way for this library to also define the required option.

Yes @Bram-dc you are totally correct - the capabilities of null/undefined is what is causing this change and it is expected

I have the same issue.

const t = z.number({description: 'Database ID', coerce: true})
t.isNullable() // true
t.isOptional() // false

Would it be an option to test isOptional in case of request params?

Because coerce is an important option for request params.