Joi.object( {
a: Joi
.boolean()
.default(false),
b: Joi
.boolean()
.default(false),
c: Joi.string().when(
'a', {
is: false,
then: Joi.when(
'b', {
is: false,
then: Joi.string().required()
}
)
}
),
})
我在提问之前尝试了嵌套when,但由于规则的顺序,它以前不起作用
Joi.object( {
c: Joi.string().when(
'a', {
is: false,
then: Joi.when(
'b', {
is: false,
then: Joi.string().required()
}
)
}
),
a: Joi
.boolean()
.default(false),
b: Joi
.boolean()
.default(false),
})
when 正在检查时,第二个架构中的 default 值未设置,因此如果您验证一个空对象 {},则第一个架构有 Validation Error: "c" is required 错误,而第二个架构有 Passed 987654330@
我在这里打开了一个问题https://github.com/sideway/joi/issues/2683