karenetheridge / JSON-Schema-Modern

Validate data against a schema using a JSON Schema
https://metacpan.org/release/JSON-Schema-Modern/
Other
10 stars 1 forks source link

custom vocabulary: keywords useful for arrays of objects #28

Open karenetheridge opened 4 years ago

karenetheridge commented 4 years ago

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> and isSortedByProperty: <propertyname>.

karenetheridge commented 4 years ago

Semantics:

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",
}
karenetheridge commented 4 years ago

TBD: maybe both these keywords could also take a list of properties?

iilei commented 3 years ago

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]",
}