Joi验证取决于其他嵌套属性是否为true

时间:2019-02-26 22:49:59

标签: javascript typescript validation joi

我正在尝试验证以下内容,因此当“ l”为假时,“ xl”也必须为假。

xl: joi.object().keys({ 
    enabled: joi.boolean().required(),
    size: joi.number() 
    }).when('l.enabled', {
           is: false,
           then: 'xl.enabled needs to be false',
           otherwise: joi.boolean(),
  }),
l: joi.object().keys({ 
    enabled: joi.boolean().required(),
    size: joi.number() 
    }).when('m.enabled', {
           is: false,
           then: 'l.enabled needs to be false',
           otherwise: joi.boolean(),
  }),
m: ... continues on the same as above..

谢谢!

0 个答案:

没有答案