带有两个when子句的Joi验证

时间:2020-03-06 09:44:18

标签: javascript validation joi

我有joi版本6.10.1,但我也尝试使用14.0.0。

我有三个相互依赖的领域。其中很少有可能为空。 还有2个when子句存在问题,验证仅适用于第一个子句。 也许我做错了什么? 当我更改时间顺序时-验证规则也会更改。看起来总是第二个何时被忽略。

        a:  utils.joi.number().integer().allow(null),
        b:  utils.joi.number().integer().allow(null),
        c:  utils.joi.number().integer().allow(null)

                   .when('a', {
                     is: null,
                     then:      utils.joi.number().integer().max(999),
                     otherwise: utils.joi.number().integer().max(utils.joi.ref('a'))
                   })
                   .when('b', {
                     is: null,
                     then:      utils.joi.number().integer().min(0),
                     otherwise: utils.joi.number().integer().min(utils.joi.ref('b'))
                   })

示例:

Validation works:
test {
   a: "4",
   b: "10",
   c: "11"
}

Does not:
test {
   a: "4",
   b: "10",
   c: "3"
}

0 个答案:

没有答案