-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
POST with empty payload fails validation (with Joi) #2722
Comments
This definitely looks like a bug. Essentially, the value |
The same happens if |
It is possible that this is not a bug, but simply a consequence of the updated payload parsing. At least I managed to find a work around: server.route({
method: 'POST',
path: '/hello',
config: {
validate: {
payload: Joi.object({
name: Joi.string()
}).allow(null)
},
handler: function (request, reply) {
reply('hello ' + ((request.payload || {}).name || 'world'));
}
}
}); |
|
@hueniverse perhaps this can be resolved by noting in the "Empty Payload" section of the 9.0.0 migration checklist (#2682) how to field empty request payloads (that are allowed to be empty) when using Joi validation. The pattern is to use |
Related to #2576 ? |
I have a route with an optional payload. After upgrading to v9, the route returns 400 when the payload is missing. I assume this is because an empty payload is now transformed to
null
instead of{}
, and whennull
is passed to Joi, Joi responds with"value" must be an object
.To reproduce:
My use case is an action for resetting a password, where users are allowed to provide a password in the payload, but if a password is not provided, we generate one automatically.
The text was updated successfully, but these errors were encountered: