You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
these keywords would complement the existing keyword:
patternProperties
Purpose
Currently, schemas can specify a minimum/maximum number of object properties, but they cannot place such constraints on particular groups of properties.
This proposal basically allows us to specify the number of properties that must match a particular pattern.
Values
patternGroups
The value of patternGroups would be an object. The keys of the object would be regular expressions (exactly like the existing patternProperties).
The values inside patternGroups would be objects, containing zero or more of the following properties:
minimum - the minimum number of properties in the data that MUST match the corresponding pattern
maximum - the maximum number of properties in the data that MUST match the corresponding pattern
schema - the schema that matching properties must follow.
minimum/maximum would be non-negative integers, and schema would be a schema.
patternRequired
The value of this keyword should be the array of patterns (to require at least one property matching the pattern)
Behaviour
patternGroups
If the instance is an object, then for every entry in patternGroups:
the set of properties matching that pattern is collected
if minimum or maximum are specified in the patternGroups entry, then the size of this property set must be between these values (inclusive)
if schema is specified in the patternGroups entry, then for every property in the property set, the corresponding object member in the instance must follow that schema.
patternRequired
If the instance is an object, the data to be valid should have at least one property matching each pattern (the same property can match multiple patterns).
Both these schemas expresses the constraint that instance objects must have at least one alphabetic key, and at least one numeric-key. (This constraint is currently not possible to express).
Additionally, the alphabetic keys must hold strings, and the numeric keys must hold integers.
Originally added as wiki: https://github.com/json-schema/json-schema/wiki/patternGroups-and-patternRequired-(v5-proposal)
Proposed keywords
This proposal would introduce two new keywords:
patternGroups
andpatternRequired
these keywords would complement the existing keyword:
patternProperties
Purpose
Currently, schemas can specify a minimum/maximum number of object properties, but they cannot place such constraints on particular groups of properties.
This proposal basically allows us to specify the number of properties that must match a particular pattern.
Values
patternGroups
The value of
patternGroups
would be an object. The keys of the object would be regular expressions (exactly like the existingpatternProperties
).The values inside
patternGroups
would be objects, containing zero or more of the following properties:minimum
- the minimum number of properties in the data that MUST match the corresponding patternmaximum
- the maximum number of properties in the data that MUST match the corresponding patternschema
- the schema that matching properties must follow.minimum
/maximum
would be non-negative integers, andschema
would be a schema.patternRequired
The value of this keyword should be the array of patterns (to require at least one property matching the pattern)
Behaviour
patternGroups
If the instance is an object, then for every entry in
patternGroups
:minimum
ormaximum
are specified in thepatternGroups
entry, then the size of this property set must be between these values (inclusive)schema
is specified in thepatternGroups
entry, then for every property in the property set, the corresponding object member in the instance must follow that schema.patternRequired
If the instance is an object, the data to be valid should have at least one property matching each pattern (the same property can match multiple patterns).
Example
patternGroups
Example with
patternRequired
Both these schemas expresses the constraint that instance objects must have at least one alphabetic key, and at least one numeric-key. (This constraint is currently not possible to express).
Additionally, the alphabetic keys must hold strings, and the numeric keys must hold integers.
Valid:
{"abc": "foo", "123": 456}
Invalid:
{"abc": "foo", "def": "bar"}
For the simple case the syntax of
patternRequired
is the simpler and consistent withproperties
/required
.The text was updated successfully, but these errors were encountered: