docs: OpenAPI request URL (#4070)
parent
53082657d7
commit
4269eeb2c9
|
|
@ -18,21 +18,34 @@ chat_api_prefix = CONFIG.get_chat_path()[1:] + '/api/'
|
||||||
|
|
||||||
def init_app_doc(system_urlpatterns):
|
def init_app_doc(system_urlpatterns):
|
||||||
system_urlpatterns += [
|
system_urlpatterns += [
|
||||||
path('doc/schema/', SpectacularAPIView.as_view(), name='schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
|
path(f'{CONFIG.get_admin_path()[1:]}/api-doc/schema/', SpectacularAPIView.as_view(), name='schema'),
|
||||||
path('doc/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), # swagger-ui的路由
|
# 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):
|
def init_chat_doc(system_urlpatterns, chat_urlpatterns):
|
||||||
system_urlpatterns += [
|
system_urlpatterns += [
|
||||||
path('doc_chat/schema/',
|
path(f'{CONFIG.get_chat_path()[1:]}/api-doc/schema/',
|
||||||
SpectacularAPIView.as_view(patterns=[
|
SpectacularAPIView.as_view(patterns=[
|
||||||
URLPattern(pattern=f'{chat_api_prefix}{str(url.pattern)}', callback=url.callback,
|
URLPattern(pattern=f'{chat_api_prefix}{str(url.pattern)}', callback=url.callback,
|
||||||
default_args=url.default_args,
|
default_args=url.default_args,
|
||||||
name=url.name) for url in chat_urlpatterns if
|
name=url.name) for url in chat_urlpatterns if
|
||||||
['chat', 'open', 'profile'].__contains__(url.name)]),
|
['chat', 'open', 'profile'].__contains__(url.name)]),
|
||||||
name='chat_schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
|
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的路由
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,9 +120,9 @@ SPECTACULAR_SETTINGS = {
|
||||||
'VERSION': 'v2',
|
'VERSION': 'v2',
|
||||||
'SERVE_INCLUDE_SCHEMA': False,
|
'SERVE_INCLUDE_SCHEMA': False,
|
||||||
# OTHER SETTINGS
|
# OTHER SETTINGS
|
||||||
'SWAGGER_UI_DIST': '/doc/swagger-ui-dist', # shorthand to use the sidecar instead
|
'SWAGGER_UI_DIST': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist', # shorthand to use the sidecar instead
|
||||||
'SWAGGER_UI_FAVICON_HREF': '/doc/swagger-ui-dist/favicon-32x32.png',
|
'SWAGGER_UI_FAVICON_HREF': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist/favicon-32x32.png',
|
||||||
'REDOC_DIST': '/doc/redoc',
|
'REDOC_DIST': f'{CONFIG.get_admin_path()}/api-doc/redoc',
|
||||||
'SECURITY_DEFINITIONS': {
|
'SECURITY_DEFINITIONS': {
|
||||||
'Bearer': {
|
'Bearer': {
|
||||||
'type': 'apiKey',
|
'type': 'apiKey',
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,14 @@ init_doc(urlpatterns, chat_urlpatterns)
|
||||||
|
|
||||||
def pro():
|
def pro():
|
||||||
urlpatterns.append(
|
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'),
|
{'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静态资源
|
# 暴露ui静态资源
|
||||||
urlpatterns.append(
|
urlpatterns.append(
|
||||||
re_path(rf"^{CONFIG.get_admin_path()[1:]}/(?P<path>.*)$", static.serve,
|
re_path(rf"^{CONFIG.get_admin_path()[1:]}/(?P<path>.*)$", static.serve,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
<span class="mr-4">
|
<span class="mr-4">
|
||||||
<el-tooltip effect="dark" :content="$t('common.setting')" placement="top">
|
<el-tooltip effect="dark" :content="$t('common.setting')" placement="top">
|
||||||
<el-button type="primary" text @click.stop="settingApiKey(row)">
|
<el-button type="primary" text @click.stop="settingApiKey(row)">
|
||||||
<AppIcon iconName="app-setting"></AppIcon>
|
<AppIcon iconName="app-setting"></AppIcon>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -87,7 +87,7 @@ const props = defineProps({
|
||||||
})
|
})
|
||||||
const emit = defineEmits(['addData'])
|
const emit = defineEmits(['addData'])
|
||||||
|
|
||||||
const apiUrl = window.location.origin + '/doc/'
|
const apiUrl = window.location.origin + +`${window.MaxKB.prefix}/api-doc/`
|
||||||
const SettingAPIKeyDialogRef = ref()
|
const SettingAPIKeyDialogRef = ref()
|
||||||
const dialogVisible = ref<boolean>(false)
|
const dialogVisible = ref<boolean>(false)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
@ -126,9 +126,7 @@ function changeState(bool: boolean, row: any) {
|
||||||
const obj = {
|
const obj = {
|
||||||
is_active: bool,
|
is_active: bool,
|
||||||
}
|
}
|
||||||
const str = bool
|
const str = bool ? t('common.enabled') : t('common.disabled')
|
||||||
? t('common.enabled')
|
|
||||||
: t('common.disabled')
|
|
||||||
systemKeyApi.putAPIKey(row.id, obj, loading).then((res) => {
|
systemKeyApi.putAPIKey(row.id, obj, loading).then((res) => {
|
||||||
MsgSuccess(str)
|
MsgSuccess(str)
|
||||||
getApiKeyList()
|
getApiKeyList()
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ const permissionPrecise = computed(() => {
|
||||||
return permissionMap['application'][apiType.value]
|
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/`
|
const baseUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api/`
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue