| 12345678910111213141516171819202122232425262728293031 |
- """Dump the FastAPI OpenAPI schema to apps/api/openapi.json.
- This must NOT require a database connection: importing ``app.main`` only builds
- the app and routes; the DB engine is created lazily. Run from apps/api:
- python -m scripts.export_openapi
- # or
- python scripts/export_openapi.py
- """
- from __future__ import annotations
- import json
- import sys
- from pathlib import Path
- # Allow running as a bare script (python scripts/export_openapi.py).
- sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
- from app.main import app # noqa: E402
- def main() -> None:
- schema = app.openapi()
- out_path = Path(__file__).resolve().parent.parent / "openapi.json"
- out_path.write_text(json.dumps(schema, indent=2, ensure_ascii=False), encoding="utf-8")
- print(f"wrote {out_path}")
- if __name__ == "__main__":
- main()
|