enjoi
enjoi copied to clipboard
Usage of "when" for conditional validations
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!
You should be able to do this with custom types.
@tlivings could you please give me a short code example how to accomplish this by using custom types with enjoi? thanks a lot!