Skip to content

Commit 1233763

Browse files
moved generation of openapi spec to server.py
1 parent 18ef8b6 commit 1233763

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ build-backend = "poetry.core.masonry.api"
5050

5151
[tool.poetry.scripts]
5252
codegate = "codegate.cli:main"
53-
generate-openapi = "src.codegate.dashboard.dashboard:generate_openapi"
53+
generate-openapi = "src.codegate.server:generate_openapi"
5454

5555
[tool.black]
5656
line-length = 100

src/codegate/dashboard/dashboard.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import asyncio
2-
import json
32
from typing import AsyncGenerator, List, Optional
43

54
import requests
65
import structlog
7-
from fastapi import APIRouter, Depends, FastAPI
6+
from fastapi import APIRouter, Depends
87
from fastapi.responses import StreamingResponse
98

109
from codegate import __version__
11-
from codegate.api.v1 import v1
1210
from codegate.dashboard.post_processing import (
1311
parse_get_alert_conversation,
1412
parse_messages_in_conversations,
@@ -107,19 +105,3 @@ def version_check():
107105
"is_latest": None,
108106
"error": "An unexpected error occurred",
109107
}
110-
111-
112-
def generate_openapi():
113-
# Create a temporary FastAPI app instance
114-
app = FastAPI()
115-
116-
# Include your defined router
117-
app.include_router(dashboard_router)
118-
app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"])
119-
120-
# Generate OpenAPI JSON
121-
openapi_schema = app.openapi()
122-
123-
# Convert the schema to JSON string for easier handling or storage
124-
openapi_json = json.dumps(openapi_schema, indent=2)
125-
print(openapi_json)

src/codegate/server.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import traceback
23

34
import structlog
@@ -102,3 +103,15 @@ async def health_check():
102103
app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"])
103104

104105
return app
106+
107+
108+
def generate_openapi():
109+
# Create a temporary FastAPI app instance
110+
app = init_app(None)
111+
112+
# Generate OpenAPI JSON
113+
openapi_schema = app.openapi()
114+
115+
# Convert the schema to JSON string for easier handling or storage
116+
openapi_json = json.dumps(openapi_schema, indent=2)
117+
print(openapi_json)

0 commit comments

Comments
 (0)