summaryrefslogtreecommitdiff
path: root/jsonschema/_utils.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2023-02-16 12:32:00 +0200
committerJulian Berman <Julian@GrayVines.com>2023-02-21 09:58:40 +0200
commite8266294408521daf38d879ba35c45a4b0ef5180 (patch)
tree0dba5b9aafc21b65d0a48b744cea021770e8e9d9 /jsonschema/_utils.py
parenta39e5c953a559b287c753bd604e3e11d218c29cf (diff)
downloadjsonschema-e8266294408521daf38d879ba35c45a4b0ef5180.tar.gz
Resolve $ref using the referencing library.
Passes all the remaining referencing tests across all drafts, hooray! Makes Validators take a referencing.Registry argument which users should use to customize preloaded schemas, or to configure remote reference retrieval. This fully obsoletes jsonschema.RefResolver, which has already been deprecated in a previous commit. Users should move to instead loading schemas into referencing.Registry objects. See the referencing documentation at https://referencing.rtfd.io/ for details (with more jsonschema-specific information to be added shortly). Note that the interface for resolving references on a Validator is not yet public (and hidden behind _resolver and _validate_reference attributes). One or both of these are likely to become public after some period of stabilization. Feedback is of course welcome!
Diffstat (limited to 'jsonschema/_utils.py')
-rw-r--r--jsonschema/_utils.py40
1 files changed, 22 insertions, 18 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py
index c218b18..b14b70e 100644
--- a/jsonschema/_utils.py
+++ b/jsonschema/_utils.py
@@ -201,15 +201,17 @@ def find_evaluated_item_indexes_by_schema(validator, instance, schema):
return list(range(0, len(instance)))
if "$ref" in schema:
- scope, resolved = validator.resolver.resolve(schema["$ref"])
- validator.resolver.push_scope(scope)
-
- try:
- evaluated_indexes += find_evaluated_item_indexes_by_schema(
- validator, instance, resolved,
- )
- finally:
- validator.resolver.pop_scope()
+ resolved = validator._resolver.lookup(schema["$ref"])
+ evaluated_indexes.extend(
+ find_evaluated_item_indexes_by_schema(
+ validator.evolve(
+ schema=resolved.contents,
+ _resolver=resolved.resolver,
+ ),
+ instance,
+ resolved.contents,
+ ),
+ )
if "prefixItems" in schema:
evaluated_indexes += list(range(0, len(schema["prefixItems"])))
@@ -260,15 +262,17 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
evaluated_keys = []
if "$ref" in schema:
- scope, resolved = validator.resolver.resolve(schema["$ref"])
- validator.resolver.push_scope(scope)
-
- try:
- evaluated_keys += find_evaluated_property_keys_by_schema(
- validator, instance, resolved,
- )
- finally:
- validator.resolver.pop_scope()
+ resolved = validator._resolver.lookup(schema["$ref"])
+ evaluated_keys.extend(
+ find_evaluated_property_keys_by_schema(
+ validator.evolve(
+ schema=resolved.contents,
+ _resolver=resolved.resolver,
+ ),
+ instance,
+ resolved.contents,
+ ),
+ )
for keyword in [
"properties", "additionalProperties", "unevaluatedProperties",