scripts/evedoc.py: handle union types in schema

Update EVE documentation script to handle union types like:

    "type": ["string", "number"]
pull/13975/head
Jason Ish 3 weeks ago committed by Victor Julien
parent ced0c2c466
commit 2848061d0d

@ -26,9 +26,13 @@ def find_ref(schema: dict, ref: str) -> dict:
def get_type(props: dict, name: str) -> str: def get_type(props: dict, name: str) -> str:
prop_type = props["type"] prop_type = props["type"]
if prop_type == "array": if isinstance(prop_type, list):
prop_type = " or ".join(prop_type)
elif prop_type == "array":
try: try:
array_type = props["items"]["type"] array_type = props["items"]["type"]
if isinstance(array_type, list):
array_type = " or ".join(array_type)
except KeyError: except KeyError:
errprint("warning: array property without items: {}".format(name)) errprint("warning: array property without items: {}".format(name))
array_type = "unknown" array_type = "unknown"
@ -48,7 +52,9 @@ def render_flat(schema: dict):
if not ref: if not ref:
raise Exception("$ref not found: {}".format(props["$ref"])) raise Exception("$ref not found: {}".format(props["$ref"]))
props = ref props = ref
if props["type"] in ["string", "integer", "boolean", "number"]: if isinstance(props["type"], list):
print("{}: {}".format(".".join(path + [name]), " or ".join(props["type"])))
elif props["type"] in ["string", "integer", "boolean", "number"]:
# End of the line... # End of the line...
print("{}: {}".format(".".join(path + [name]), props["type"])) print("{}: {}".format(".".join(path + [name]), props["type"]))
elif props["type"] == "object": elif props["type"] == "object":
@ -63,9 +69,12 @@ def render_flat(schema: dict):
) )
elif props["type"] == "array": elif props["type"] == "array":
if "items" in props and "type" in props["items"]: if "items" in props and "type" in props["items"]:
item_type = props["items"]["type"]
if isinstance(item_type, list):
item_type = " or ".join(item_type)
print( print(
"{}: {}[]".format( "{}: {}[]".format(
".".join(path + [name]), props["items"]["type"] ".".join(path + [name]), item_type
) )
) )
if "properties" in props["items"]: if "properties" in props["items"]:
@ -110,14 +119,17 @@ def render_rst(schema: dict):
{"name": name, "type": prop_type, "description": description} {"name": name, "type": prop_type, "description": description}
) )
if props["type"] == "object" and "properties" in props: if not isinstance(props["type"], list) and props["type"] == "object" and "properties" in props:
stack.insert(0, (props, path + [name], "object")) stack.insert(0, (props, path + [name], "object"))
elif ( elif (
props["type"] == "array" not isinstance(props["type"], list)
and props["type"] == "array"
and "items" in props and "items" in props
and "properties" in props["items"] and "properties" in props["items"]
): ):
array_type = props["items"]["type"] array_type = props["items"]["type"]
if isinstance(array_type, list):
array_type = " or ".join(array_type)
stack.insert( stack.insert(
0, 0,
( (

Loading…
Cancel
Save