arb / celebrate

A joi validation middleware for Express.
MIT License
1.33k stars 66 forks source link

joi.alternatives error message too generic #241

Closed maxuai closed 1 year ago

maxuai commented 1 year ago

My joi schema looks like this:

`{

    param: Joi.alternatives().try(Joi.object({
      name: Joi.string(),
    }), Joi.object({
      name: Joi.number(),
    })),
}`

Here is an example value that is not working as expected:

(param: { name: true })

The issue I am having with celebrate is:

When using joi.alternatives with objects and none of the alternatives matches the error message is too generic like "message": "\\"param\\" does not match any of the allowed types". What would be needed is to add the context from the the error details to the validation object in the error response.

maxuai commented 1 year ago

I would have a branch with a fix ready, but am am not allowed to push ;)

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

arb commented 1 year ago

Hi @maxuai if you're still interested in adding this, please folk this project and open a pull request; I'd be happy to review.