allOf : Array<Schema>
allOf
Array<Schema>An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword’s value.
Kind | Applicator |
---|---|
Applies To | Any |
Dialect | 2020-12 |
Introduced In | Draft 4 |
Vocabulary | Applicator |
Specification | https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.2.1.1 |
Metaschema | https://json-schema.org/draft/2020-12/meta/applicator |
Also see |
|
The allOf
keyword is used to specify that a given instance must validate against all of the subschemas provided within an array. It’s essentially a logical “AND” operation where all conditions must be met for validation to pass.
- The value of this keyword must be a non-empty array.
- Each item of the array must be a valid JSON Schema.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"allOf": [
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{ "foo": "foo" }
{ "foo": [ "foo" ] }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"allOf": [
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
},
{
"properties": {
"bar": { "type": "number" }
},
"required": [ "bar" ]
}
]
}
{ "foo": "foo", "bar": 33 }
{ "foo": "foo" }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
true,
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{ "foo": "foo" }
{ "foo": true }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
false,
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{ "foo": false }
{ "foo": "foo" }
- Remember, if any subschema within the
allOf
keyword fails validation or has a booleanfalse
value, the entire validation will always fail.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"allOf": [
{ "type": "number" }
]
},
{
"allOf": [
{ "minimum": 18 }
]
}
]
}
25
10