Zod z.stringbool is converted to string in the spec #3057
-
input: z.object({
override: z
.boolean()
.default(false)
.optional(),
}),With the input shown, the spec says this is a boolean as expected, however Zod can't parse the input because it's a query string, and Zod expects a boolean, not a string. Is there a way to get around this and still define the type as a boolean in the spec, while still being able to parse the value? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It is the answer to your question, @PseudoResonance When parsing GET request, the query is a string, all its parameters are strings. You can't have If you want booleans, use a request that supports |
Beta Was this translation helpful? Give feedback.
It is the answer to your question, @PseudoResonance
When parsing GET request, the query is a string, all its parameters are strings.
So there must be some interpretation implemented that could treat some of those strings as "truthy" or "falsy" in order to get booleans out of them.
You can't have
z.boolean()in input schema for GET request directly — it won't pass the validation, because thetypeofis stillstring. You can have a string-based schema, having a transformer to boolean.z.stringbool()is a flexibly configurable shorthand for that purpose.If you want booleans, use a request that supports
body, for instance — POST.The body os JSON encoded, so that its par…