Skip to content

Commit

Permalink
Minor code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Oct 20, 2023
1 parent c658444 commit 6441770
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions snovault/schema_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,28 +643,30 @@ def get_all_required_properties_from_any_of(schema: dict) -> list:
name or list of property names; if the "anyOf" construct looks like it is anything OTHER
than this limited usaage, then an EXCEPTION will be raised.
"""
def raise_unsupported_usage_exception():
raise Exception("Unsupported use of anyOf in schema.")
required_properties = set()
any_of_list = schema.get("anyOf")
if not any_of_list:
return required_properties
if not isinstance(any_of_list, list):
raise Exception("Unsupported use of anyOf in schema.")
raise_unsupported_usage_exception()
for any_of in any_of_list:
if not any_of:
continue
if not isinstance(any_of, dict):
raise Exception("Unsupported use of anyOf in schema.")
raise_unsupported_usage_exception()
for any_of_key, any_of_value in any_of.items():
if any_of_key != "required":
raise Exception("Unsupported use of anyOf in schema.")
raise_unsupported_usage_exception()
if not any_of_value:
continue
if isinstance(any_of_value, list):
required_properties.update(any_of_value)
elif isinstance(any_of_value, str):
required_properties.add(any_of_value)
else:
raise Exception("Unsupported use of anyOf in schema.")
raise_unsupported_usage_exception()
return list(required_properties)

identifying_properties = schema.get("identifyingProperties", [])
Expand Down

0 comments on commit 6441770

Please sign in to comment.