Skip to content

Commit 20623a0

Browse files
committed
Revise the $vocabulary 2020-12 description and examples
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 2337310 commit 20623a0

File tree

2 files changed

+42
-54
lines changed

2 files changed

+42
-54
lines changed

content/2019-09/core/vocabulary.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
keyword: "$vocabulary"
33
signature: "Object<URI, Boolean>"
44
value: This keyword must be set to an object where each key is a JSON Schema vocabulary URI and each value is a boolean that represents whether the corresponding vocabulary is considered optional (false) or required (true)
5-
summary: "This keyword is used in meta-schemas to identify the required and optional vocabularies available for use in schemas described by that meta-schema."
5+
summary: "This keyword is used in dialect meta-schemas to identify the required and optional vocabularies available for use in schemas described by that dialect."
66
kind: [ "identifier" ]
77
instance: [ "any" ]
88
specification: "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.8.1.2"

content/2020-12/core/vocabulary.markdown

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
keyword: "$vocabulary"
33
signature: "Object<URI, Boolean>"
44
value: This keyword must be set to an object where each key is a JSON Schema vocabulary URI and each value is a boolean that represents whether the corresponding vocabulary is considered optional (false) or required (true)
5-
summary: "This keyword is used in meta-schemas to identify the required and optional vocabularies available for use in schemas described by that meta-schema."
5+
summary: "This keyword is used in dialect meta-schemas to identify the required and optional vocabularies available for use in schemas described by that dialect."
66
kind: [ "identifier" ]
77
instance: [ "any" ]
88
specification: "https://json-schema.org/draft/2020-12/json-schema-core.html#section-8.1.2"
@@ -19,22 +19,37 @@ related:
1919
keyword: $schema
2020
---
2121

22-
The `$vocabulary` keyword is used in meta-schemas to identify the vocabularies available for use in schemas described by that meta-schema. It is also used to indicate whether each vocabulary is required or optional, in the sense that an implementation must understand the required vocabularies in order to successfully process the schema.
22+
The `$vocabulary` keyword is a _mandatory_ component of a dialect meta-schema
23+
to list the required and optional vocabularies available for use by the schema
24+
instances of such dialect. The vocabularies declared by a dialect meta-schema
25+
are not inherited by meta-schemas that derive from it. Each dialect meta-schema
26+
must explicitly state the vocabularies it imports using the `$vocabulary`
27+
keyword.
2328

24-
* **Required and optional vocabularies:** If a vocabulary is required and an implementation does not recognize it, it must refuse to process any schemas that declare this meta-schema. If a vocabulary is optional, implementations that do not recognize it should proceed with processing such schemas.
29+
{{<common-pitfall>}}Declaring the `$vocabulary` keyword in a schema does not
30+
grant that same schema access to such vocabularies. Instead, the `$vocabulary`
31+
keyword must be set in the dialect meta-schema that describes the desired
32+
schema.{{</common-pitfall>}}
2533

26-
* **Mandatory:** The Core vocabulary MUST always be included and set as required.
34+
If a vocabulary is marked as required, JSON Schema implementations that do not
35+
recognise the given vocabulary must refuse to process schemas described by such
36+
dialect. As a notable exception, every dialect must list the [Core](..)
37+
vocabulary as required, as it is the foundational vocabulary that implements
38+
the vocabulary system itself.
2739

28-
* **Non-inheritability:** Vocabularies defined in one meta-schema do not automatically apply to another meta-schema that references it. Each meta-schema must declare its vocabularies independently.
29-
30-
* **Recommendation:** Meta-schemas should always declare this keyword to clearly specify the vocabularies in use and avoid ambiguities.
40+
{{<learning-more>}} By convention, every official JSON Schema dialect defines a
41+
dynamic anchor called `meta`. This serves as an extensibility point for
42+
arbitrary vocabularies to register syntactic constraints that are automatically
43+
applied to every JSON Schema subschema apart from the top-level one.
44+
{{</learning-more>}}
3145

3246
## Examples
3347

34-
{{<schema `'$vocabulary' for default official-2020-12 meta-schema`>}}
48+
{{<schema `The seven required vocabularies declared by the JSON Schema 2020-12 official dialect`>}}
3549
{
3650
"$schema": "https://json-schema.org/draft/2020-12/schema",
3751
"$id": "https://json-schema.org/draft/2020-12/schema",
52+
"$dynamicAnchor": "meta",
3853
"$vocabulary": {
3954
"https://json-schema.org/draft/2020-12/vocab/core": true,
4055
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
@@ -44,75 +59,48 @@ The `$vocabulary` keyword is used in meta-schemas to identify the vocabularies a
4459
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
4560
"https://json-schema.org/draft/2020-12/vocab/content": true
4661
},
47-
"allOf" : [
48-
{ "$ref": "meta/core" },
49-
{ "$ref": "meta/applicator" },
50-
{ "$ref": "meta/unevaluated" },
51-
{ "$ref": "meta/validation" },
52-
{ "$ref": "meta/meta-data" },
53-
{ "$ref": "meta/format-annotation" },
54-
{ "$ref": "meta/content" }
55-
],
5662
// ...
5763
}
5864
{{</schema>}}
5965

