docs: OpenAPI request URL (#4070)
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
Typos Check / Spell Check with Typos (push) Waiting to run

This commit is contained in:
shaohuzhang1 2025-09-22 11:51:59 +08:00 committed by GitHub
parent 53082657d7
commit 4269eeb2c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 14 deletions

View File

@ -18,21 +18,34 @@ chat_api_prefix = CONFIG.get_chat_path()[1:] + '/api/'
def init_app_doc(system_urlpatterns):
system_urlpatterns += [
path('doc/schema/', SpectacularAPIView.as_view(), name='schema'), # schema的配置文件的路由下面两个ui也是根据这个配置文件来生成的
path('doc/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), # swagger-ui的路由
path(f'{CONFIG.get_admin_path()[1:]}/api-doc/schema/', SpectacularAPIView.as_view(), name='schema'),
# schema的配置文件的路由下面两个ui也是根据这个配置文件来生成的
path(f'{CONFIG.get_admin_path()[1:]}/api-doc/', SpectacularSwaggerView.as_view(url_name='schema'),
name='swagger-ui'), # swagger-ui的路由
]
class ChatSpectacularSwaggerView(SpectacularSwaggerView):
@staticmethod
def _swagger_ui_resource(filename):
return f'{CONFIG.get_chat_path()}/api-doc/swagger-ui-dist/{filename}'
@staticmethod
def _swagger_ui_favicon():
return f'{CONFIG.get_chat_path()}/api-doc/swagger-ui-dist/favicon-32x32.png'
def init_chat_doc(system_urlpatterns, chat_urlpatterns):
system_urlpatterns += [
path('doc_chat/schema/',
path(f'{CONFIG.get_chat_path()[1:]}/api-doc/schema/',
SpectacularAPIView.as_view(patterns=[
URLPattern(pattern=f'{chat_api_prefix}{str(url.pattern)}', callback=url.callback,
default_args=url.default_args,
name=url.name) for url in chat_urlpatterns if
['chat', 'open', 'profile'].__contains__(url.name)]),
name='chat_schema'), # schema的配置文件的路由下面两个ui也是根据这个配置文件来生成的
path('doc_chat/', SpectacularSwaggerView.as_view(url_name='chat_schema'), name='swagger-ui'), # swagger-ui的路由
path(f'{CONFIG.get_chat_path()[1:]}/api-doc/', ChatSpectacularSwaggerView.as_view(url_name='chat_schema'),
name='swagger-ui'), # swagger-ui的路由
]

View File

@ -120,9 +120,9 @@ SPECTACULAR_SETTINGS = {
'VERSION': 'v2',
'SERVE_INCLUDE_SCHEMA': False,
# OTHER SETTINGS
'SWAGGER_UI_DIST': '/doc/swagger-ui-dist', # shorthand to use the sidecar instead
'SWAGGER_UI_FAVICON_HREF': '/doc/swagger-ui-dist/favicon-32x32.png',
'REDOC_DIST': '/doc/redoc',
'SWAGGER_UI_DIST': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist', # shorthand to use the sidecar instead
'SWAGGER_UI_FAVICON_HREF': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist/favicon-32x32.png',
'REDOC_DIST': f'{CONFIG.get_admin_path()}/api-doc/redoc',
'SECURITY_DEFINITIONS': {
'Bearer': {
'type': 'apiKey',

View File

@ -52,9 +52,14 @@ init_doc(urlpatterns, chat_urlpatterns)
def pro():
urlpatterns.append(
re_path(r'^doc/(?P<path>.*)$', static.serve,
re_path(rf'^{CONFIG.get_admin_path()[1:]}/api-doc/(?P<path>.*)$', static.serve,
{'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar")}, name='doc'),
)
urlpatterns.append(
re_path(rf'^{CONFIG.get_chat_path()[1:]}/api-doc/(?P<path>.*)$', static.serve,
{'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar")}, name='doc_chat'),
)
# 暴露ui静态资源
urlpatterns.append(
re_path(rf"^{CONFIG.get_admin_path()[1:]}/(?P<path>.*)$", static.serve,

View File

@ -49,7 +49,7 @@
<span class="mr-4">
<el-tooltip effect="dark" :content="$t('common.setting')" placement="top">
<el-button type="primary" text @click.stop="settingApiKey(row)">
<AppIcon iconName="app-setting"></AppIcon>
<AppIcon iconName="app-setting"></AppIcon>
</el-button>
</el-tooltip>
</span>
@ -87,7 +87,7 @@ const props = defineProps({
})
const emit = defineEmits(['addData'])
const apiUrl = window.location.origin + '/doc/'
const apiUrl = window.location.origin + +`${window.MaxKB.prefix}/api-doc/`
const SettingAPIKeyDialogRef = ref()
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
@ -126,9 +126,7 @@ function changeState(bool: boolean, row: any) {
const obj = {
is_active: bool,
}
const str = bool
? t('common.enabled')
: t('common.disabled')
const str = bool ? t('common.enabled') : t('common.disabled')
systemKeyApi.putAPIKey(row.id, obj, loading).then((res) => {
MsgSuccess(str)
getApiKeyList()

View File

@ -229,7 +229,7 @@ const permissionPrecise = computed(() => {
return permissionMap['application'][apiType.value]
})
const apiUrl = window.location.origin + '/doc_chat/'
const apiUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api-doc/`
const baseUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api/`