I have a joi validation which uses “when” and “is” to reference another value of the object. It works fine.
es: Joi.object().keys({
cascadeIfNecessary: Joi.boolean(),
battery_id: Joi.number().when('cascadeIfNecessary', { is: true, then: Joi.required() }),
}),
From the joi docs I learn that “not” is simply the opposite od “is”. https://joi.dev/api/?v=17.13.0#anywhencondition-options
So I thought I can simply make something like this:
es: Joi.object().keys({
cascadeIfNecessary: Joi.boolean(),
battery_id: Joi.number().when('cascadeIfNecessary', { not: true, then: Joi.required() }),
}),
Or with
not: 1
not: 'text'
or something like that. But I always get the Error
Uncaught Error: Invalid schema content
Can someone explain the use of not
with when
in joi.js