Skip to content

Commit dc2a4bd

Browse files
rkuo-danswerRichard Kuo (Onyx)
authored andcommitted
Feature/openapi (onyx-dot-app#4710)
* starting openapi support * fix app / app_fn * send gitignore * dedupe function names * add readme * modify gitignore * update launch template * fix unused path param * fix mypy * local tests pass * first pass at making integration tests work * fixes * fix script path * set python path * try full path * fix output dir * fix integration test * more build fixes * add generated directory * use the config * add a comment * add * modify tsconfig.json * fix index linting bugs * tons of lint fixes * new gitignore * remove generated dir * add tasks template * check for undefined explicitly * fix hooks.ts * refactor destructureValue * improve readme --------- Co-authored-by: Richard Kuo (Onyx) <rkuo@onyx.app>
1 parent 404c234 commit dc2a4bd

File tree

96 files changed

+1218
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1218
-480
lines changed

.github/workflows/pr-integration-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ jobs:
2626
- name: Checkout code
2727
uses: actions/checkout@v4
2828

29+
- name: Setup Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.11"
33+
cache: "pip"
34+
cache-dependency-path: |
35+
backend/requirements/default.txt
36+
backend/requirements/dev.txt
37+
backend/requirements/ee.txt
38+
- run: |
39+
python -m pip install --upgrade pip
40+
pip install --retries 5 --timeout 30 -r backend/requirements/default.txt
41+
pip install --retries 5 --timeout 30 -r backend/requirements/dev.txt
42+
pip install --retries 5 --timeout 30 -r backend/requirements/ee.txt
43+
44+
- name: Generate OpenAPI schema
45+
working-directory: ./backend
46+
env:
47+
PYTHONPATH: "."
48+
run: |
49+
python scripts/onyx_openapi_schema.py --filename generated/openapi.json
50+
51+
- name: Generate OpenAPI Python client
52+
working-directory: ./backend
53+
run: |
54+
docker run --rm \
55+
-v "${{ github.workspace }}/backend/generated:/local" \
56+
openapitools/openapi-generator-cli generate \
57+
-i /local/openapi.json \
58+
-g python \
59+
-o /local/onyx_openapi_client \
60+
--package-name onyx_openapi_client
61+
2962
- name: Set up Docker Buildx
3063
uses: docker/setup-buildx-action@v3
3164

.github/workflows/pr-mit-integration-tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,38 @@ jobs:
2424
steps:
2525
- name: Checkout code
2626
uses: actions/checkout@v4
27+
28+
- name: Setup Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: "3.11"
32+
cache: "pip"
33+
cache-dependency-path: |
34+
backend/requirements/default.txt
35+
backend/requirements/dev.txt
36+
- run: |
37+
python -m pip install --upgrade pip
38+
pip install --retries 5 --timeout 30 -r backend/requirements/default.txt
39+
pip install --retries 5 --timeout 30 -r backend/requirements/dev.txt
40+
41+
- name: Generate OpenAPI schema
42+
working-directory: ./backend
43+
env:
44+
PYTHONPATH: "."
45+
run: |
46+
python scripts/onyx_openapi_schema.py --filename generated/openapi.json
2747
48+
- name: Generate OpenAPI Python client
49+
working-directory: ./backend
50+
run: |
51+
docker run --rm \
52+
-v "${{ github.workspace }}/backend/generated:/local" \
53+
openapitools/openapi-generator-cli generate \
54+
-i /local/openapi.json \
55+
-g python \
56+
-o /local/onyx_openapi_client \
57+
--package-name onyx_openapi_client
58+
2859
- name: Set up Docker Buildx
2960
uses: docker/setup-buildx-action@v3
3061

.github/workflows/pr-python-checks.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ jobs:
3131
pip install --retries 5 --timeout 30 -r backend/requirements/dev.txt
3232
pip install --retries 5 --timeout 30 -r backend/requirements/model_server.txt
3333
34+
- name: Generate OpenAPI schema
35+
working-directory: ./backend
36+
env:
37+
PYTHONPATH: "."
38+
run: |
39+
python scripts/onyx_openapi_schema.py --filename generated/openapi.json
40+
41+
- name: Generate OpenAPI Python client
42+
working-directory: ./backend
43+
run: |
44+
docker run --rm \
45+
-v "${{ github.workspace }}/backend/generated:/local" \
46+
openapitools/openapi-generator-cli generate \
47+
-i /local/openapi.json \
48+
-g python \
49+
-o /local/onyx_openapi_client \
50+
--package-name onyx_openapi_client
51+
3452
- name: Run MyPy
3553
run: |
3654
cd backend

.vscode/launch.template.jsonc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,23 @@
412412
"group": "3"
413413
}
414414
},
415+
{
416+
// script to generate the openapi schema
417+
"name": "Onyx OpenAPI Schema Generator",
418+
"type": "debugpy",
419+
"request": "launch",
420+
"program": "scripts/onyx_openapi_schema.py",
421+
"cwd": "${workspaceFolder}/backend",
422+
"envFile": "${workspaceFolder}/.env",
423+
"env": {
424+
"PYTHONUNBUFFERED": "1",
425+
"PYTHONPATH": "."
426+
},
427+
"args": [
428+
"--filename",
429+
"generated/openapi.json",
430+
]
431+
},
415432
{
416433
"name": "Debug React Web App in Chrome",
417434
"type": "chrome",

.vscode/tasks.template.jsonc

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "austin",
6+
"label": "Profile celery beat",
7+
"envFile": "${workspaceFolder}/.env",
8+
"options": {
9+
"cwd": "${workspaceFolder}/backend"
10+
},
11+
"command": [
12+
"sudo",
13+
"-E"
14+
],
15+
"args": [
16+
"celery",
17+
"-A",
18+
"onyx.background.celery.versioned_apps.beat",
19+
"beat",
20+
"--loglevel=INFO"
21+
]
22+
},
23+
{
24+
"type": "shell",
25+
"label": "Generate Onyx OpenAPI Python client",
26+
"cwd": "${workspaceFolder}/backend",
27+
"envFile": "${workspaceFolder}/.env",
28+
"options": {
29+
"cwd": "${workspaceFolder}/backend"
30+
},
31+
"command": [
32+
"openapi-generator"
33+
],
34+
"args": [
35+
"generate",
36+
"-i",
37+
"generated/openapi.json",
38+
"-g",
39+
"python",
40+
"-o",
41+
"generated/onyx_openapi_client",
42+
"--package-name",
43+
"onyx_openapi_client",
44+
]
45+
},
46+
{
47+
"type": "shell",
48+
"label": "Generate Typescript Fetch client (openapi-generator)",
49+
"envFile": "${workspaceFolder}/.env",
50+
"options": {
51+
"cwd": "${workspaceFolder}"
52+
},
53+
"command": [
54+
"openapi-generator"
55+
],
56+
"args": [
57+
"generate",
58+
"-i",
59+
"backend/generated/openapi.json",
60+
"-g",
61+
"typescript-fetch",
62+
"-o",
63+
"${workspaceFolder}/web/src/lib/generated/onyx_api",
64+
"--additional-properties=disallowAdditionalPropertiesIfNotPresent=false,legacyDiscriminatorBehavior=false,supportsES6=true",
65+
]
66+
},
67+
{
68+
"type": "shell",
69+
"label": "Generate TypeScript Client (openapi-ts)",
70+
"envFile": "${workspaceFolder}/.env",
71+
"options": {
72+
"cwd": "${workspaceFolder}/web"
73+
},
74+
"command": [
75+
"npx"
76+
],
77+
"args": [
78+
"openapi-typescript",
79+
"../backend/generated/openapi.json",
80+
"--output",
81+
"./src/lib/generated/onyx-schema.ts",
82+
]
83+
},
84+
{
85+
"type": "shell",
86+
"label": "Generate TypeScript Client (orval)",
87+
"envFile": "${workspaceFolder}/.env",
88+
"options": {
89+
"cwd": "${workspaceFolder}/web"
90+
},
91+
"command": [
92+
"npx"
93+
],
94+
"args": [
95+
"orval",
96+
"--config",
97+
"orval.config.js",
98+
]
99+
}
100+
]
101+
}

