-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexport_gateway_openapi.py
More file actions
43 lines (33 loc) · 1.17 KB
/
Copy pathexport_gateway_openapi.py
File metadata and controls
43 lines (33 loc) · 1.17 KB
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
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
from octopal.gateway.app import build_app
from octopal.infrastructure.config.settings import Settings
def build_openapi_document() -> dict:
project_root = Path(__file__).resolve().parents[1]
settings = Settings(
TELEGRAM_BOT_TOKEN="dummy:token",
OCTOPAL_STATE_DIR=project_root / "tmp" / "openapi_state",
OCTOPAL_WORKSPACE_DIR=project_root / "workspace",
)
app = build_app(settings)
return app.openapi()
def main() -> None:
parser = argparse.ArgumentParser(
description="Export FastAPI OpenAPI spec for frontend type generation."
)
parser.add_argument(
"--out",
default="webapp/openapi.json",
help="Path to write the generated OpenAPI JSON file.",
)
args = parser.parse_args()
out_path = Path(args.out)
out_path.parent.mkdir(parents=True, exist_ok=True)
document = build_openapi_document()
out_path.write_text(json.dumps(document, ensure_ascii=False, indent=2), encoding="utf-8")
sys.stdout.write(f"Wrote OpenAPI schema to {out_path}\n")
if __name__ == "__main__":
main()