Skip to content

How to get req.query req.params if we dont know the shape #831

Answered by RobinTail
fbritoferreira asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @fbritoferreira ,

request properties are combined and into a single object that is being validated against input schema, which has to be z.object.
However, you can easily enable unknown properties on that schema by utilizing .passthrough() method.

Check out this example:

https://github.com/RobinTail/express-zod-api/blob/master/example/endpoints/upload-avatar.ts#L18

Another advice could be making your z.record schema a property inside the input schema object, like this:

z.object({ 
  params: z.record(
    z.string(), z.string(),
  )
})

I hope this would help you

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RobinTail
Comment options

Answer selected by RobinTail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #830 on February 26, 2023 16:25.