diff --git a/pyproject.toml b/pyproject.toml index f90a6488..c38ca31b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] codegate = "codegate.cli:main" -generate-openapi = "src.codegate.dashboard.dashboard:generate_openapi" +generate-openapi = "src.codegate.server:generate_openapi" [tool.black] line-length = 100 diff --git a/src/codegate/dashboard/dashboard.py b/src/codegate/dashboard/dashboard.py index 070598bd..bf4a6037 100644 --- a/src/codegate/dashboard/dashboard.py +++ b/src/codegate/dashboard/dashboard.py @@ -1,14 +1,12 @@ import asyncio -import json from typing import AsyncGenerator, List, Optional import requests import structlog -from fastapi import APIRouter, Depends, FastAPI +from fastapi import APIRouter, Depends from fastapi.responses import StreamingResponse from codegate import __version__ -from codegate.api.v1 import v1 from codegate.dashboard.post_processing import ( parse_get_alert_conversation, parse_messages_in_conversations, @@ -107,19 +105,3 @@ def version_check(): "is_latest": None, "error": "An unexpected error occurred", } - - -def generate_openapi(): - # Create a temporary FastAPI app instance - app = FastAPI() - - # Include your defined router - app.include_router(dashboard_router) - app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"]) - - # Generate OpenAPI JSON - openapi_schema = app.openapi() - - # Convert the schema to JSON string for easier handling or storage - openapi_json = json.dumps(openapi_schema, indent=2) - print(openapi_json) diff --git a/src/codegate/server.py b/src/codegate/server.py index d1da668e..dcd0809e 100644 --- a/src/codegate/server.py +++ b/src/codegate/server.py @@ -1,3 +1,4 @@ +import json import traceback import structlog @@ -102,3 +103,15 @@ async def health_check(): app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"]) return app + + +def generate_openapi(): + # Create a temporary FastAPI app instance + app = init_app(None) + + # Generate OpenAPI JSON + openapi_schema = app.openapi() + + # Convert the schema to JSON string for easier handling or storage + openapi_json = json.dumps(openapi_schema, indent=2) + print(openapi_json)