File size: 789 Bytes
40e0b51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Dump the FastAPI OpenAPI 3.1 spec to docs/apispec.json.

Run from the project root:

    .venv/bin/python -m scripts.gen_openapi

Importing app.main only constructs the app; lifespan startup
(YOLO load, DB connect) does NOT run, so this is safe to invoke
without network or GPU access."""
from __future__ import annotations

import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / "docs" / "apispec.json"

# Importing app instantiates FastAPI() — that's all we need.
from app.main import app  # noqa: E402

spec = app.openapi()

OUT.parent.mkdir(parents=True, exist_ok=True)
OUT.write_text(json.dumps(spec, indent=2, ensure_ascii=False) + "\n")

print(f"wrote {OUT.relative_to(ROOT)}  ({OUT.stat().st_size:,} bytes)", file=sys.stderr)