Skip to content

Commit

Permalink
Merge pull request #3995 from open-formulieren/issue/3688-no-spec
Browse files Browse the repository at this point in the history
[#3688] Fix issue when no JSON Schema spec is provided
  • Loading branch information
sergei-maertens authored Mar 12, 2024
2 parents ef9be79 + 178304f commit 78dea0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from jsonschema_specifications import REGISTRY
from referencing import Resource
from referencing.exceptions import Unresolvable
from referencing.jsonschema import ObjectSchema
from referencing.jsonschema import DRAFT202012, ObjectSchema
from typing_extensions import Self


Expand Down Expand Up @@ -68,7 +68,7 @@ def iter_json_schema_paths(
Known to be unsupported:
- Composition (https://json-schema.org/understanding-json-schema/reference/combining)
"""
resource = Resource.from_contents(json_schema)
resource = Resource.from_contents(json_schema, default_specification=DRAFT202012)
# Or referencing.jsonschema.EMPTY_REGISTRY?
resolver = REGISTRY.resolver_with_root(resource)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
json_schema_matches,
)

JSON_SCHEMA_NO_SPEC = {"type": "object", "properties": {"prop": {"type": "string"}}}

JSON_SCHEMA_NO_REFS = {
"$id": "noise-complaint.schema",
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down Expand Up @@ -163,6 +165,12 @@ class IterJsonSchemaTests(SimpleTestCase):
simply be tested as ``([], CURRENT_SCHEMA_TESTED)``.
"""

def test_no_spec_default(self):
try:
list(iter_json_schema_paths(JSON_SCHEMA_NO_SPEC))
except Exception as e:
raise self.failureException("Unexpected exception") from e

def test_iter_json_schema_no_refs(self):
paths_list = [
(path.segments, schema)
Expand Down

0 comments on commit 78dea0c

Please sign in to comment.