60-
{{<schema `Vocabulary meta-schema`>}}
66+
{{<schema `An example dialect meta-schema that opts-in to the JSON Schema 2020-12 format assertion vocabulary`>}}
6167
{
6268
"$schema": "https://json-schema.org/draft/2020-12/schema",
63-
"$id": "https://example.com/meta/example-vocab",
64-
"$dynamicAnchor": "meta",
65-
"type": [ "object", "boolean" ],
66-
"properties": {
67-
"minDate": {
68-
"type": "string",
69-
"pattern": "\\d\\d\\d\\d-\\d\\d-\\d\\d",
70-
"format": "date"
71-
}
72-
}
73-
}
74-
{{</schema>}}
75-
76-
{{<learning-more>}}
77-
The `$dynamicAnchor: meta` declaration is set by convention to `meta` on the official meta-schemas. This setting serves as a mechanism to enable meta-schema extensibility. By declaring `$dynamicAnchor: meta` here, JSON Schema is configured to validate every subschema of the instance schema against the meta-schema, extending validation beyond just the top level.
78-
{{</learning-more>}}
79-
80-
{{<schema `Meta-schema with the above vocabulary as required`>}}
81-
{
82-
"$schema": "https://json-schema.org/draft/2020-12/schema",
83-
"$id": "https://example.com/schema-required",
69+
"$id": "https://example.com/2020-12-with-format-assertion",
8470
"$dynamicAnchor": "meta",
8571
"$vocabulary": {
8672
"https://json-schema.org/draft/2020-12/vocab/core": true,
87-
"https://example.com/vocab/example-vocab": "true"
73+
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
74+
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
75+
"https://json-schema.org/draft/2020-12/vocab/validation": true,
76+
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
77+
"https://json-schema.org/draft/2020-12/vocab/format-assertion": true,
78+
"https://json-schema.org/draft/2020-12/vocab/content": true
8879
},
8980
"allOf": [
9081
{ "$ref": "https://json-schema.org/draft/2020-12/meta/core" },
91-
{ "$ref": "https://example.com/meta/example-vocab" }
82+
{ "$ref": "https://json-schema.org/draft/2020-12/meta/applicator" },
83+
{ "$ref": "https://json-schema.org/draft/2020-12/meta/unevaluated" },
84+
{ "$ref": "https://json-schema.org/draft/2020-12/meta/validation" },
85+
{ "$ref": "https://json-schema.org/draft/2020-12/meta/meta-data" },
86+
{ "$ref": "https://json-schema.org/draft/2020-12/meta/format-assertion" },
87+
{ "$ref": "https://json-schema.org/draft/2020-12/meta/content" }
9288
]
9389
}
9490
{{</schema>}}
9591

96-
{{<schema `Meta-schema with the above vocabulary as optional`>}}
92+
{{<schema `An example dialect meta-schema that imports the Core vocabulary as required and the Validation vocabulary as optional`>}}
9793
{
9894
"$schema": "https://json-schema.org/draft/2020-12/schema",
99-
"$id": "https://example.com/schema-optional",
95+
"$id": "https://example.com/simple-2020-12",
10096
"$dynamicAnchor": "meta",
10197
"$vocabulary": {
10298
"https://json-schema.org/draft/2020-12/vocab/core": true,
103-
"https://example.com/vocab/example-vocab": "false"
99+
"https://json-schema.org/draft/2020-12/vocab/validation": false
104100
},
105101
"allOf": [
106102
{ "$ref": "https://json-schema.org/draft/2020-12/meta/core" },
107-
{ "$ref": "https://example.com/meta/example-vocab" }
103+
{ "$ref": "https://json-schema.org/draft/2020-12/meta/validation" }
108104
]
109105
}
110106
{{</schema>}}
111-
112-
{{<schema `Schema that uses the above meta-schema`>}}
113-
{
114-
"$schema": "https://example.com/schema-required",
115-
"$id": "https://my-schema.com",
116-
"minDate": "2024-05-17"
117-
}
118-
{{</schema>}}

0 commit comments

Comments
 (0)