feat(zod-validator): pass target from zod-validator to a hook#695
feat(zod-validator): pass target from zod-validator to a hook#695yusukebe merged 4 commits intohonojs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 7fc598c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
lucaschultz
left a comment
There was a problem hiding this comment.
I just made the same change to the middleware. I'm so glad I double-checked and found your PR! I went a slightly different route by adding another generic to the hook (see comments), which creates a narrower type for the target passed to the hook. Would you consider including that change in your PR, @bartekbp?
|
Thanks for the suggestion @lucaschultz! I applied it! |
|
Hi @bartekbp Sorry for the super late reply. Looks good to me. I'll merge this and release a new version now. Thank you! |
Today, when we use
zod-openapiand pass schema forbodyandparams, we can pass a hook which is called with the result of the validation.The function doesn't get information about the target being validated. This is problematic when we want to return custom error responses depending on the target being validated. For example, one may want to:
415 Unsupported Media Typewhen body parsing failed due to missing content-type. Such behaviour doesn't make sense forparamsjsonwe may write in the response body 'body validation failed', forparams'path validation failed' and forquery'search params validation failed' .This pull request adds this functionality.