Closed Wykks closed 3 months ago
There will be a new option called coercion
that you can enable that will use z.coerce.date()
instead of .date()
.
See https://1051.docs.kubb.dev/plugins/swagger-zod/#coercion.
Awesome thanks!
Thank you for this feature! It has a slight side effect to coerce everything where it’s might not be wanted:
z.union([z.coerce.string(), z.null()]),
null
in input will be coerced as "null"
string
Would there be a way to coerce only Date and not the rest?
What is the problem this feature would solve?
If have a setup where I generate mocks and use msw (without kubb here), and zod to validate the data.
I would like to generate every date with the native
Date
, but on runtime msw send a date as a string (because it's serialized), and it break, because zod expect a Date object.External documents/projects?
No response
What is the feature you are proposing to solve the problem?
Instead of doing
z.date()
, doz.coerce.date()
to parse date even if they come in stringWhat alternatives have you considered?
No response