anyOf, allOf, oneOf, not - sgpinkus/json-schema GitHub Wiki
THIS WIKI IS OBSOLETE. PLEASE SEE THE NEW JSON-SCHEMA-ORG/JSON-SCHEMA-SPEC REPOSITORY.
NOTE: This proposal was incorporated in Draft 04.
Those four keywords intend to bring logical processing primitives to JSON Schema validation. They would allow to get rid of:
- schemas in type;
- the disallow keyword;
- the extends keyword.
An instance is valid against this keyword if and only if it is valid against at least one schema in this keyword's value.
The value of this keyword MUST be an array. This array MUST have at least one element.
Each element of this array MUST be an object, and each object MUST be a valid JSON Schema.
An instance is valid against this keyword if and only if it is valid against all the schemas in this keyword's value.
The value of this keyword MUST be an array. This array MUST have at least one element.
Each element of this array MUST be an object, and each object MUST be a valid JSON Schema.
An instance is valid against this keyword if and only if it is valid against exactly one schema in this keyword's value.
The value of this keyword MUST be an array. This array MUST have at least one element.
Each element of this array MUST be an object, and each object MUST be a valid JSON Schema.
An instance is valid against this keyword if and only if it fails to validate against this keyword's value.
The value of this keyword MUST be an object. This object MUST be a valid JSON Schema.
Before:
{
"type": [ "string", "boolean", { "schema1": "here" }, { "schema2": "here" } ]
}
After:
{
"anyOf": [
{ "type": [ "string", "boolean" ] },
{ "schema1": "here" },
{ "schema2": "here" }
]
}
Before:
{
"disallow": [ "string", "boolean", { "schema1": "here" }, { "schema2": "here" } ]
}
After:
{
"not": {
"anyOf": [
{ "type": [ "string", "boolean" ] },
{ "schema1": "here" },
{ "schema2": "here" }
]
}
}
Before:
{
"keyword": "here",
"extends": [ { "schema1": "here" }, { "schema2": "here" } ]
}
After:
{
"allOf": [
{ "keyword": "here" },
{ "schema1": "here" },
{ "schema2": "here" }
]
}
{
"oneOf": [
{ "schema1": "here" },
{ "schema2": "here" },
{ "etc": "etc" }
]
}
That is, the instance is valid if and only if it matches exactly one schema among all listed schemas.
Draft v3 has no mechanism for that, or not as terse.