-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenapi.py
More file actions
executable file
·31 lines (23 loc) · 941 Bytes
/
openapi.py
File metadata and controls
executable file
·31 lines (23 loc) · 941 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
#!/usr/bin/env python3
from fastapi.openapi.utils import get_openapi
from main import app
import yaml
import argparse
specs = get_openapi(
title=app.title if app.title else None,
version=app.version if app.version else None,
openapi_version=app.openapi_version if app.openapi_version else None,
description=app.description if app.description else None,
routes=app.routes if app.routes else None,
)
# Use > style only for long strings
def string_representer(dumper, data):
if len(data) > 60 and len(data.split(" ")[0]) < 60:
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style=">")
return dumper.represent_scalar("tag:yaml.org,2002:str", data)
yaml.add_representer(str, string_representer)
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", default="openapi.yaml")
args = parser.parse_args()
with open(args.output, "w") as f:
yaml.dump(specs, f, width=80)