arb / celebrate

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

Full mode validation can not be enabled #228

Closed AdamAld closed 2 years ago

AdamAld commented 2 years ago

My celebrate definition and joi schema looks like this:

    celebrate({
            [Segments.QUERY]: {
                ...
                type: Joi.string().valid(
                    "active-payouts",
                    "all-payouts",
                ).required(),
                sortDirection: Joi.string().case("upper").valid("ASC", "DESC"). default("DESC"),
                startDate: Joi.string().default('2020-06-01'),
                endDate: Joi.string().default(new Date().toISOString().slice(0, 10))
            }
        }, 
        {}, 
        { mode: Modes.FULL })

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

N/A

The issue I am having with celebrate is:

Passing { mode: Modes.FULL } as the opts parameter to the celebrate function - or the curried version via celebrator - does not override the default value of Modes.PARTIAL.

AdamAld commented 2 years ago

A workaround is to abortEarly: false as part of the joiOpts:

image

arb commented 2 years ago

That mode just controls if celebrate should validate the all the segments of a request. Normally, it fails on the first segment that is invalid (just like hapi does). The abortEarly option is used to control if Joi will abort on the first error or not. The two are not really related directly and mixing and matching them is possible.

AdamAld commented 2 years ago

Ahh, I see! I was conflating the two - Celebrate FULL mode and Joi abortEarly - as having the same operational outcome. Thank you!