Skip to content

Commit

Permalink
common.py: Handle oneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed (ODSC) committed Oct 24, 2024
1 parent 3cbc23e commit 2e8ad98
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libcove2/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
)


def resolve_ref(value, defs, registry=None):
if value["$ref"].startswith("urn:"):
subschema = registry.contents(value["$ref"].split("#")[0])
if "#/$defs/" in value["$ref"]:
name = value["$ref"].split("$defs/")[-1]
defs = subschema["$defs"]
subschema = defs[name]
return subschema
elif value["$ref"].startswith("#/$defs/"):
name = value["$ref"].split("$defs/")[-1]
return defs[name]

def process_items(schema_dict, registry=None, defs=None):
items_schema_dicts = []
if "oneOf" in schema_dict["items"] and isinstance(
Expand Down Expand Up @@ -79,6 +91,12 @@ def schema_dict_fields_generator(schema_dict, registry=None, defs=None):
property_schema_dict["items"], registry=registry, defs=defs
):
yield f"/{property_name}{field}"
elif "$ref" in property_schema_dict:
item_schema_dict = resolve_ref(property_schema_dict, defs, registry=registry)
for field in schema_dict_fields_generator(
item_schema_dict, registry=registry, defs=defs
):
yield f"/{property_name}{field}"
yield f"/{property_name}"
if "allOf" in schema_dict and isinstance(schema_dict["allOf"], list):
for clause in schema_dict["allOf"]:
Expand Down

0 comments on commit 2e8ad98

Please sign in to comment.