diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index e561f3e2b..f65997934 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -146,30 +146,6 @@ def narrow_unicode_build(test): # pragma: no cover narrow_unicode_build(test) or missing_format(draft4_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="ref", - case_description="Location-independent identifier", - )(test) - or skip( - message=bug(371), - subject="ref", - case_description=( - "Location-independent identifier with absolute URI" - ), - )(test) - or skip( - message=bug(371), - subject="ref", - case_description=( - "Location-independent identifier with base URI change in subschema" - ), - )(test) or skip( message=bug(), subject="refRemote", @@ -220,30 +196,6 @@ def narrow_unicode_build(test): # pragma: no cover narrow_unicode_build(test) or missing_format(draft6_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="ref", - case_description="Location-independent identifier", - )(test) - or skip( - message=bug(371), - subject="ref", - case_description=( - "Location-independent identifier with absolute URI" - ), - )(test) - or skip( - message=bug(371), - subject="ref", - case_description=( - "Location-independent identifier with base URI change in subschema" - ), - )(test) or skip( message=bug(), subject="refRemote", @@ -295,30 +247,6 @@ def narrow_unicode_build(test): # pragma: no cover narrow_unicode_build(test) or missing_format(draft7_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="ref", - case_description="Location-independent identifier", - )(test) - or skip( - message=bug(371), - subject="ref", - case_description=( - "Location-independent identifier with absolute URI" - ), - )(test) - or skip( - message=bug(371), - subject="ref", - case_description=( - "Location-independent identifier with base URI change in subschema" - ), - )(test) or skip( message=bug(), subject="refRemote", diff --git a/jsonschema/validators.py b/jsonschema/validators.py index dd4a3abe4..1081100fd 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -5,6 +5,7 @@ import contextlib import json import numbers +import copy from jsonschema import ( _legacy_validators, @@ -654,6 +655,7 @@ def __init__( ) self.store.update(store) self.store[base_uri] = referrer + self.store_subschema(referrer, last_url=base_uri) self._urljoin_cache = urljoin_cache self._remote_cache = remote_cache @@ -862,6 +864,40 @@ def resolve_remote(self, uri): self.store[uri] = result return result + def store_subschema(self, schema, last_url=None): + """ + Using $id or id with $ref, save subschema to self.store + + Arguments: + + schema: + + The referring schema. + + last_url: + + The last URL. + """ + if not isinstance(schema, dict): + return + + for k in schema.keys(): + if k in [u"id", u"$id"] and isinstance(schema[k], str): + # Splicing the url in the last id with the url in this id, + # and store last_url at the same time. + last_url = urljoin(last_url, schema[k], allow_fragments=True) + url, fragment = urldefrag(last_url) + + # Save the schema into self.store[url] + self.store[url] = copy.deepcopy(schema) + + # Add fragment element in self.store[url] + if fragment: + self.store[url][fragment] = copy.deepcopy(schema) + + if isinstance(schema[k], dict): + self.store_subschema(schema[k], last_url) + def validate(instance, schema, cls=None, *args, **kwargs): """