Open karenetheridge opened 4 years ago
Semantics:
{"type":"array", "items": {"type": "object" } }
.isUniqueByProperty
MUST have a value of string. It evaluates to true if the property named by the keyword either does not exist in each item member's object, or appears exactly once across all items. If any property value of the indicated name appears more than once across all the items, evaluation is false.isSortedByProperty
MUST have a value of string. It evaluates to true if the property named by the keyword either does not exist in each item member's object, or appears in each item in sorted order. ("in order" is considered to be normal string sorting (insert spec?) if the properties are of string type, or numeric if the properties are of number type. Behaviour is undefined if the named property is not a consistent type across all items, or is any type other than "string" or "number". If the indicated property is seen more than once across the items, the sort order between those items is indeterminate (so any ordering would be considered to be valid), so it may be desirable to combine with "isUniqueByProperty".Since both keywords can act on object items even when the property is not present, and the outcome is indeterminant if the property types vary, it is recommended to include extra validation with the "required", "properties" and "type" keywords for the property of interest.
Example:
{
"type": "array",
"items": {
"type": "object",
"required": [ "name" ],
"properties": {
"name": { "type": "string" },
... other properties...
},
},
"isUniqueByProperty": "name",
"isSortedByProperty": "name",
}
TBD: maybe both these keywords could also take a list of properties?
For better flexibility I would consider using jsonpath expressions.
The Example above then would become something like
{
...
"uniquenessProvidedBy": ".name",
"sortingProvidedBy": ".name",
}
whilst allowing for conjunction keys etc.
TBD: maybe both these keywords could also take a list of properties?
That would also allow for lists:
{
...
"uniquenessProvidedBy": ".[name,key,id]",
"sortingProvidedBy": ".[name,key,id]",
}
see https://github.com/json-schema-org/json-schema-vocabularies/issues/22 -- when the instance data is an array of objects, it would be useful to have the keywords
isUniqueByProperty: <propertyname>
andisSortedByProperty: <propertyname>
.