If I have two fields, I'd just like to validate when at least one field is a non empty string, but fail when both fields are empty strings.
Something like this does not validate
var schema = Joi.object().keys({
a: Joi.string(),
b: Joi.string()
}).or('a', 'b');
When validating against
{a: 'aa', b: ''}
The or
condition only tests for the presence of either key a
or b
, but does test whether the condition for a
or b
is true. Joi.string()
will fail for empty strings.
Here is gist with some test cases to demonstrate