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

Commit ac0ccff

Browse files
committed
feat: add action to publish openapi.json
Create a github action that generates openapi on each request, and creates a PR when there have been some modifications Closes: #416
1 parent cc76070 commit ac0ccff

File tree

4 files changed

+379
-1
lines changed

4 files changed

+379
-1
lines changed

.github/workflows/openapi.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Generate OpenAPI Documentation
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
generate_openapi:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
steps:
17+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
18+
19+
- name: Set up Python 3.12
20+
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5
21+
with:
22+
python-version: "3.12"
23+
24+
- name: Install Poetry
25+
run: |
26+
curl -sSL https://install.python-poetry.org | python3 -
27+
28+
- name: Configure Poetry
29+
run: |
30+
echo "$HOME/.local/bin" >> $GITHUB_PATH
31+
32+
- name: Install dependencies
33+
run: |
34+
poetry install
35+
36+
- name: Generate OpenAPI JSON
37+
run: |
38+
poetry run generate-openapi > api/openapi.json
39+
40+
- name: Check if OpenAPI changed
41+
id: check-openapi
42+
run: |
43+
if ! git diff --quiet api/openapi.json ; then
44+
echo "changed=true" >> "$GITHUB_OUTPUT"
45+
else
46+
echo "changed=false" >> "$GITHUB_OUTPUT"
47+
fi
48+
49+
- name: Set git config
50+
run: |
51+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
52+
git config --local user.name "github-actions[bot]"
53+
54+
- name: Generate PR if needed
55+
if: steps.check-openapi.outputs.changed == 'true'
56+
run: |
57+
git checkout -b update-openapi-$GITHUB_SHA
58+
59+
git add api/openapi.json
60+
git commit -m "Update OpenAPI to version generated from ref $GITHUB_SHA"
61+
62+
echo "Pushing branch so we can create a PR..."
63+
git push --set-upstream origin update-openapi-$GITHUB_SHA
64+
65+
gh pr create --title "Update OpenAPI" \
66+
--body "This PR updates the OpenAPI definition to the version generated from ref $GITHUB_SHA" \
67+
--repo "$GITHUB_REPOSITORY" \
68+
--base main \
69+
--head update-openapi-$GITHUB_SHA
70+
env:
71+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

