"""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)