Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workspaces to OpenAPI spec #634

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
316 changes: 316 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,217 @@
}
}
}
},
"/api/v1/workspaces": {
"get": {
"tags": [
"CodeGate API",
"Workspaces"
],
"summary": "List Workspaces",
"description": "List all workspaces.",
"operationId": "v1_list_workspaces",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ListWorkspacesResponse"
}
}
}
}
}
},
"post": {
"tags": [
"CodeGate API",
"Workspaces"
],
"summary": "Create Workspace",
"description": "Create a new workspace.",
"operationId": "v1_create_workspace",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateWorkspaceRequest"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v1/workspaces/active": {
"get": {
"tags": [
"CodeGate API",
"Workspaces"
],
"summary": "List Active Workspaces",
"description": "List all active workspaces.\n\nIn it's current form, this function will only return one workspace. That is,\nthe globally active workspace.",
"operationId": "v1_list_active_workspaces",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ListActiveWorkspacesResponse"
}
}
}
}
}
},
"post": {
"tags": [
"CodeGate API",
"Workspaces"
],
"summary": "Activate Workspace",
"description": "Activate a workspace by name.",
"operationId": "v1_activate_workspace",
"parameters": [
{
"name": "status_code",
"in": "query",
"required": false,
"schema": {
"default": 204,
"title": "Status Code"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ActivateWorkspaceRequest"
}
}
}
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v1/workspaces/{workspace_name}": {
"delete": {
"tags": [
"CodeGate API",
"Workspaces"
],
"summary": "Delete Workspace",
"description": "Delete a workspace by name.",
"operationId": "v1_delete_workspace",
"parameters": [
{
"name": "workspace_name",
"in": "path",
"required": true,
"schema": {
"type": "string",
"title": "Workspace Name"
}
}
],
"responses": {
"204": {
"description": "Successful Response"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"ActivateWorkspaceRequest": {
"properties": {
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"name"
],
"title": "ActivateWorkspaceRequest"
},
"ActiveWorkspace": {
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"is_active": {
"type": "boolean",
"title": "Is Active"
},
"last_updated": {
"title": "Last Updated"
}
},
"type": "object",
"required": [
"name",
"is_active",
"last_updated"
],
"title": "ActiveWorkspace"
},
"AlertConversation": {
"properties": {
"conversation": {
Expand Down Expand Up @@ -268,6 +475,64 @@
"title": "Conversation",
"description": "Represents a conversation."
},
"CreateWorkspaceRequest": {
"properties": {
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"name"
],
"title": "CreateWorkspaceRequest"
},
"HTTPValidationError": {
"properties": {
"detail": {
"items": {
"$ref": "#/components/schemas/ValidationError"
},
"type": "array",
"title": "Detail"
}
},
"type": "object",
"title": "HTTPValidationError"
},
"ListActiveWorkspacesResponse": {
"properties": {
"workspaces": {
"items": {
"$ref": "#/components/schemas/ActiveWorkspace"
},
"type": "array",
"title": "Workspaces"
}
},
"type": "object",
"required": [
"workspaces"
],
"title": "ListActiveWorkspacesResponse"
},
"ListWorkspacesResponse": {
"properties": {
"workspaces": {
"items": {
"$ref": "#/components/schemas/Workspace"
},
"type": "array",
"title": "Workspaces"
}
},
"type": "object",
"required": [
"workspaces"
],
"title": "ListWorkspacesResponse"
},
"QuestionAnswer": {
"properties": {
"question": {
Expand All @@ -291,6 +556,57 @@
],
"title": "QuestionAnswer",
"description": "Represents a question and answer pair."
},
"ValidationError": {
"properties": {
"loc": {
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
},
"type": "array",
"title": "Location"
},
"msg": {
"type": "string",
"title": "Message"
},
"type": {
"type": "string",
"title": "Error Type"
}
},
"type": "object",
"required": [
"loc",
"msg",
"type"
],
"title": "ValidationError"
},
"Workspace": {
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"is_active": {
"type": "boolean",
"title": "Is Active"
}
},
"type": "object",
"required": [
"name",
"is_active"
],
"title": "Workspace"
}
}
}
Expand Down
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
16 changes: 0 additions & 16 deletions src/codegate/dashboard/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import json
from typing import AsyncGenerator, List, Optional

import structlog
Expand Down Expand Up @@ -60,18 +59,3 @@ async def stream_sse():
Send alerts event
"""
return StreamingResponse(generate_sse_events(), media_type="text/event-stream")


def generate_openapi():
# Create a temporary FastAPI app instance
app = FastAPI()

# Include your defined router
app.include_router(dashboard_router)

# 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)
2 changes: 1 addition & 1 deletion src/codegate/db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, sqlite_path: Optional[str] = None):
)
self._db_path = Path(sqlite_path).absolute()
self._db_path.parent.mkdir(parents=True, exist_ok=True)
logger.debug(f"Connecting to DB from path: {self._db_path}")
# logger.debug(f"Connecting to DB from path: {self._db_path}")
engine_dict = {
"url": f"sqlite+aiosqlite:///{self._db_path}",
"echo": False, # Set to False in production
Expand Down
Loading
Loading