Skip to content

Commit

Permalink
Don't blow up if an automatically retrieved resource is missing $schema.
Browse files Browse the repository at this point in the history
This should possibly default to the specification that the child resource
is contained within, but that's actually nontrivial to implement...
  • Loading branch information
Julian committed Aug 7, 2023
1 parent eaf2e7b commit 2f5ff0b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -3,6 +3,9 @@ v4.19.0

* Importing the ``Validator`` protocol directly from the package root is deprecated.
Import it from ``jsonschema.protocols.Validator`` instead.
* Automatic retrieval of remote references (which is still deprecated) now properly succeeds even if the retrieved resource does not declare which version of JSON Schema it uses.
Such resources are assumed to be 2020-12 schemas.
This more closely matches the pre-referencing library behavior.

v4.18.6
=======
Expand Down
5 changes: 1 addition & 4 deletions jsonschema/tests/test_deprecations.py
Expand Up @@ -381,10 +381,7 @@ def test_automatic_remote_retrieval(self):
Automatic retrieval of remote references is deprecated as of v4.18.0.
"""
ref = "http://bar#/$defs/baz"
schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {"baz": {"type": "integer"}},
}
schema = {"$defs": {"baz": {"type": "integer"}}}

if "requests" in sys.modules: # pragma: no cover
self.addCleanup(
Expand Down
5 changes: 4 additions & 1 deletion jsonschema/validators.py
Expand Up @@ -119,7 +119,10 @@ def _warn_for_remote_retrieve(uri: str):
DeprecationWarning,
stacklevel=9, # Ha ha ha ha magic numbers :/
)
return referencing.Resource.from_contents(json.load(response))
return referencing.Resource.from_contents(
json.load(response),
default_specification=referencing.jsonschema.DRAFT202012,
)


_REMOTE_WARNING_REGISTRY = SPECIFICATIONS.combine(
Expand Down

0 comments on commit 2f5ff0b

Please sign in to comment.