Skip to content

Latest commit

 

History

History
158 lines (141 loc) · 4.03 KB

File metadata and controls

158 lines (141 loc) · 4.03 KB
keyword allOf
signature Array<Schema>
value This keyword must be set to a *non-empty* array, where each item is a valid JSON Schema
summary An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword's value.
kind
applicator
instance
any
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
default
logical_value
[]
tests
draft2020-12/allOf.json
index -99999
introduced_in draft4
related
vocabulary keyword
applicator
anyOf
vocabulary keyword
applicator
oneOf
vocabulary keyword
applicator
if
vocabulary keyword
applicator
then
vocabulary keyword
applicator
else
vocabulary keyword
applicator
not

The {{}} 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.

Examples

{{<schema Schema with 'allOf' keyword containing only one subschema>}} { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "allOf": [ { "properties": { "foo": { "type": "string" } }, "required": [ "foo" ] } ] } {{}}

{{<instance-pass An instance conforming to all the subschemas of 'allOf' is valid>}} { "foo": "foo" } {{}}

{{<instance-fail The value of 'foo' must be a string>}} { "foo": [ "foo" ] } {{}}

{{<schema Schema with 'allOf' keyword containing multiple subschemas>}} { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "allOf": [ { "properties": { "foo": { "type": "string" } }, "required": [ "foo" ] }, { "properties": { "bar": { "type": "number" } }, "required": [ "bar" ] } ] } {{}}

{{<instance-pass An instance conforming to all the subschemas of 'allOf' is valid>}} { "foo": "foo", "bar": 33 } {{}}

{{<instance-fail An instance that does not conform to both subschemas within 'allOf' is invalid>}} { "foo": "foo" } {{}}

{{<schema Schema with 'allOf' keyword containing some boolean subschemas>}} { "$schema": "https://json-schema.org/draft/2020-12/schema", "allOf": [ true, { "properties": { "foo": { "type": "string" } }, "required": [ "foo" ] } ] } {{}}

{{<instance-pass An instance conforming to all the subschemas of 'allOf' is valid>}} { "foo": "foo" } {{}}

{{<instance-fail The value of 'foo' must be a string>}} { "foo": true } {{}}

{{<schema Schema with 'allOf' keyword containing some boolean subschemas>}} { "$schema": "https://json-schema.org/draft/2020-12/schema", "allOf": [ false, { "properties": { "foo": { "type": "string" } }, "required": [ "foo" ] } ] } {{}}

{{<instance-fail An instance not conforming to the second subschema of 'allOf' is invalid>}} { "foo": false } {{}}

{{<instance-fail An instance conforming to the second subschema of 'allOf' is also invalid>}} { "foo": "foo" } {{}}

  • Remember, if any subschema within the {{}} keyword fails validation or has a boolean false value, the entire validation will always fail.

{{<schema Schema with nested 'allOf'>}} { "$schema": "https://json-schema.org/draft/2020-12/schema", "allOf": [ { "allOf": [ { "type": "number" } ] }, { "allOf": [ { "minimum": 18 } ] } ] } {{}}

{{<instance-pass An instance conforming to all the subschemas including the nested 'allOf' is valid>}} 25 {{}}

{{<instance-fail The validation fails due to the 2nd subschema of the top-level 'allOf'>}} 10 {{}}