Closed UberMouse closed 2 years ago
Indeed this is by design, cf https://github.com/ecyrbe/zodios/discussions/225 Because the default behaviour is to do it on backend, not frontend. what could be done is an option to activate it, but would not be activated by default.
An option to activate it would be useful, as we are only using @zodios/core on the front-end so that's where I need default values. I've updated @zodios/core to try the transform option mentioned in that discussion but it doesn't work for this scenario as the schema isn't executed for undefined values.
As a general advice, if you have optional parameters with defaults, you should let your backend set it. Indeed, default values can be considered business code and you usually want business code to be executed on your backend. That's why zodios has this behaviour by default.
Nevetheless, this option is now available on @zodios/core
v10.7.0. see documentation
Thanks :tada: The specific endpoint I'm adding now has different responses depending on whether you include a query param or not so I'm making two separate endpoints, one with the query param forced to true and the other without it.
This is something I have wanted to be able to do a few times now and doesn't seem possible. Could be solved via the Zod
default
function if all the params/query fields were parsed with the schema (I don't see that happening anywhere but maybe I missed it), that's what I have tried so far.