turkerdev / fastify-type-provider-zod

MIT License
303 stars 19 forks source link

`querystring` needs to restrict to `Record<string, string>` #95

Open BriungRi opened 2 weeks ago

BriungRi commented 2 weeks ago

Currently, querystring can accept something like

z.object({
  name: z.string(),
  age: z.number(),
});

which will always fail the validation because all parameters from querystring are string type.

A few ideas:

  1. For querystring only, if a number is expected, parse the string into a number and then do zod validation
  2. Add (static) typing that enforces querystring type
  3. Add (dynamic) type check that enforces querystring type by throwing an error for invalid type