diff options
author | Harald Nezbeda <hn@nezhar.com> | 2021-06-23 21:15:41 +0200 |
---|---|---|
committer | Harald Nezbeda <hn@nezhar.com> | 2021-07-20 17:08:39 +0200 |
commit | f8555cd4a7458b0dd8c39f869d18c1b3cc67e816 (patch) | |
tree | 25089e61fbe344b7ada54b2fd8cc3784a06c0955 /jsonschema/_validators.py | |
parent | 73ec5a45f21112d9d8233f6e374acc2163a18dbd (diff) | |
download | jsonschema-f8555cd4a7458b0dd8c39f869d18c1b3cc67e816.tar.gz |
Julian/jsonschema#782: Implements dynamicRef validations
Diffstat (limited to 'jsonschema/_validators.py')
-rw-r--r-- | jsonschema/_validators.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py index 448b306..588d957 100644 --- a/jsonschema/_validators.py +++ b/jsonschema/_validators.py @@ -1,4 +1,5 @@ from fractions import Fraction +from urllib.parse import urldefrag, urljoin import re from jsonschema._utils import ( @@ -384,6 +385,24 @@ def ref(validator, ref, instance, schema): validator.resolver.pop_scope() +def dynamicRef(validator, dynamicRef, instance, schema): + _, fragment = urldefrag(dynamicRef) + scope_stack = validator.resolver.scopes_stack_copy + + for url in scope_stack: + with validator.resolver.resolving(urljoin(url, dynamicRef)) as lookup_schema: + if "$dynamicAnchor" in lookup_schema and fragment == lookup_schema["$dynamicAnchor"]: + subschema = lookup_schema + for error in validator.descend(instance, subschema): + yield error + break + else: + with validator.resolver.resolving(dynamicRef) as lookup_schema: + subschema = lookup_schema + for error in validator.descend(instance, subschema): + yield error + + def defs(validator, defs, instance, schema): if not validator.is_type(instance, "object"): return |