Node express check multiple JSON-Schema fields

Using express-jsonschema

How to check two fields, for example:

("quantity" == 0 && "actualQuantity" == 0) || ("quantity" > 0 && "actualQuantity" > 0)

+5
source share
1 answer

Just tested, this will complete the task:

 { "anyOf" : [ { "properties" : { "quantity" : { "minimum" : 0, "maximum" : 0 }, "actualQuantity" : { "minimum" : 0, "maximum" : 0 } } }, { "properties" : { "quantity" : { "minimum" : 1 }, "actualQuantity" : { "minimum" : 1 } } } ] } 

You can also use "oneOf" instead of "anyOf" , but "anyOf" faster in most implementations.

+1
source

Source: https://habr.com/ru/post/1261450/


All Articles