api/openapi.json

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "FastAPI",
5+
"version": "0.1.0"
6+
},
7+
"paths": {
8+
"/dashboard/messages": {
9+
"get": {
10+
"tags": [
11+
"Dashboard"
12+
],
13+
"summary": "Get Messages",
14+
"description": "Get all the messages from the database and return them as a list of conversations.",
15+
"operationId": "get_messages_dashboard_messages_get",
16+
"responses": {
17+
"200": {
18+
"description": "Successful Response",
19+
"content": {
20+
"application/json": {
21+
"schema": {
22+
"items": {
23+
"$ref": "#/components/schemas/Conversation"
24+
},
25+
"type": "array",
26+
"title": "Response Get Messages Dashboard Messages Get"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
},
34+
"/dashboard/alerts": {
35+
"get": {
36+
"tags": [
37+
"Dashboard"
38+
],
39+
"summary": "Get Alerts",
40+
"description": "Get all the messages from the database and return them as a list of conversations.",
41+
"operationId": "get_alerts_dashboard_alerts_get",
42+
"responses": {
43+
"200": {
44+
"description": "Successful Response",
45+
"content": {
46+
"application/json": {
47+
"schema": {
48+
"items": {
49+
"$ref": "#/components/schemas/AlertConversation"
50+
},
51+
"type": "array",
52+
"title": "Response Get Alerts Dashboard Alerts Get"
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
},
60+
"/dashboard/alerts_notification": {
61+
"get": {
62+
"tags": [
63+
"Dashboard"
64+
],
65+
"summary": "Stream Sse",
66+
"description": "Send alerts event",
67+
"operationId": "stream_sse_dashboard_alerts_notification_get",
68+
"responses": {
69+
"200": {
70+
"description": "Successful Response",
71+
"content": {
72+
"application/json": {
73+
"schema": {}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
},
81+
"components": {
82+
"schemas": {
83+
"AlertConversation": {
84+
"properties": {
85+
"conversation": {
86+
"$ref": "#/components/schemas/Conversation"
87+
},
88+
"alert_id": {
89+
"type": "string",
90+
"title": "Alert Id"
91+
},
92+
"code_snippet": {
93+
"anyOf": [
94+
{
95+
"$ref": "#/components/schemas/CodeSnippet"
96+
},
97+
{
98+
"type": "null"
99+
}
100+
]
101+
},
102+
"trigger_string": {
103+
"anyOf": [
104+
{
105+
"type": "string"
106+
},
107+
{
108+
"type": "object"
109+
},
110+
{
111+
"type": "null"
112+
}
113+
],
114+
"title": "Trigger String"
115+
},
116+
"trigger_type": {
117+
"type": "string",
118+
"title": "Trigger Type"
119+
},
120+
"trigger_category": {
121+
"anyOf": [
122+
{
123+
"type": "string"
124+
},
125+
{
126+
"type": "null"
127+
}
128+
],
129+
"title": "Trigger Category"
130+
},
131+
"timestamp": {
132+
"type": "string",
133+
"format": "date-time",
134+
"title": "Timestamp"
135+
}
136+
},
137+
"type": "object",
138+
"required": [
139+
"conversation",
140+
"alert_id",
141+
"code_snippet",
142+
"trigger_string",
143+
"trigger_type",
144+
"trigger_category",
145+
"timestamp"
146+
],
147+
"title": "AlertConversation",
148+
"description": "Represents an alert with it's respective conversation."
149+
},
150+
"ChatMessage": {
151+
"properties": {
152+
"message": {
153+
"type": "string",
154+
"title": "Message"
155+
},
156+
"timestamp": {
157+
"type": "string",
158+
"format": "date-time",
159+
"title": "Timestamp"
160+
},
161+
"message_id": {
162+
"type": "string",
163+
"title": "Message Id"
164+
}
165+
},
166+
"type": "object",
167+
"required": [
168+
"message",
169+
"timestamp",
170+
"message_id"
171+
],
172+
"title": "ChatMessage",
173+
"description": "Represents a chat message."
174+
},
175+
"CodeSnippet": {
176+
"properties": {
177+
"code": {
178+
"type": "string",
179+
"title": "Code"
180+
},
181+
"language": {
182+
"anyOf": [
183+
{
184+
"type": "string"
185+
},
186+
{
187+
"type": "null"
188+
}
189+
],
190+
"title": "Language"
191+
},
192+
"filepath": {
193+
"anyOf": [
194+
{
195+
"type": "string"
196+
},
197+
{
198+
"type": "null"
199+
}
200+
],
201+
"title": "Filepath"
202+
},
203+
"libraries": {
204+
"items": {
205+
"type": "string"
206+
},
207+
"type": "array",
208+
"title": "Libraries"
209+
}
210+
},
211+
"type": "object",
212+
"required": [
213+
"code",
214+
"language",
215+
"filepath"
216+
],
217+
"title": "CodeSnippet"
218+
},
219+
"Conversation": {
220+
"properties": {
221+
"question_answers": {
222+
"items": {
223+
"$ref": "#/components/schemas/QuestionAnswer"
224+
},
225+
"type": "array",
226+
"title": "Question Answers"
227+
},
228+
"provider": {
229+
"anyOf": [
230+
{
231+
"type": "string"
232+
},
233+
{
234+
"type": "null"
235+
}
236+
],
237+
"title": "Provider"
238+
},
239+
"type": {
240+
"type": "string",
241+
"title": "Type"
242+
},
243+
"chat_id": {
244+
"type": "string",
245+
"title": "Chat Id"
246+
},
247+
"conversation_timestamp": {
248+
"type": "string",
249+
"format": "date-time",
250+
"title": "Conversation Timestamp"
251+
}
252+
},
253+
"type": "object",
254+
"required": [
255+
"question_answers",
256+
"provider",
257+
"type",
258+
"chat_id",
259+
"conversation_timestamp"
260+
],
261+
"title": "Conversation",
262+
"description": "Represents a conversation."
263+
},
264+
"QuestionAnswer": {
265+
"properties": {
266+
"question": {
267+
"$ref": "#/components/schemas/ChatMessage"
268+
},
269+
"answer": {
270+
"anyOf": [
271+
{
272+
"$ref": "#/components/schemas/ChatMessage"
273+
},
274+
{
275+
"type": "null"
276+
}
277+
]
278+
}
279+
},
280+
"type": "object",
281+
"required": [
282+
"question",
283+
"answer"
284+
],
285+
"title": "QuestionAnswer",
286+
"description": "Represents a question and answer pair."
287+
}
288+
}
289+
}
290+
}

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ build-backend = "poetry.core.masonry.api"
4949

5050
[tool.poetry.scripts]
5151
codegate = "codegate.cli:main"
52+
generate-openapi = "src.codegate.dashboard.dashboard:generate_openapi"
5253

5354
[tool.black]
5455
line-length = 100

0 commit comments

Comments
 (0)