-
Notifications
You must be signed in to change notification settings - Fork 2.6k
docs: OpenAPI request URL #4070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,9 +52,14 @@ | |
|
|
||
| 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, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code is mostly syntactically and semantically correct. However, there are a few improvements that can be made:
Here's the optimized version of the code: @@ -52,9 +52,14 @@
def pro():
urlpatterns.append(
- re_path(r'^doc/(?P<path>.*)$', static.serve,
+ re_path(rf'^{CONFIG.get_admin_path()[1:]}/openapi/(?P<path>.*)$', static.serve,
{'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar"), 'name': 'openapi'},
),
)
+
+ urlpatterns.append(
+ re_path(rf'^{CONFIG.get_chat_path()[1:]}/openapi/(?P<path>.*)$', static.serve,
+ {'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar"), 'name': 'openapi_chat'},
+ ),
+ )
# 暴露ui静态资源
urlpatterns.append(
re_path(rf"^/{CONFIG.get_admin_path()[1:]}/(?P<path>.*)$", static.serve,Key Changes:
These changes make the code more maintainable and prevent potential conflicts with different types or categories of API documentation. Additionally, providing meaningful names can be helpful for easier management and documentation. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has a small issue and can be improved slightly:
Here's the corrected version of the relevant part of your code: const apiUrl = window.location.origin + `${(window?.MaxKB ?? {}).prefix || ''}/api-doc/`;Explanation:
This change will prevent any issues related to undefined values or improper string concatenation. Note: Ensure that |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks generally correct, but there are a few minor issues and optimizations that can be made:
Use
pathinstead of string concatenation: It's more pythonic to use thepathfunction from Django URLs compared to string concatenation. This makes the code cleaner and easier to read.Consistent spacing around operators and brackets: Ensure consistent formatting for readability, especially outside parentheses and between operators like
=and,.Remove unnecessary comments at the end of lines: Python doesn't require trailing comments on inline strings. Remove these for better readability.
Here is the revised version of the code:
These changes will make the code slightly cleaner and more maintainable.