Skip to content

when() switch statement #1860

@hueniverse

Description

@hueniverse
const schema = {
    a: Joi.number(),
    b: Joi.number().when('a', {
        switch: [
            { is: 1, then: Joi.number().min(1) },
            { is: 2, then: Joi.number.max(10) }
        ],
        otherwise: Joi.forbidden() });

Basically replace is and then with a new switch. Internally, it gets broken into multiple when() statements. This is just sugar.

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions