[英]Node express JSON-Schema multiple fields validation
Using express-jsonschema 使用express-jsonschema
How to validation two fields, for example: 如何验证两个字段,例如:
("quantity" == 0 && "actualQuantity" == 0) || ("quantity" > 0 && "actualQuantity" > 0)
Just tested, this will do the job: 刚刚测试过,这将完成这项工作:
{
"anyOf" : [
{
"properties" : {
"quantity" : {
"minimum" : 0,
"maximum" : 0
},
"actualQuantity" : {
"minimum" : 0,
"maximum" : 0
}
}
},
{
"properties" : {
"quantity" : {
"minimum" : 1
},
"actualQuantity" : {
"minimum" : 1
}
}
}
]
}
You could also use "oneOf"
instead of "anyOf"
, but "anyOf"
is faster with most implementations. 您也可以使用
"oneOf"
而不是"anyOf"
,但"anyOf"
在大多数实现中都会更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.