Skip to content

Commit 4269eeb

Browse files
authored
docs: OpenAPI request URL (#4070)
1 parent 5308265 commit 4269eeb

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

apps/common/init/init_doc.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,34 @@
1818

1919
def init_app_doc(system_urlpatterns):
2020
system_urlpatterns += [
21-
path('doc/schema/', SpectacularAPIView.as_view(), name='schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
22-
path('doc/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), # swagger-ui的路由
21+
path(f'{CONFIG.get_admin_path()[1:]}/api-doc/schema/', SpectacularAPIView.as_view(), name='schema'),
22+
# schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
23+
path(f'{CONFIG.get_admin_path()[1:]}/api-doc/', SpectacularSwaggerView.as_view(url_name='schema'),
24+
name='swagger-ui'), # swagger-ui的路由
2325
]
2426

2527

28+
class ChatSpectacularSwaggerView(SpectacularSwaggerView):
29+
@staticmethod
30+
def _swagger_ui_resource(filename):
31+
return f'{CONFIG.get_chat_path()}/api-doc/swagger-ui-dist/{filename}'
32+
33+
@staticmethod
34+
def _swagger_ui_favicon():
35+
return f'{CONFIG.get_chat_path()}/api-doc/swagger-ui-dist/favicon-32x32.png'
36+
37+
2638
def init_chat_doc(system_urlpatterns, chat_urlpatterns):
2739
system_urlpatterns += [
28-
path('doc_chat/schema/',
40+
path(f'{CONFIG.get_chat_path()[1:]}/api-doc/schema/',
2941
SpectacularAPIView.as_view(patterns=[
3042
URLPattern(pattern=f'{chat_api_prefix}{str(url.pattern)}', callback=url.callback,
3143
default_args=url.default_args,
3244
name=url.name) for url in chat_urlpatterns if
3345
['chat', 'open', 'profile'].__contains__(url.name)]),
3446
name='chat_schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
35-
path('doc_chat/', SpectacularSwaggerView.as_view(url_name='chat_schema'), name='swagger-ui'), # swagger-ui的路由
47+
path(f'{CONFIG.get_chat_path()[1:]}/api-doc/', ChatSpectacularSwaggerView.as_view(url_name='chat_schema'),
48+
name='swagger-ui'), # swagger-ui的路由
3649
]
3750

3851

apps/maxkb/settings/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@
120120
'VERSION': 'v2',
121121
'SERVE_INCLUDE_SCHEMA': False,
122122
# OTHER SETTINGS
123-
'SWAGGER_UI_DIST': '/doc/swagger-ui-dist', # shorthand to use the sidecar instead
124-
'SWAGGER_UI_FAVICON_HREF': '/doc/swagger-ui-dist/favicon-32x32.png',
125-
'REDOC_DIST': '/doc/redoc',
123+
'SWAGGER_UI_DIST': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist', # shorthand to use the sidecar instead
124+
'SWAGGER_UI_FAVICON_HREF': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist/favicon-32x32.png',
125+
'REDOC_DIST': f'{CONFIG.get_admin_path()}/api-doc/redoc',
126126
'SECURITY_DEFINITIONS': {
127127
'Bearer': {
128128
'type': 'apiKey',

apps/maxkb/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@
5252

5353
def pro():
5454
urlpatterns.append(
55-
re_path(r'^doc/(?P<path>.*)$', static.serve,
55+
re_path(rf'^{CONFIG.get_admin_path()[1:]}/api-doc/(?P<path>.*)$', static.serve,
5656
{'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar")}, name='doc'),
5757
)
58+
59+
urlpatterns.append(
60+
re_path(rf'^{CONFIG.get_chat_path()[1:]}/api-doc/(?P<path>.*)$', static.serve,
61+
{'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar")}, name='doc_chat'),
62+
)
5863
# 暴露ui静态资源
5964
urlpatterns.append(
6065
re_path(rf"^{CONFIG.get_admin_path()[1:]}/(?P<path>.*)$", static.serve,

ui/src/layout/layout-header/avatar/APIKeyDialog.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<span class="mr-4">
5050
<el-tooltip effect="dark" :content="$t('common.setting')" placement="top">
5151
<el-button type="primary" text @click.stop="settingApiKey(row)">
52-
<AppIcon iconName="app-setting"></AppIcon>
52+
<AppIcon iconName="app-setting"></AppIcon>
5353
</el-button>
5454
</el-tooltip>
5555
</span>
@@ -87,7 +87,7 @@ const props = defineProps({
8787
})
8888
const emit = defineEmits(['addData'])
8989
90-
const apiUrl = window.location.origin + '/doc/'
90+
const apiUrl = window.location.origin + +`${window.MaxKB.prefix}/api-doc/`
9191
const SettingAPIKeyDialogRef = ref()
9292
const dialogVisible = ref<boolean>(false)
9393
const loading = ref(false)
@@ -126,9 +126,7 @@ function changeState(bool: boolean, row: any) {
126126
const obj = {
127127
is_active: bool,
128128
}
129-
const str = bool
130-
? t('common.enabled')
131-
: t('common.disabled')
129+
const str = bool ? t('common.enabled') : t('common.disabled')
132130
systemKeyApi.putAPIKey(row.id, obj, loading).then((res) => {
133131
MsgSuccess(str)
134132
getApiKeyList()

ui/src/views/application-overview/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ const permissionPrecise = computed(() => {
229229
return permissionMap['application'][apiType.value]
230230
})
231231
232-
const apiUrl = window.location.origin + '/doc_chat/'
232+
const apiUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api-doc/`
233233
234234
const baseUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api/`
235235

0 commit comments

Comments
 (0)