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

feat: add action to publish openapi.json #502

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Generate OpenAPI Documentation

on:
workflow_dispatch:
push:
branches:
- main

jobs:
generate_openapi:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- name: Set up Python 3.12
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5
with:
python-version: "3.12"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -

- name: Configure Poetry
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Install dependencies
run: |
poetry install

- name: Generate OpenAPI JSON
run: |
poetry run generate-openapi > api/openapi.json

- name: Check if OpenAPI changed
id: check-openapi
run: |
if ! git diff --quiet api/openapi.json ; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Set git config
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

- name: Generate PR if needed
if: steps.check-openapi.outputs.changed == 'true'
run: |
git checkout -b update-openapi-$GITHUB_SHA

git add api/openapi.json
git commit -m "Update OpenAPI to version generated from ref $GITHUB_SHA"

echo "Pushing branch so we can create a PR..."
git push --set-upstream origin update-openapi-$GITHUB_SHA

gh pr create --title "Update OpenAPI" \
--body "This PR updates the OpenAPI definition to the version generated from ref $GITHUB_SHA" \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head update-openapi-$GITHUB_SHA
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
290 changes: 290 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
{
"openapi": "3.1.0",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/dashboard/messages": {
"get": {
"tags": [
"Dashboard"
],
"summary": "Get Messages",
"description": "Get all the messages from the database and return them as a list of conversations.",
"operationId": "get_messages_dashboard_messages_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"items": {
"$ref": "#/components/schemas/Conversation"
},
"type": "array",
"title": "Response Get Messages Dashboard Messages Get"
}
}
}
}
}
}
},
"/dashboard/alerts": {
"get": {
"tags": [
"Dashboard"
],
"summary": "Get Alerts",
"description": "Get all the messages from the database and return them as a list of conversations.",
"operationId": "get_alerts_dashboard_alerts_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"items": {
"$ref": "#/components/schemas/AlertConversation"
},
"type": "array",
"title": "Response Get Alerts Dashboard Alerts Get"
}
}
}
}
}
}
},
"/dashboard/alerts_notification": {
"get": {
"tags": [
"Dashboard"
],
"summary": "Stream Sse",
"description": "Send alerts event",
"operationId": "stream_sse_dashboard_alerts_notification_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
}
},
"components": {
"schemas": {
"AlertConversation": {
"properties": {
"conversation": {
"$ref": "#/components/schemas/Conversation"
},
"alert_id": {
"type": "string",
"title": "Alert Id"
},
"code_snippet": {
"anyOf": [
{
"$ref": "#/components/schemas/CodeSnippet"
},
{
"type": "null"
}
]
},
"trigger_string": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
},
{
"type": "null"
}
],
"title": "Trigger String"
},
"trigger_type": {
"type": "string",
"title": "Trigger Type"
},
"trigger_category": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Trigger Category"
},
"timestamp": {
"type": "string",
"format": "date-time",
"title": "Timestamp"
}
},
"type": "object",
"required": [
"conversation",
"alert_id",
"code_snippet",
"trigger_string",
"trigger_type",
"trigger_category",
"timestamp"
],
"title": "AlertConversation",
"description": "Represents an alert with it's respective conversation."
},
"ChatMessage": {
"properties": {
"message": {
"type": "string",
"title": "Message"
},
"timestamp": {
"type": "string",
"format": "date-time",
"title": "Timestamp"
},
"message_id": {
"type": "string",
"title": "Message Id"
}
},
"type": "object",
"required": [
"message",
"timestamp",
"message_id"
],
"title": "ChatMessage",
"description": "Represents a chat message."
},
"CodeSnippet": {
"properties": {
"code": {
"type": "string",
"title": "Code"
},
"language": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Language"
},
"filepath": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Filepath"
},
"libraries": {
"items": {
"type": "string"
},
"type": "array",
"title": "Libraries"
}
},
"type": "object",
"required": [
"code",
"language",
"filepath"
],
"title": "CodeSnippet"
},
"Conversation": {
"properties": {
"question_answers": {
"items": {
"$ref": "#/components/schemas/QuestionAnswer"
},
"type": "array",
"title": "Question Answers"
},
"provider": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Provider"
},
"type": {
"type": "string",
"title": "Type"
},
"chat_id": {
"type": "string",
"title": "Chat Id"
},
"conversation_timestamp": {
"type": "string",
"format": "date-time",
"title": "Conversation Timestamp"
}
},
"type": "object",
"required": [
"question_answers",
"provider",
"type",
"chat_id",
"conversation_timestamp"
],
"title": "Conversation",
"description": "Represents a conversation."
},
"QuestionAnswer": {
"properties": {
"question": {
"$ref": "#/components/schemas/ChatMessage"
},
"answer": {
"anyOf": [
{
"$ref": "#/components/schemas/ChatMessage"
},
{
"type": "null"
}
]
}
},
"type": "object",
"required": [
"question",
"answer"
],
"title": "QuestionAnswer",
"description": "Represents a question and answer pair."
}
}
}
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
codegate = "codegate.cli:main"
generate-openapi = "src.codegate.dashboard.dashboard:generate_openapi"

[tool.black]
line-length = 100
Expand Down
Loading
Loading