Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 23ec130

Browse files
committed
feat(server): move dashboard endpoints under api v1 router
1 parent 4f111e3 commit 23ec130

File tree

8 files changed

+53
-31
lines changed

8 files changed

+53
-31
lines changed

api/openapi.json

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
{
22
"openapi": "3.1.0",
33
"info": {
4-
"title": "FastAPI",
5-
"version": "0.1.0"
4+
"title": "CodeGate",
5+
"description": "Generative AI CodeGen security gateway",
6+
"version": "0.1.7"
67
},
78
"paths": {
8-
"/dashboard/messages": {
9+
"/health": {
910
"get": {
1011
"tags": [
12+
"System"
13+
],
14+
"summary": "Health Check",
15+
"operationId": "health_check_health_get",
16+
"responses": {
17+
"200": {
18+
"description": "Successful Response",
19+
"content": {
20+
"application/json": {
21+
"schema": {}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
},
28+
"/api/v1/dashboard/messages": {
29+
"get": {
30+
"tags": [
31+
"CodeGate API",
1132
"Dashboard"
1233
],
1334
"summary": "Get Messages",
1435
"description": "Get all the messages from the database and return them as a list of conversations.",
15-
"operationId": "get_messages_dashboard_messages_get",
36+
"operationId": "get_messages_api_v1_dashboard_messages_get",
1637
"responses": {
1738
"200": {
1839
"description": "Successful Response",
@@ -23,22 +44,23 @@
2344
"$ref": "#/components/schemas/Conversation"
2445
},
2546
"type": "array",
26-
"title": "Response Get Messages Dashboard Messages Get"
47+
"title": "Response Get Messages Api V1 Dashboard Messages Get"
2748
}
2849
}
2950
}
3051
}
3152
}
3253
}
3354
},
34-
"/dashboard/alerts": {
55+
"/api/v1/dashboard/alerts": {
3556
"get": {
3657
"tags": [
58+
"CodeGate API",
3759
"Dashboard"
3860
],
3961
"summary": "Get Alerts",
4062
"description": "Get all the messages from the database and return them as a list of conversations.",
41-
"operationId": "get_alerts_dashboard_alerts_get",
63+
"operationId": "get_alerts_api_v1_dashboard_alerts_get",
4264
"responses": {
4365
"200": {
4466
"description": "Successful Response",
@@ -56,22 +78,23 @@
5678
]
5779
},
5880
"type": "array",
59-
"title": "Response Get Alerts Dashboard Alerts Get"
81+
"title": "Response Get Alerts Api V1 Dashboard Alerts Get"
6082
}
6183
}
6284
}
6385
}
6486
}
6587
}
6688
},
67-
"/dashboard/alerts_notification": {
89+
"/api/v1/dashboard/alerts_notification": {
6890
"get": {
6991
"tags": [
92+
"CodeGate API",
7093
"Dashboard"
7194
],
7295
"summary": "Stream Sse",
7396
"description": "Send alerts event",
74-
"operationId": "stream_sse_dashboard_alerts_notification_get",
97+
"operationId": "stream_sse_api_v1_dashboard_alerts_notification_get",
7598
"responses": {
7699
"200": {
77100
"description": "Successful Response",
@@ -84,13 +107,14 @@
84107
}
85108
}
86109
},
87-
"/dashboard/version": {
110+
"/api/v1/dashboard/version": {
88111
"get": {
89112
"tags": [
113+
"CodeGate API",
90114
"Dashboard"
91115
],
92116
"summary": "Version Check",
93-
"operationId": "version_check_dashboard_version_get",
117+
"operationId": "version_check_api_v1_dashboard_version_get",
94118
"responses": {
95119
"200": {
96120
"description": "Successful Response",
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import structlog
66
from fastapi import APIRouter, Depends, FastAPI
77
from fastapi.responses import StreamingResponse
8-
98
from codegate import __version__
10-
from codegate.dashboard.post_processing import (
9+
10+
from codegate.api.dashboard.post_processing import (
1111
parse_get_alert_conversation,
1212
parse_messages_in_conversations,
1313
)
14-
from codegate.dashboard.request_models import AlertConversation, Conversation
14+
from codegate.api.dashboard.request_models import AlertConversation, Conversation
1515
from codegate.db.connection import DbReader, alert_queue
1616

1717
logger = structlog.get_logger("codegate")
@@ -81,7 +81,7 @@ def version_check():
8181
latest_version_stripped = latest_version.lstrip('v')
8282

8383
is_latest: bool = latest_version_stripped == current_version
84-
84+
8585
return {
8686
"current_version": current_version,
8787
"latest_version": latest_version_stripped,

src/codegate/dashboard/post_processing.py renamed to src/codegate/api/dashboard/post_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import structlog
88

9-
from codegate.dashboard.request_models import (
9+
from codegate.api.dashboard.request_models import (
1010
AlertConversation,
1111
ChatMessage,
1212
Conversation,
File renamed without changes.

src/codegate/api/v1.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
from codegate.api import v1_models
77
from codegate.db.connection import AlreadyExistsError
88
from codegate.workspaces.crud import WorkspaceCrud
9+
from codegate.api.dashboard.dashboard import dashboard_router
910

1011
v1 = APIRouter()
12+
v1.include_router(dashboard_router)
13+
1114
wscrud = WorkspaceCrud()
1215

1316

src/codegate/server.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import traceback
3+
from unittest.mock import Mock
34

45
import structlog
56
from fastapi import APIRouter, FastAPI, Request
@@ -9,7 +10,6 @@
910

1011
from codegate import __description__, __version__
1112
from codegate.api.v1 import v1
12-
from codegate.dashboard.dashboard import dashboard_router
1313
from codegate.pipeline.factory import PipelineFactory
1414
from codegate.providers.anthropic.provider import AnthropicProvider
1515
from codegate.providers.llamacpp.provider import LlamaCppProvider
@@ -97,7 +97,6 @@ async def health_check():
9797
return {"status": "healthy"}
9898

9999
app.include_router(system_router)
100-
app.include_router(dashboard_router)
101100

102101
# CodeGate API
103102
app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"])
@@ -106,11 +105,7 @@ async def health_check():
106105

107106

108107
def generate_openapi():
109-
# Create a temporary FastAPI app instance
110-
app = FastAPI()
111-
112-
app.include_router(dashboard_router)
113-
app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"])
108+
app = init_app(Mock(spec=PipelineFactory))
114109

115110
# Generate OpenAPI JSON
116111
openapi_schema = app.openapi()

tests/dashboard/test_post_processing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import pytest
66

7-
from codegate.dashboard.post_processing import (
7+
from codegate.api.dashboard.post_processing import (
88
_get_question_answer,
99
_group_partial_messages,
1010
_is_system_prompt,
1111
parse_output,
1212
parse_request,
1313
)
14-
from codegate.dashboard.request_models import (
14+
from codegate.api.dashboard.request_models import (
1515
PartialQuestions,
1616
)
1717
from codegate.db.models import GetPromptWithOutputsRow
@@ -162,10 +162,10 @@ async def test_parse_output(output_dict, expected_str):
162162
)
163163
async def test_get_question_answer(request_msg_list, output_msg_str, row):
164164
with patch(
165-
"codegate.dashboard.post_processing.parse_request", new_callable=AsyncMock
165+
"codegate.api.dashboard.post_processing.parse_request", new_callable=AsyncMock
166166
) as mock_parse_request:
167167
with patch(
168-
"codegate.dashboard.post_processing.parse_output", new_callable=AsyncMock
168+
"codegate.api.dashboard.post_processing.parse_output", new_callable=AsyncMock
169169
) as mock_parse_output:
170170
# Set return values for the mocks
171171
mock_parse_request.return_value = request_msg_list

tests/test_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def test_health_check(test_client: TestClient) -> None:
8181
assert response.status_code == 200
8282
assert response.json() == {"status": "healthy"}
8383

84-
@patch("codegate.dashboard.dashboard.fetch_latest_version", return_value="foo")
84+
@patch("codegate.api.dashboard.fetch_latest_version", return_value="foo")
8585
def test_version_endpoint(mock_fetch_latest_version, test_client: TestClient) -> None:
8686
"""Test the version endpoint."""
87-
response = test_client.get("/dashboard/version")
87+
response = test_client.get("/api/v1/dashboard/version")
8888
assert response.status_code == 200
8989

9090
response_data = response.json()
@@ -139,7 +139,7 @@ def test_dashboard_routes(mock_pipeline_factory) -> None:
139139
routes = [route.path for route in app.routes]
140140

141141
# Verify dashboard endpoints are included
142-
dashboard_routes = [route for route in routes if route.startswith("/dashboard")]
142+
dashboard_routes = [route for route in routes if route.startswith("/api/v1/dashboard")]
143143
assert len(dashboard_routes) > 0
144144

145145

0 commit comments

Comments
 (0)