Skip to content

Commit cf4da26

Browse files
committed
Pull in current draft metaschemas and vocabularies.
1 parent 3d6bc89 commit cf4da26

26 files changed

+1370
-4
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
exclude: jsonschema_specifications/schemas/
2+
13
repos:
24
- repo: https://github.com/pre-commit/pre-commit-hooks
35
rev: v4.4.0

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pyrsistent==0.19.2
4949
# via referencing
5050
pytz==2022.7
5151
# via babel
52-
referencing==0.8.8
52+
referencing==0.8.9
5353
# via jsonschema-specifications
5454
requests==2.28.1
5555
# via sphinx

jsonschema_specifications/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from jsonschema_specifications._core import REGISTRY # noqa: F401

jsonschema_specifications/_core.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
A `referencing.Registry` containing schemas from the JSON Schema specification.
3+
"""
4+
5+
import json
6+
7+
try:
8+
from importlib.resources import files
9+
except ImportError:
10+
from importlib_resources import files # type: ignore
11+
12+
from referencing import IdentifiedResource, Registry
13+
14+
15+
def _schemas():
16+
"""
17+
All schemas we ship.
18+
"""
19+
20+
# importlib.resources.abc.Traversal doesn't have nice ways to do this that
21+
# I'm aware of...
22+
#
23+
# It can't recurse arbitrarily, e.g. no ``.glob()``.
24+
#
25+
# So this takes some liberties given the real layout of what we ship
26+
# (only 2 levels of nesting, no directories within the second level).
27+
28+
for version in files(__package__).joinpath("schemas").iterdir():
29+
for child in version.iterdir():
30+
children = [child] if child.is_file() else child.iterdir()
31+
for path in children:
32+
contents = json.loads(path.read_text())
33+
resource = IdentifiedResource.from_resource(contents)
34+
yield resource.id(), resource
35+
36+
37+
REGISTRY = Registry().with_identified_resources(_schemas())
38+
# FIXME: as soon as _crawl has a public replacement
39+
REGISTRY = REGISTRY._crawl()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "https://json-schema.org/draft/2019-09/schema",
4+
"$vocabulary": {
5+
"https://json-schema.org/draft/2019-09/vocab/core": true,
6+
"https://json-schema.org/draft/2019-09/vocab/applicator": true,
7+
"https://json-schema.org/draft/2019-09/vocab/validation": true,
8+
"https://json-schema.org/draft/2019-09/vocab/meta-data": true,
9+
"https://json-schema.org/draft/2019-09/vocab/format": false,
10+
"https://json-schema.org/draft/2019-09/vocab/content": true
11+
},
12+
"$recursiveAnchor": true,
13+
14+
"title": "Core and Validation specifications meta-schema",
15+
"allOf": [
16+
{"$ref": "meta/core"},
17+
{"$ref": "meta/applicator"},
18+
{"$ref": "meta/validation"},
19+
{"$ref": "meta/meta-data"},
20+
{"$ref": "meta/format"},
21+
{"$ref": "meta/content"}
22+
],
23+
"type": ["object", "boolean"],
24+
"properties": {
25+
"definitions": {
26+
"$comment": "While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.",
27+
"type": "object",
28+
"additionalProperties": { "$recursiveRef": "#" },
29+
"default": {}
30+
},
31+
"dependencies": {
32+
"$comment": "\"dependencies\" is no longer a keyword, but schema authors should avoid redefining it to facilitate a smooth transition to \"dependentSchemas\" and \"dependentRequired\"",
33+
"type": "object",
34+
"additionalProperties": {
35+
"anyOf": [
36+
{ "$recursiveRef": "#" },
37+
{ "$ref": "meta/validation#/$defs/stringArray" }
38+
]
39+
}
40+
}
41+
}
42+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "https://json-schema.org/draft/2019-09/meta/applicator",
4+
"$vocabulary": {
5+
"https://json-schema.org/draft/2019-09/vocab/applicator": true
6+
},
7+
"$recursiveAnchor": true,
8+
9+
"title": "Applicator vocabulary meta-schema",
10+
"type": ["object", "boolean"],
11+
"properties": {
12+
"additionalItems": { "$recursiveRef": "#" },
13+
"unevaluatedItems": { "$recursiveRef": "#" },
14+
"items": {
15+
"anyOf": [
16+
{ "$recursiveRef": "#" },
17+
{ "$ref": "#/$defs/schemaArray" }
18+
]
19+
},
20+
"contains": { "$recursiveRef": "#" },
21+
"additionalProperties": { "$recursiveRef": "#" },
22+
"unevaluatedProperties": { "$recursiveRef": "#" },
23+
"properties": {
24+
"type": "object",
25+
"additionalProperties": { "$recursiveRef": "#" },
26+
"default": {}
27+
},
28+
"patternProperties": {
29+
"type": "object",
30+
"additionalProperties": { "$recursiveRef": "#" },
31+
"propertyNames": { "format": "regex" },
32+
"default": {}
33+
},
34+
"dependentSchemas": {
35+
"type": "object",
36+
"additionalProperties": {
37+
"$recursiveRef": "#"
38+
}
39+
},
40+
"propertyNames": { "$recursiveRef": "#" },
41+
"if": { "$recursiveRef": "#" },
42+
"then": { "$recursiveRef": "#" },
43+
"else": { "$recursiveRef": "#" },
44+
"allOf": { "$ref": "#/$defs/schemaArray" },
45+
"anyOf": { "$ref": "#/$defs/schemaArray" },
46+
"oneOf": { "$ref": "#/$defs/schemaArray" },
47+
"not": { "$recursiveRef": "#" }
48+
},
49+
"$defs": {
50+
"schemaArray": {
51+
"type": "array",
52+
"minItems": 1,
53+
"items": { "$recursiveRef": "#" }
54+
}
55+
}
56+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "https://json-schema.org/draft/2019-09/meta/content",
4+
"$vocabulary": {
5+
"https://json-schema.org/draft/2019-09/vocab/content": true
6+
},
7+
"$recursiveAnchor": true,
8+
9+
"title": "Content vocabulary meta-schema",
10+
11+
"type": ["object", "boolean"],
12+
"properties": {
13+
"contentMediaType": { "type": "string" },
14+
"contentEncoding": { "type": "string" },
15+
"contentSchema": { "$recursiveRef": "#" }
16+
}
17+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "https://json-schema.org/draft/2019-09/meta/core",
4+
"$vocabulary": {
5+
"https://json-schema.org/draft/2019-09/vocab/core": true
6+
},
7+
"$recursiveAnchor": true,
8+
9+
"title": "Core vocabulary meta-schema",
10+
"type": ["object", "boolean"],
11+
"properties": {
12+
"$id": {
13+
"type": "string",
14+
"format": "uri-reference",
15+
"$comment": "Non-empty fragments not allowed.",
16+
"pattern": "^[^#]*#?$"
17+
},
18+
"$schema": {
19+
"type": "string",
20+
"format": "uri"
21+
},
22+
"$anchor": {
23+
"type": "string",
24+
"pattern": "^[A-Za-z][-A-Za-z0-9.:_]*$"
25+
},
26+
"$ref": {
27+
"type": "string",
28+
"format": "uri-reference"
29+
},
30+
"$recursiveRef": {
31+
"type": "string",
32+
"format": "uri-reference"
33+
},
34+
"$recursiveAnchor": {
35+
"type": "boolean",
36+
"default": false
37+
},
38+
"$vocabulary": {
39+
"type": "object",
40+
"propertyNames": {
41+
"type": "string",
42+
"format": "uri"
43+
},
44+
"additionalProperties": {
45+
"type": "boolean"
46+
}
47+
},
48+
"$comment": {
49+
"type": "string"
50+
},
51+
"$defs": {
52+
"type": "object",
53+
"additionalProperties": { "$recursiveRef": "#" },
54+
"default": {}
55+
}
56+
}
57+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "https://json-schema.org/draft/2019-09/meta/meta-data",
4+
"$vocabulary": {
5+
"https://json-schema.org/draft/2019-09/vocab/meta-data": true
6+
},
7+
"$recursiveAnchor": true,
8+
9+
"title": "Meta-data vocabulary meta-schema",
10+
11+
"type": ["object", "boolean"],
12+
"properties": {
13+
"title": {
14+
"type": "string"
15+
},
16+
"description": {
17+
"type": "string"
18+
},
19+
"default": true,
20+
"deprecated": {
21+
"type": "boolean",
22+
"default": false
23+
},
24+
"readOnly": {
25+
"type": "boolean",
26+
"default": false
27+
},
28+
"writeOnly": {
29+
"type": "boolean",
30+
"default": false
31+
},
32+
"examples": {
33+
"type": "array",
34+
"items": true
35+
}
36+
}
37+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "https://json-schema.org/draft/2019-09/meta/validation",
4+
"$vocabulary": {
5+
"https://json-schema.org/draft/2019-09/vocab/validation": true
6+
},
7+
"$recursiveAnchor": true,
8+
9+
"title": "Validation vocabulary meta-schema",
10+
"type": ["object", "boolean"],
11+
"properties": {
12+
"multipleOf": {
13+
"type": "number",
14+
"exclusiveMinimum": 0
15+
},
16+
"maximum": {
17+
"type": "number"
18+
},
19+
"exclusiveMaximum": {
20+
"type": "number"
21+
},
22+
"minimum": {
23+
"type": "number"
24+
},
25+
"exclusiveMinimum": {
26+
"type": "number"
27+
},
28+
"maxLength": { "$ref": "#/$defs/nonNegativeInteger" },
29+
"minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
30+
"pattern": {
31+
"type": "string",
32+
"format": "regex"
33+
},
34+
"maxItems": { "$ref": "#/$defs/nonNegativeInteger" },
35+
"minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
36+
"uniqueItems": {
37+
"type": "boolean",
38+
"default": false
39+
},
40+
"maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
41+
"minContains": {
42+
"$ref": "#/$defs/nonNegativeInteger",
43+
"default": 1
44+
},
45+
"maxProperties": { "$ref": "#/$defs/nonNegativeInteger" },
46+
"minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
47+
"required": { "$ref": "#/$defs/stringArray" },
48+
"dependentRequired": {
49+
"type": "object",
50+
"additionalProperties": {
51+
"$ref": "#/$defs/stringArray"
52+
}
53+
},
54+
"const": true,
55+
"enum": {
56+
"type": "array",
57+
"items": true
58+
},
59+
"type": {
60+
"anyOf": [
61+
{ "$ref": "#/$defs/simpleTypes" },
62+
{
63+
"type": "array",
64+
"items": { "$ref": "#/$defs/simpleTypes" },
65+
"minItems": 1,
66+
"uniqueItems": true
67+
}
68+
]
69+
}
70+
},
71+
"$defs": {
72+
"nonNegativeInteger": {
73+
"type": "integer",
74+
"minimum": 0
75+
},
76+
"nonNegativeIntegerDefault0": {
77+
"$ref": "#/$defs/nonNegativeInteger",
78+
"default": 0
79+
},
80+
"simpleTypes": {
81+
"enum": [
82+
"array",
83+
"boolean",
84+
"integer",
85+
"null",
86+
"number",
87+
"object",
88+
"string"
89+
]
90+
},
91+
"stringArray": {
92+
"type": "array",
93+
"items": { "type": "string" },
94+
"uniqueItems": true,
95+
"default": []
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)