summaryrefslogtreecommitdiff
path: root/jsonschema
diff options
context:
space:
mode:
Diffstat (limited to 'jsonschema')
-rw-r--r--jsonschema/_legacy_validators.py3
-rw-r--r--jsonschema/validators.py31
2 files changed, 15 insertions, 19 deletions
diff --git a/jsonschema/_legacy_validators.py b/jsonschema/_legacy_validators.py
index f0607d2..b50b78f 100644
--- a/jsonschema/_legacy_validators.py
+++ b/jsonschema/_legacy_validators.py
@@ -217,5 +217,6 @@ def recursiveRef(validator, recursiveRef, instance, schema):
else:
break
- subschema = validator.resolver.resolve_local(recursiveRef, target)
+ fragment = recursiveRef.lstrip("#")
+ subschema = validator.resolver.resolve_fragment(target, fragment)
yield from validator.descend(instance, subschema)
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 0314559..ee1f35b 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -731,30 +731,23 @@ class RefResolver(object):
return results
- def resolve_local(self, url, schema):
+ def resolve(self, ref):
"""
- Resolve the given reference within the schema
+ Resolve the given reference.
"""
+ url = self._urljoin_cache(self.resolution_scope, ref).rstrip("/")
+
uri, fragment = urldefrag(url)
- for subschema in self._finditem(schema, "$id"):
+ for subschema in self._finditem(self.referrer, "$id"):
target_uri = self._urljoin_cache(
self.resolution_scope, subschema["$id"],
)
if target_uri.rstrip("/") == uri.rstrip("/"):
if fragment:
subschema = self.resolve_fragment(subschema, fragment)
- return subschema
+ return url, subschema
- def resolve(self, ref):
- """
- Resolve the given reference.
- """
- url = self._urljoin_cache(self.resolution_scope, ref).rstrip("/")
- local_resolve = self.resolve_local(url, self.referrer)
-
- if local_resolve:
- return url, local_resolve
return url, self._remote_cache(url)
def resolve_from_url(self, url):
@@ -789,11 +782,13 @@ class RefResolver(object):
fragment = fragment.lstrip("/")
- if fragment:
- for keyword in ["$anchor", "$dynamicAnchor"]:
- for subschema in self._finditem(document, keyword):
- if fragment == subschema[keyword]:
- return subschema
+ if not fragment:
+ return document
+
+ for keyword in ["$anchor", "$dynamicAnchor"]:
+ for subschema in self._finditem(document, keyword):
+ if fragment == subschema[keyword]:
+ return subschema
# Resolve via path
parts = unquote(fragment).split("/") if fragment else []