Skip to content

Commit ff86a54

Browse files
committed
process secondaryFiles DSLs non-destructively
1 parent 42d6172 commit ff86a54

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

schema_salad/metaschema.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,22 +438,23 @@ def load(self, doc, baseuri, loadingOptions, docRoot=None):
438438
r.append({"pattern": d})
439439
elif isinstance(d, dict):
440440
new_dict: Dict[str, Any] = {}
441-
if "pattern" in d:
442-
new_dict["pattern"] = d.pop("pattern")
441+
dict_copy = copy.deepcopy(d)
442+
if "pattern" in dict_copy:
443+
new_dict["pattern"] = dict_copy.pop("pattern")
443444
else:
444445
raise ValidationException(
445446
"Missing pattern in secondaryFiles specification entry: {}".format(
446447
d
447448
)
448449
)
449450
new_dict["required"] = (
450-
d.pop("required") if "required" in d else None
451+
dict_copy.pop("required") if "required" in dict_copy else None
451452
)
452453

453-
if len(d):
454+
if len(dict_copy):
454455
raise ValidationException(
455456
"Unallowed values in secondaryFiles specification entry: {}".format(
456-
d
457+
dict_copy
457458
)
458459
)
459460
r.append(new_dict)
@@ -464,20 +465,23 @@ def load(self, doc, baseuri, loadingOptions, docRoot=None):
464465
)
465466
elif isinstance(doc, MutableMapping):
466467
new_dict = {}
467-
if "pattern" in doc:
468-
new_dict["pattern"] = doc.pop("pattern")
468+
doc_copy = copy.deepcopy(doc)
469+
if "pattern" in doc_copy:
470+
new_dict["pattern"] = doc_copy.pop("pattern")
469471
else:
470472
raise ValidationException(
471473
"Missing pattern in secondaryFiles specification entry: {}".format(
472474
doc
473475
)
474476
)
475-
new_dict["required"] = doc.pop("required") if "required" in doc else None
477+
new_dict["required"] = (
478+
doc_copy.pop("required") if "required" in doc_copy else None
479+
)
476480

477-
if len(doc):
481+
if len(doc_copy):
478482
raise ValidationException(
479483
"Unallowed values in secondaryFiles specification entry: {}".format(
480-
doc
484+
doc_copy
481485
)
482486
)
483487
r.append(new_dict)

schema_salad/python_codegen_support.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,22 +435,23 @@ def load(self, doc, baseuri, loadingOptions, docRoot=None):
435435
r.append({"pattern": d})
436436
elif isinstance(d, dict):
437437
new_dict: Dict[str, Any] = {}
438-
if "pattern" in d:
439-
new_dict["pattern"] = d.pop("pattern")
438+
dict_copy = copy.deepcopy(d)
439+
if "pattern" in dict_copy:
440+
new_dict["pattern"] = dict_copy.pop("pattern")
440441
else:
441442
raise ValidationException(
442443
"Missing pattern in secondaryFiles specification entry: {}".format(
443444
d
444445
)
445446
)
446447
new_dict["required"] = (
447-
d.pop("required") if "required" in d else None
448+
dict_copy.pop("required") if "required" in dict_copy else None
448449
)
449450

450-
if len(d):
451+
if len(dict_copy):
451452
raise ValidationException(
452453
"Unallowed values in secondaryFiles specification entry: {}".format(
453-
d
454+
dict_copy
454455
)
455456
)
456457
r.append(new_dict)
@@ -461,20 +462,23 @@ def load(self, doc, baseuri, loadingOptions, docRoot=None):
461462
)
462463
elif isinstance(doc, MutableMapping):
463464
new_dict = {}
464-
if "pattern" in doc:
465-
new_dict["pattern"] = doc.pop("pattern")
465+
doc_copy = copy.deepcopy(doc)
466+
if "pattern" in doc_copy:
467+
new_dict["pattern"] = doc_copy.pop("pattern")
466468
else:
467469
raise ValidationException(
468470
"Missing pattern in secondaryFiles specification entry: {}".format(
469471
doc
470472
)
471473
)
472-
new_dict["required"] = doc.pop("required") if "required" in doc else None
474+
new_dict["required"] = (
475+
doc_copy.pop("required") if "required" in doc_copy else None
476+
)
473477

474-
if len(doc):
478+
if len(doc_copy):
475479
raise ValidationException(
476480
"Unallowed values in secondaryFiles specification entry: {}".format(
477-
doc
481+
doc_copy
478482
)
479483
)
480484
r.append(new_dict)

0 commit comments

Comments
 (0)