summaryrefslogtreecommitdiff
path: root/jsonschema/validators.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2022-08-16 10:05:46 +0300
committerJulian Berman <Julian@GrayVines.com>2022-08-16 10:11:51 +0300
commit18a64d7e0fd15370ad60c01047916fc705a60c84 (patch)
tree7ef700d437408890f8246589c78a36fc3b692097 /jsonschema/validators.py
parent9aea572efe7c094dba03e98d5879867087f78292 (diff)
downloadjsonschema-18a64d7e0fd15370ad60c01047916fc705a60c84.tar.gz
Add support for referencing schemas across different drafts.
In other words, a draft 7 schema may reference a draft 2019 schema (or vice versa), and now correctly apply the 2019 rules within the referenced schema. Refs: json-schema-org/JSON-Schema-Test-Suite#587
Diffstat (limited to 'jsonschema/validators.py')
-rw-r--r--jsonschema/validators.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 9ead094..4fa10cc 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -189,7 +189,6 @@ def create(
schema = attr.ib(repr=reprlib.repr)
resolver = attr.ib(default=None, repr=False)
format_checker = attr.ib(default=None)
- evolve = attr.evolve
def __attrs_post_init__(self):
if self.resolver is None:
@@ -203,6 +202,22 @@ def create(
for error in cls(cls.META_SCHEMA).iter_errors(schema):
raise exceptions.SchemaError.create_from(error)
+ def evolve(self, **changes):
+ schema = changes.setdefault("schema", self.schema)
+ NewValidator = validator_for(schema, default=Validator)
+
+ # Essentially reproduces attr.evolve, but may involve instantiating
+ # a different class than this one.
+ for field in attr.fields(Validator):
+ if not field.init:
+ continue
+ attr_name = field.name # To deal with private attributes.
+ init_name = attr_name if attr_name[0] != "_" else attr_name[1:]
+ if init_name not in changes:
+ changes[init_name] = getattr(self, attr_name)
+
+ return NewValidator(**changes)
+
def iter_errors(self, instance, _schema=None):
if _schema is not None:
warnings.warn(