Skip to content

Commit

Permalink
fix(doc): doc of nested objects under JSON schema items.oneOf (canoni…
Browse files Browse the repository at this point in the history
…cal#5562)

Document any keys of objects in a list which allows for objects as one
of the alternative types allowed as a list item.

Also, when documenting properties, ensure we skip documentation of
either 'properties' or 'patternProperties' if those properties are
declared in the hidden key.

Fixes canonicalGH-5514
  • Loading branch information
blackboxsw committed Aug 2, 2024
1 parent f219b5b commit 695593c
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions doc/rtd/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,28 @@ def render_property_template(prop_name, prop_cfg, prefix=""):

def render_nested_properties(prop_cfg, defs, prefix):
prop_str = ""
prop_types = set(["properties", "patternProperties"])
flatten_schema_refs(prop_cfg, defs)
if "items" in prop_cfg:
prop_str += render_nested_properties(prop_cfg["items"], defs, prefix)
if not set(["properties", "patternProperties"]).intersection(prop_cfg):
return prop_str
for prop_name, nested_cfg in prop_cfg.get("properties", {}).items():
flatten_schema_all_of(nested_cfg)
flatten_schema_refs(nested_cfg, defs)
prop_str += render_property_template(prop_name, nested_cfg, prefix)
prop_str += render_nested_properties(nested_cfg, defs, prefix + " ")
for prop_name, nested_cfg in prop_cfg.get("patternProperties", {}).items():
flatten_schema_all_of(nested_cfg)
flatten_schema_refs(nested_cfg, defs)
if nested_cfg.get("label"):
prop_name = nested_cfg.get("label")
prop_str += render_property_template(prop_name, nested_cfg, prefix)
prop_str += render_nested_properties(nested_cfg, defs, prefix + " ")
for alt_schema in prop_cfg["items"].get("oneOf", []):
if prop_types.intersection(alt_schema):
prop_str += render_nested_properties(alt_schema, defs, prefix)

for hidden_key in prop_cfg.get("hidden", []):
prop_cfg.pop(hidden_key, None)

# Render visible property types
for prop_type in prop_types.intersection(prop_cfg):
for prop_name, nested_cfg in prop_cfg.get(prop_type, {}).items():
flatten_schema_all_of(nested_cfg)
flatten_schema_refs(nested_cfg, defs)
if nested_cfg.get("label"):
prop_name = nested_cfg.get("label")
prop_str += render_property_template(prop_name, nested_cfg, prefix)
prop_str += render_nested_properties(
nested_cfg, defs, prefix + " "
)
return prop_str


Expand Down

0 comments on commit 695593c

Please sign in to comment.