diff --git a/apps/backend/.gitignore b/apps/backend/.gitignore new file mode 100644 index 0000000..2bac744 --- /dev/null +++ b/apps/backend/.gitignore @@ -0,0 +1 @@ +openapi.json \ No newline at end of file diff --git a/apps/backend/export_openapi.py b/apps/backend/export_openapi.py new file mode 100644 index 0000000..e8c1842 --- /dev/null +++ b/apps/backend/export_openapi.py @@ -0,0 +1,28 @@ +"""Export the FastAPI OpenAPI spec to a JSON file.""" + +import argparse +import json +import sys + +from main import app + + +def export_openapi(output: str | None = None) -> None: + spec = app.openapi() + text = json.dumps(spec, indent=2) + + if output: + with open(output, "w") as f: + f.write(text) + else: + sys.stdout.write(text) + sys.stdout.write("\n") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Export FastAPI OpenAPI spec") + parser.add_argument( + "-o", "--output", help="Output file path (default: stdout)", default=None + ) + args = parser.parse_args() + export_openapi(args.output) diff --git a/apps/backend/pyproject.toml b/apps/backend/pyproject.toml index eb829b9..05d94fe 100644 --- a/apps/backend/pyproject.toml +++ b/apps/backend/pyproject.toml @@ -9,6 +9,9 @@ dependencies = [ "shared" ] +[tool.setuptools] +py-modules = ["main", "export_openapi"] + [dependency-groups] test = [ "pytest>=9.0.3", @@ -37,6 +40,7 @@ lint = "uv run ruff check ." typecheck = "uv run mypy ." test = "uv run pytest tests" format = "uv run ruff format ." +export-openapi = "uv run python export_openapi.py -o openapi.json" [tool.poe.tasks.start] help = "Build mypyc extensions and start FastAPI in production mode"