I have the following validation on one of my routes:
payload: {
keywordGroups: Joi.array().items(Joi.object().keys({
language: Joi.string().required(),
containsAny: Joi.array().items(Joi.string()).default([]).when('containsAll', { is: [], then: Joi.required() }),
containsAll: Joi.array().items(Joi.string()).default([]).when('containsAny', { is: [], then: Joi.required() }),
notContainsAll: Joi.array().items(Joi.string()).default([]),
notContainsAny: Joi.array().items(Joi.string()).default([])
})).required(),
}
I'm trying to make it so that containsAny
or containsAll
have to include at least one string. If containsAny
is empty, containsAll
should have at least one item. And if containsAll
is empty, containsAny
should at least include one item.
But it seems Joi.when
doesn't really work when it comes to an array of objects.