tdegrunt/jsonschema

JSON Schema for a list of objects that must contain one of three default props

Roni-Ravin opened this issue · 1 comments

Hello, I need help...
How can I prepare JSON Schema for a list of objects that must contain one of three default props (1,77,90), e.g:

VALID:
[
{"provider_metadata_id": 1},
{"provider_metadata_id": 77},
{"provider_metadata_id": 90}
]
VALID:
[
{"provider_metadata_id": 77},
{"provider_metadata_id": 44}
]
VALID:
[
{"provider_metadata_id": 7884},
{"provider_metadata_id": 4564},
{"provider_metadata_id": 1}
]
INVALID
[
{"provider_metadata_id": 7884},
{"provider_metadata_id": 4564},
{"provider_metadata_id": 60}
]
Can someone help me, please?

@Roni-Ravin This is for development of this particular library, for help writing schemas, check out the support resources at https://json-schema.org/

That said, you're probably looking for the "anyOf" keyword, something like

{ "anyOf": [
   { "properties": { "provider_metadata_id": { "const": 1 } } },
// etc
] }