-
-
Notifications
You must be signed in to change notification settings - Fork 484
fix: duplication in request URL path when configuring OpenAPI #3306 #4072
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
base: main
Are you sure you want to change the base?
fix: duplication in request URL path when configuring OpenAPI #3306 #4072
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4072 +/- ##
==========================================
- Coverage 98.38% 98.34% -0.04%
==========================================
Files 348 348
Lines 15895 15907 +12
Branches 1756 1760 +4
==========================================
+ Hits 15638 15644 +6
- Misses 121 125 +4
- Partials 136 138 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
litestar/_openapi/plugin.py
Outdated
| """ | ||
| path = route.path_format or "/" | ||
| if self.app.path != "/": | ||
| return path.replace(self.app.path, "") or "/" |
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.
This can easily lead to bugs, if self.app.path is contained somewhere within path. If we are to do this, it should use .removeprefix.
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.
@provinzkraut Maybe use return path[len(self.app.path):] or "/" to support Python 3.8. ?
|
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4072 |
Description
I would like to propose a solution for issue #3306. I have created two methods in
OpenAPIPlugin:_normalize_route_pathis designed to remove redundant parts from the URL. Here, I assume that the URLs specified in servers have higher priority when building the Open API schema._normalize_default_serveris needed in cases where the user setsapp.pathbut does not defineserversinOpenApiConfig