enjoi icon indicating copy to clipboard operation
enjoi copied to clipboard

Usage of "when" for conditional validations

Open ManuSevenval opened this issue 6 years ago • 2 comments

Thanks for your great library!

I am wondering if it would be possible to define conditional validation rules in a json schema, since I used this feature a lot with Joi.

Taken from their examples page:

const schema = {
    a: Joi.valid('a', 'b', 'other'),
    other: Joi.string()
        .when('a', { is: 'other', then: Joi.required() }),
};

Can such conditional validation rules be expressed via a static schema with enjoi?

Thanks!

ManuSevenval avatar Nov 09 '18 11:11 ManuSevenval

You should be able to do this with custom types.

tlivings avatar Nov 11 '18 14:11 tlivings

@tlivings could you please give me a short code example how to accomplish this by using custom types with enjoi? thanks a lot!

ManuSevenval avatar Nov 11 '18 22:11 ManuSevenval