-
Notifications
You must be signed in to change notification settings - Fork 5
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
Get converted payload after validation #9
Comments
Hi, @JeffreySoriano5! That's currently not possible, but it looks like a good idea to me :-) I will take a look at joi's documentation and hapi implementation to see if that's a good practice (I have some reservations about mixing together validation and "transformation"). |
Thanks for the quick response @sergioalvz. I understand your concern. Maybe it could be an option. It would be useful for things like the query search strings which are always parsed as string, for example for pagination. In this case I would have to call the validate inside of the handler again to get the casted/sanitized values. |
Another thing to consider: as a TypeScript user, I would expect |
You can use my approach described in #13, or if you use next-connect, you can also use the generic from the call actions: interface Body {
name: string,
number: number,
}
.post<{body: Body}>(validator({ body: schema }), async (req, res) => {
});
From my pov that should be no problem, since the validation function returns the converted values by default.
We could add the possibility to pass an option object for the validation function of Joi to this middleware, because there is the |
Hello,
I am using next-joi with next-connect and it works great.
I was wondering if there is a way for the request handler to receive the validated/converted payload.
For example:
The text was updated successfully, but these errors were encountered: