-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.py
More file actions
37 lines (26 loc) · 930 Bytes
/
docs.py
File metadata and controls
37 lines (26 loc) · 930 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
31
32
33
34
35
36
37
from argparse import ArgumentParser, ArgumentTypeError
import json
import os
import re
import yaml
from robopipe_api.robopipe import app
def check_path(path: str):
if not re.match(r"^.*\.(json|yml|yaml)$", path):
raise ArgumentTypeError("Path must be either json ot yaml")
return path
def export_openapi_spec(save_path: str | None = None):
openapi = app.openapi()
if save_path is not None:
_, fmt = os.path.splitext(save_path)
with open(save_path, "w") as f:
if fmt == ".json":
json.dump(openapi, f, indent=2)
else:
yaml.dump(openapi, f, sort_keys=False)
else:
print(json.dumps(openapi, indent=2))
if __name__ == "__main__":
parser = ArgumentParser(prog="Save OpenAPI specification")
parser.add_argument("-f", "--file", type=check_path)
args = parser.parse_args()
export_openapi_spec(args.file)