Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pycodegen: fix secondaryFiles DSL #360

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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