Skip to content

Commit

Permalink
moved generation of openapi spec to server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
aponcedeleonch committed Jan 17, 2025
1 parent 8f3b030 commit 9b141e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 1 addition & 19 deletions src/codegate/dashboard/dashboard.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
13 changes: 13 additions & 0 deletions src/codegate/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import traceback

import structlog
Expand Down Expand Up @@ -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)

0 comments on commit 9b141e4

Please sign in to comment.