StefanTerdell / zod-to-json-schema

Converts Zod schemas to Json schemas
ISC License
854 stars 67 forks source link

When zod specifies z.date(), type is converted to date-time rather than date #109

Closed matthew-kaye closed 5 months ago

matthew-kaye commented 6 months ago

Steps to reproduce:

StefanTerdell commented 5 months ago

Hello @matthew-kaye, thanks for opening an issue.

The behavior you describe makes sense to me. z.date() represents the JS Date class, which by default is serialized to JSON as a date-time string, thus matching z.string().datetime().

Feel free to reopen the issue if you don't agree!

matthew-kaye commented 5 months ago

Hello @matthew-kaye, thanks for opening an issue.

The behavior you describe makes sense to me. z.date() represents the JS Date class, which by default is serialized to JSON as a date-time string, thus matching z.string().datetime().

Feel free to reopen the issue if you don't agree!

I'm not sure I do agree actually sorry 😅 Since a zod schema for z.date() would allow a data field like "2024-01-01" but a JSON schema requiring a date-time would not. It seems normal to me to expect that data which would pass the zod schema would also be accepted by the JSON schema generated from it

image