backend/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ dynamic_config_storage/
1111
celerybeat-schedule*
1212
onyx/connectors/salesforce/data/
1313
.test.env
14-
14+
/generated

backend/ee/onyx/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from onyx.main import include_auth_router_with_prefix
5252
from onyx.main import include_router_with_global_prefix_prepended
5353
from onyx.main import lifespan as lifespan_base
54+
from onyx.main import use_route_function_names_as_operation_ids
5455
from onyx.utils.logger import setup_logger
5556
from onyx.utils.variable_functionality import global_version
5657
from shared_configs.configs import MULTI_TENANT
@@ -192,4 +193,6 @@ def get_application() -> FastAPI:
192193
# for route in application.router.routes:
193194
# print(f"Path: {route.path}, Methods: {route.methods}")
194195

196+
use_route_function_names_as_operation_ids(application)
197+
195198
return application

backend/ee/onyx/server/enterprise_settings/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ async def refresh_access_token(
114114

115115

116116
@admin_router.put("")
117-
def put_settings(
117+
def admin_ee_put_settings(
118118
settings: EnterpriseSettings, _: User | None = Depends(current_admin_user)
119119
) -> None:
120120
store_settings(settings)
121121

122122

123123
@basic_router.get("")
124-
def fetch_settings() -> EnterpriseSettings:
124+
def ee_fetch_settings() -> EnterpriseSettings:
125125
if MULTI_TENANT:
126126
tenant_id = get_current_tenant_id()
127127
if not tenant_id or tenant_id == POSTGRES_DEFAULT_SCHEMA:

backend/ee/onyx/server/query_history/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def snapshot_from_chat_session(
147147

148148

149149
@router.get("/admin/chat-sessions")
150-
def get_user_chat_sessions(
150+
def admin_get_chat_sessions(
151151
user_id: UUID,
152152
_: User | None = Depends(current_admin_user),
153153
db_session: Session = Depends(get_session),

backend/generated/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Generated Files
2+
* Generated files live here. This directory should be git ignored.

0 commit comments

Comments
 (0)