Skip to content

Commit 77c2483

Browse files
committed
Fix the old typeDSL handling for better message
1 parent 15833b9 commit 77c2483

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

schema_salad/metaschema.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,15 @@ def resolve(
595595
if doc_.endswith("[]"):
596596
salad_versions = [int(v) for v in self.salad_version[1:].split(".")]
597597
items = "" # type: Union[List[Union[Dict[str, Any], str]], Dict[str, Any], str]
598+
rest = doc_[0:-2]
598599
if salad_versions < [1, 3]:
599-
items = expand_url(doc_[0:-2], baseuri, loadingOptions, False, True, self.refScope)
600+
if rest.endswith("[]"):
601+
# To show the error message with the original type
602+
return doc
603+
else:
604+
items = expand_url(rest, baseuri, loadingOptions, False, True, self.refScope)
600605
else:
601-
items = self.resolve(doc_[0:-2], baseuri, loadingOptions)
606+
items = self.resolve(rest, baseuri, loadingOptions)
602607
if isinstance(items, str):
603608
items = expand_url(items, baseuri, loadingOptions, False, True, self.refScope)
604609
expanded = {"type": "array", "items": items} # type: Union[Dict[str, Any], str]

schema_salad/python_codegen_support.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,15 @@ def resolve(
592592
if doc_.endswith("[]"):
593593
salad_versions = [int(v) for v in self.salad_version[1:].split(".")]
594594
items = "" # type: Union[List[Union[Dict[str, Any], str]], Dict[str, Any], str]
595+
rest = doc_[0:-2]
595596
if salad_versions < [1, 3]:
596-
items = expand_url(doc_[0:-2], baseuri, loadingOptions, False, True, self.refScope)
597+
if rest.endswith("[]"):
598+
# To show the error message with the original type
599+
return doc
600+
else:
601+
items = expand_url(rest, baseuri, loadingOptions, False, True, self.refScope)
597602
else:
598-
items = self.resolve(doc_[0:-2], baseuri, loadingOptions)
603+
items = self.resolve(rest, baseuri, loadingOptions)
599604
if isinstance(items, str):
600605
items = expand_url(items, baseuri, loadingOptions, False, True, self.refScope)
601606
expanded = {"type": "array", "items": items} # type: Union[Dict[str, Any], str]

schema_salad/ref_resolver.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,15 @@ def _type_dsl(
645645

646646
if t_.endswith("[]"):
647647
salad_versions = [int(v) for v in self.salad_version[1:].split(".")]
648+
rest = t_[0:-2]
648649
if salad_versions < [1, 3]:
649-
cmap = CommentedMap((("type", "array"), ("items", t_[0:-2])))
650+
if rest.endswith("[]"):
651+
# To show the error message with the original type
652+
return t
653+
else:
654+
cmap = CommentedMap((("type", "array"), ("items", rest)))
650655
else:
651-
items = self._type_dsl(t_[0:-2], lc, filename)
656+
items = self._type_dsl(rest, lc, filename)
652657
cmap = CommentedMap((("type", "array"), ("items", items)))
653658
cmap.lc.add_kv_line_col("type", lc)
654659
cmap.lc.add_kv_line_col("items", lc)

schema_salad/tests/test_examples.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import schema_salad.main
1111
import schema_salad.schema
12+
from schema_salad.exceptions import ValidationException
1213
from schema_salad.jsonld_context import makerdf
1314
from schema_salad.ref_resolver import Loader, file_uri, uri_file_path
1415
from schema_salad.sourceline import SourceLine, cmap
@@ -355,8 +356,8 @@ def test_typedsl_ref() -> None:
355356
ra, _ = ldr.resolve_all(cmap({"type": "File[]?"}), "")
356357
assert {"type": ["null", {"items": "File", "type": "array"}]} == ra
357358

358-
ra, _ = ldr.resolve_all(cmap({"type": "File[][]"}), "")
359-
assert {"type": {"items": "File[]", "type": "array"}} == ra
359+
with pytest.raises(ValidationException):
360+
ldr.resolve_all(cmap({"type": "File[][]"}), "")
360361

361362

362363
def test_nested_typedsl_ref() -> None:

0 commit comments

Comments
 (0)