Skip to content
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

Is Joi.default() supported? #10

Open
enquestor opened this issue Dec 24, 2021 · 1 comment
Open

Is Joi.default() supported? #10

enquestor opened this issue Dec 24, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@enquestor
Copy link

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.

@sergioalvz
Copy link
Member

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 :-)

@sergioalvz sergioalvz added the enhancement New feature or request label Dec 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants