-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(zod-validator): pass target from zod-validator to a hook #695
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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-openapi
and pass schema forbody
andparams
, 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 Type
when body parsing failed due to missing content-type. Such behaviour doesn't make sense forparams
json
we 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.