Metarules
Metarules are rules for describing more complex rules: nested objects, lists, conditions and alternatives. Errors of nested rules are returned in the same shape as the data.
nested_objectDescribes validation rules for a nested object.{ nested_object: { … } }FORMAT_ERRORvariable_objectDescribes validation rules for a field that can contain different kinds of objects. The value of the selector field (product_type in the example) chooses the set of rules.{ variable_object: ['type', { … }] }FORMAT_ERRORlist_ofDescribes validation rules for a list. The rules are applied to every element.{ list_of: 'positive_integer' }FORMAT_ERRORlist_of_objectsDescribes validation rules for a list of objects. The rules are applied to every element.{ list_of_objects: { … } }FORMAT_ERRORlist_of_different_objectsDescribes validation rules for a list of different objects. For every element, the value of the selector field chooses the set of rules, like in variable_object.{ list_of_different_objects: ['type', { … }] }FORMAT_ERRORorTakes several sets of rules and applies them one after another until one of them succeeds.{ or: ['email', 'positive_integer'] }no errorswhen2.5Applies rules to the field depending on the value of another field.{ when: ['type', { eq: 'company' }, 'required'] }NOT_ALLOWED_VALUEvalues2.5Validates every value of an object with the same rules, as list_of validates every item of a list. The keys can be any.{ values: 'positive_integer' }FORMAT_ERRORkeys2.5Validates every key of an object as a string with the given rules. The rules only check: the keys do not change.{ keys: { one_of: ['uk', 'en'] } }WRONG_KEY