-
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
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| name='swagger-ui'), # swagger-ui的路由 | ||
| ] | ||
|
|
||
|
|
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:
def init_app_doc(system_urlpatterns):
system_urlpatterns += [
path(
f'{CONFIG.get_admin_path()[1:]}/api-doc/schema/',
SpectacularAPIView.as_view(),
name='schema'
),
# schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
path( # Swagger UI的路由
f'{CONFIG.get_admin_path()[1:]}/api-doc/',
SpectacularSwaggerView.as_view(url_name='schema'),
name='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.append( # Append app doc URL patterns to the main system URL list
path(
f'{CONFIG.get_chat_path()[1:]}/api-doc/schema/',
SpectacularAPIView.as_view(patterns=[ # Create a new route with specific pattern
# Iterate over each URL pattern in chat_urlpatterns
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' in url.name],
name='chat_schema') # Name for this route
) # Swagger UI route for chat API documentation
)These changes will make the code slightly cleaner and more maintainable.
| const str = bool ? t('common.enabled') : t('common.disabled') | ||
| systemKeyApi.putAPIKey(row.id, obj, loading).then((res) => { | ||
| MsgSuccess(str) | ||
| getApiKeyList() |
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 provided code has a small issue and can be improved slightly:
-
Suggested Changes:
The error seems to be due to an incorrect way of concatenating strings in JavaScript. Instead of
window.location.origin + +${window.MaxKB.prefix}/api-doc/, it should be fixed using a template literal. -
Corrected Code Snippet:
Here's the corrected version of the relevant part of your code:
const apiUrl = window.location.origin + `${(window?.MaxKB ?? {}).prefix || ''}/api-doc/`;Explanation:
- Using
(window?.MaxKB ?? '')ensures that ifwindow?.MaxKBdoes not exist (i.e., this might happen on some platforms), it defaults to an empty string, preventing errors from the concatenation. - Added
{}aroundMaxKBto correctly access its properties when available.
This change will prevent any issues related to undefined values or improper string concatenation.
Note: Ensure that maxKB is defined with a prefix before making calls like these to avoid further errors.
| ) | ||
| # 暴露ui静态资源 | ||
| urlpatterns.append( | ||
| re_path(rf"^{CONFIG.get_admin_path()[1:]}/(?P<path>.*)$", static.serve, |
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 provided code is mostly syntactically and semantically correct. However, there are a few improvements that can be made:
-
Duplicated API Documentation URLs: The duplicate
api-docURL patterns will clash with each other when both paths point to different endpoints within the application. It would be better to rename these to avoid conflicts. -
Use of Regular Expressions: In Python 3.x, using single quotes (
') instead of double quotes (") for string literals does not affect functionality but it's generally recommended for consistency.
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:
- Changed
'doc/'to'openapi/'. - Added an `{'name': '...'} dictionary entry to give a unique name to the openAPI endpoint.
- Renamed the second set of API documentation URLs accordingly (
.chat/).
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.
docs: OpenAPI request URL