我有以下架构:
var testSchema = Joi.object().keys({
a: Joi.string(),
b: Joi.string(),
c: Joi.string().when('a', {'is': 'avalue', then: Joi.string().required()})
});
但我想在 c
字段定义上添加一个条件,以便在以下情况下需要它:
a == 'avalue' AND b=='bvalue'
我该怎么做?
最佳答案
您可以连接两个 when
规则:
var schema = {
a: Joi.string(),
b: Joi.string(),
c: Joi.string().when('a', { is: 'avalue', then: Joi.string().required() }).concat(Joi.string().when('b', { is: 'bvalue', then: Joi.string().required() }))
};
关于javascript - Joi 验证多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26509551/