next-joi
next-joi copied to clipboard
Is Joi.default() supported?
I am trying to add a default value to an optional parameter, but Joi.default() doesn't seem to take effect.
My code looks somehow like this:
const params = Joi.object({
language: Joi.string().default('en-us')
})
export default validate({ body: params }, async (req, res) => {
console.log(req.body.language) // outputs undefined if not passed
})
I'm guessing either I shouldn't access body with req.body or this is not supported, is it?
Thanks in advance.
Hi, @Allen-Hu!
Currently, any operation that modifies the request's body (or query, headers) is not supported. We use joi to perform validation only. Anyway, I think you raise a valid point here, and I will take a look to try adding support for this anytime soon.
I think this may be somehow related to #9 too.
And yes, you are doing the right thing accessing req.body from your handler :-)