-
Notifications
You must be signed in to change notification settings - Fork 213
/
generate_config_docs.py
78 lines (74 loc) · 3.53 KB
/
generate_config_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# flake8: noqa
import json
if __name__ == "__main__":
schema = json.load(open("./taskcat/cfg/config_schema.json", "r"))
def resolve_ref(props):
if "$ref" in props:
ref = props["$ref"].split("/")[-1]
del props["$ref"]
props.update(schema["definitions"][ref])
return props
for k, v in schema["properties"].items():
item_str = f"* `{k}` "
v = resolve_ref(v)
item_str += f"*type:* `{v['type']}` "
if "description" in v:
item_str += f'{v["description"]}'
print(item_str)
if "properties" in v:
for ik, iv in v["properties"].items():
item_str = f" * `{ik}` "
iv = resolve_ref(iv)
item_str += f"*type:* `{iv['type']}` "
if "description" in iv:
item_str += f'{iv["description"]}'
print(item_str)
if iv["type"] == "object":
if "properties" in iv:
for iik, iiv in iv["properties"].items():
item_str = f" * `{iik}` "
iiv = resolve_ref(iiv)
item_str += f"*type:* `{iiv['type']}` "
if "description" in iiv:
item_str += f'{iiv["description"]}'
elif "additionalProperties" in iv:
name = ik[:-1] if ik.endswith("s") else ik
item_str = f" * `<{name.upper()}_NAME>` "
props = resolve_ref(iv["additionalProperties"])
item_str += f"*type:* `{iv['type']}` "
if "description" in props:
item_str += f'{props["description"]}'
print(item_str)
elif "additionalProperties" in v:
name = k[:-1] if k.endswith("s") else k
item_str = f" * `<{name.upper()}_NAME>` "
props = resolve_ref(v["additionalProperties"])
item_str += f"*type:* `{v['type']}` "
if "description" in props:
item_str += f'{props["description"]}'
if "properties" in props:
for ik, iv in props["properties"].items():
item_str = f" * `{ik}` "
iv = resolve_ref(iv)
item_str += f"*type:* `{iv['type']}` "
if "description" in iv:
item_str += f'{iv["description"]}'
print(item_str)
if iv["type"] == "object":
if "properties" in iv:
for iik, iiv in iv["properties"].items():
item_str = f" * `{iik}` "
iiv = resolve_ref(iiv)
item_str += f"*type:* `{iiv['type']}` "
if "description" in iiv:
item_str += f'{iiv["description"]}'
elif "additionalProperties" in iv:
name = ik[:-1] if ik.endswith("s") else ik
item_str = f" * `<{name.upper()}_NAME>` "
iprops = resolve_ref(iv["additionalProperties"])
item_str += f"*type:* `{iv['type']}` "
if "description" in iprops:
item_str += f'{iprops["description"]}'
print(item_str)
else:
print(v)