Skip to content

Commit

Permalink
pycodegen: fix secondaryFiles DSL (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c authored Nov 12, 2020
1 parent 0be3a0d commit 5e8fe09
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion schema_salad/codegen_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ def epilogue(self, root_loader: TypeDef) -> None:
"""Trigger to generate the epilouge code."""
raise NotImplementedError()

def secondaryfilesdsl_loader(self, type_loader: TypeDef) -> TypeDef:
def secondaryfilesdsl_loader(self, inner: TypeDef) -> TypeDef:
"""Construct the TypeDef for secondary files"""
raise NotImplementedError()
44 changes: 36 additions & 8 deletions schema_salad/python_codegen_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,25 +296,53 @@ def load(self, doc, baseuri, loadingOptions, docRoot=None):


class _SecondaryDSLLoader(_Loader):
def __init__(self, items):
def __init__(self, inner):
# type: (_Loader) -> None
self.items = items
self.inner = inner

def load(self, doc, baseuri, loadingOptions, docRoot=None):
# type: (Any, str, LoadingOptions, Optional[str]) -> Any
r: List[Dict[str, Any]] = []
if isinstance(doc, MutableSequence):
r = [] # type: List[Any]
for d in doc:
if isinstance(d, str):
r.append(d)
if d.endswith("?"):
r.append({"pattern": d[:-1], "required": False})
else:
r.append({"pattern": d})
elif isinstance(d, dict):
new_dict: Dict[str, Any] = {}
if "pattern" in d:
new_dict["pattern"] = d.pop("pattern")
else:
raise ValidationException(
"Missing pattern in secondaryFiles specification entry: {}".format(
d
)
)
new_dict["required"] = (
d.pop("required") if "required" in d else None
)

if len(d):
raise ValidationException(
"Unallowed values in secondaryFiles specification entry: {}".format(
d
)
)

else:
raise ValidationException("Expected str or sequence of str")
doc = r
raise ValidationException(
"Expected a string or sequence of (strings or mappings)."
)
elif isinstance(doc, str):
pass
if doc.endswith("?"):
r.append({"pattern": doc[:-1], "required": False})
else:
r.append({"pattern": doc})
else:
raise ValidationException("Expected str or sequence of str")
return doc
return self.inner.load(r, baseuri, loadingOptions, docRoot)


class _RecordLoader(_Loader):
Expand Down

0 comments on commit 5e8fe09

Please sign in to comment.