summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-05-08 18:08:26 -0400
committerJulian Berman <Julian@GrayVines.com>2021-05-08 18:08:26 -0400
commit0c0235f21247fb6c3ec6fc1b6a5fbcbfeb0e31f2 (patch)
tree57a35efc585a90e3c58bb94883882a4764f56de3
parent0ea12edea319580473bda7e26ef088ff3a0983c5 (diff)
downloadjsonschema-drafts.tar.gz
-rw-r--r--jsonschema/__init__.py2
-rw-r--r--jsonschema/_format.py1
-rw-r--r--jsonschema/schemas/draft2020-12.json58
-rw-r--r--jsonschema/tests/test_jsonschema_test_suite.py133
-rw-r--r--jsonschema/validators.py19
5 files changed, 213 insertions, 0 deletions
diff --git a/jsonschema/__init__.py b/jsonschema/__init__.py
index 619a7ea..c1cb2e9 100644
--- a/jsonschema/__init__.py
+++ b/jsonschema/__init__.py
@@ -14,6 +14,7 @@ from jsonschema._format import (
draft4_format_checker,
draft6_format_checker,
draft7_format_checker,
+ draft202012_format_checker,
)
from jsonschema._types import TypeChecker
from jsonschema.exceptions import (
@@ -28,6 +29,7 @@ from jsonschema.validators import (
Draft4Validator,
Draft6Validator,
Draft7Validator,
+ Draft202012Validator,
RefResolver,
validate,
)
diff --git a/jsonschema/_format.py b/jsonschema/_format.py
index 6d9be51..2c6df84 100644
--- a/jsonschema/_format.py
+++ b/jsonschema/_format.py
@@ -131,6 +131,7 @@ draft3_format_checker = FormatChecker()
draft4_format_checker = FormatChecker()
draft6_format_checker = FormatChecker()
draft7_format_checker = FormatChecker()
+draft202012_format_checker = FormatChecker()
_draft_checkers = dict(
diff --git a/jsonschema/schemas/draft2020-12.json b/jsonschema/schemas/draft2020-12.json
new file mode 100644
index 0000000..d5e2d31
--- /dev/null
+++ b/jsonschema/schemas/draft2020-12.json
@@ -0,0 +1,58 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "$id": "https://json-schema.org/draft/2020-12/schema",
+ "$vocabulary": {
+ "https://json-schema.org/draft/2020-12/vocab/core": true,
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true,
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
+ "https://json-schema.org/draft/2020-12/vocab/validation": true,
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
+ "https://json-schema.org/draft/2020-12/vocab/content": true
+ },
+ "$dynamicAnchor": "meta",
+
+ "title": "Core and Validation specifications meta-schema",
+ "allOf": [
+ {"$ref": "meta/core"},
+ {"$ref": "meta/applicator"},
+ {"$ref": "meta/unevaluated"},
+ {"$ref": "meta/validation"},
+ {"$ref": "meta/meta-data"},
+ {"$ref": "meta/format-annotation"},
+ {"$ref": "meta/content"}
+ ],
+ "type": ["object", "boolean"],
+ "$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
+ "properties": {
+ "definitions": {
+ "$comment": "\"definitions\" has been replaced by \"$defs\".",
+ "type": "object",
+ "additionalProperties": { "$dynamicRef": "#meta" },
+ "deprecated": true,
+ "default": {}
+ },
+ "dependencies": {
+ "$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
+ "type": "object",
+ "additionalProperties": {
+ "anyOf": [
+ { "$dynamicRef": "#meta" },
+ { "$ref": "meta/validation#/$defs/stringArray" }
+ ]
+ },
+ "deprecated": true,
+ "default": {}
+ },
+ "$recursiveAnchor": {
+ "$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
+ "$ref": "meta/core#/$defs/anchorString",
+ "deprecated": true
+ },
+ "$recursiveRef": {
+ "$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
+ "$ref": "meta/core#/$defs/uriReferenceString",
+ "deprecated": true
+ }
+ }
+}
diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py
index 813182d..82a3ebd 100644
--- a/jsonschema/tests/test_jsonschema_test_suite.py
+++ b/jsonschema/tests/test_jsonschema_test_suite.py
@@ -13,10 +13,12 @@ from jsonschema import (
Draft4Validator,
Draft6Validator,
Draft7Validator,
+ Draft202012Validator,
draft3_format_checker,
draft4_format_checker,
draft6_format_checker,
draft7_format_checker,
+ draft202012_format_checker,
)
from jsonschema.tests._helpers import bug
from jsonschema.tests._suite import Suite
@@ -26,6 +28,7 @@ DRAFT3 = SUITE.version(name="draft3")
DRAFT4 = SUITE.version(name="draft4")
DRAFT6 = SUITE.version(name="draft6")
DRAFT7 = SUITE.version(name="draft7")
+DRAFT202012 = SUITE.version(name="draft2020-12")
def skip(message, **kwargs):
@@ -496,3 +499,133 @@ TestDraft7 = DRAFT7.to_unittest_testcase(
)(test)
),
)
+
+
+TestDraft202012 = DRAFT202012.to_unittest_testcase(
+ DRAFT202012.tests(),
+ DRAFT202012.format_tests(),
+ DRAFT202012.optional_tests_of(name="bignum"),
+ DRAFT202012.optional_tests_of(name="non-bmp-regex"),
+ Validator=Draft202012Validator,
+ format_checker=draft202012_format_checker,
+ skip=lambda test: (
+ narrow_unicode_build(test)
+ or missing_date_fromisoformat(test)
+ or allowed_leading_zeros(test)
+ or leap_second(test)
+ or missing_format(draft202012_format_checker)(test)
+ or complex_email_validation(test)
+ or skip(
+ message=bug(),
+ subject="ref",
+ case_description="Recursive references between schemas",
+ )(test)
+ or skip(
+ message=bug(371),
+ subject="anchor",
+ case_description="Location-independent identifier",
+ )(test)
+ or skip(
+ message=bug(371),
+ subject="anchor",
+ case_description=(
+ "Location-independent identifier with absolute URI"
+ ),
+ )(test)
+ or skip(
+ message=bug(371),
+ subject="anchor",
+ case_description=(
+ "Location-independent identifier with "
+ "base URI change in subschema"
+ ),
+ )(test)
+ or skip(
+ message=bug(371),
+ subject="id",
+ description="match $ref to id",
+ )(test)
+ or skip(
+ message=bug(371),
+ subject="id",
+ description="no match on enum or $ref to id",
+ )(test)
+ or skip(
+ message=bug(),
+ subject="refRemote",
+ case_description="base URI change - change folder in subschema",
+ )(test)
+ or skip(
+ message=bug(593),
+ subject="content",
+ valid=False,
+ case_description=(
+ "validation of string-encoded content based on media type"
+ ),
+ )(test)
+ or skip(
+ message=bug(593),
+ subject="content",
+ valid=False,
+ case_description="validation of binary string-encoding",
+ )(test)
+ or skip(
+ message=bug(593),
+ subject="content",
+ valid=False,
+ case_description=(
+ "validation of binary-encoded media type documents"
+ ),
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="uniqueItems",
+ description="[0] and [false] are unique",
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="uniqueItems",
+ description="[1] and [true] are unique",
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="uniqueItems",
+ description="nested [0] and [false] are unique",
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="uniqueItems",
+ description="nested [1] and [true] are unique",
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="uniqueItems",
+ description='{"a": false} and {"a": 0} are unique',
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="uniqueItems",
+ description='{"a": true} and {"a": 1} are unique',
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="const",
+ case_description="const with [false] does not match [0]",
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="const",
+ case_description="const with [true] does not match [1]",
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="const",
+ case_description='const with {"a": false} does not match {"a": 0}',
+ )(test)
+ or skip(
+ message=bug(686),
+ subject="const",
+ case_description='const with {"a": true} does not match {"a": 1}',
+ )(test)
+ ),
+)
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 70d46c2..6dd56a1 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -428,6 +428,25 @@ Draft7Validator = create(
version="draft7",
)
+Draft202012Validator = create(
+ meta_schema=_utils.load_schema("draft2020-12"),
+ validators={
+ u"$ref": _validators.ref,
+ u"additionalProperties": _validators.additionalProperties,
+ u"allOf": _validators.allOf,
+ u"anyOf": _validators.anyOf,
+ u"enum": _validators.enum,
+ u"maximum": _validators.maximum,
+ u"minimum": _validators.minimum,
+ u"multipleOf": _validators.multipleOf,
+ u"oneOf": _validators.oneOf,
+ u"properties": _validators.properties,
+ u"required": _validators.required,
+ u"type": _validators.type,
+ },
+ version="draft2020-12",
+)
+
_LATEST_VERSION = Draft7Validator