forked from ekeih/libtado
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgenerate_json_schemas.py
More file actions
30 lines (20 loc) · 821 Bytes
/
Copy pathgenerate_json_schemas.py
File metadata and controls
30 lines (20 loc) · 821 Bytes
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
import json
import inspect
from tests.api import utils
def generate_jsonschema_file(filename: str, data: object):
from genson import SchemaBuilder
builder = SchemaBuilder()
builder.add_object(data)
schema = builder.to_schema()
with open(f"schemas/{filename}.json", "w") as file:
file.write(json.dumps(schema, indent=2))
return schema
tado_methods = inspect.getmembers(utils.TestApi, predicate=inspect.isfunction)
tado_methods = [method[0] for method in tado_methods if method[0].startswith('get_') or method[0].startswith('set_')]
for method in tado_methods:
print(f"Calling {method}")
res = eval(f'utils.TestApi.{method}()')
print(f"Generating schema for {method}")
schema = generate_jsonschema_file(f"{method}", res)
print()
print("End of generating schemas.")