-
-
Notifications
You must be signed in to change notification settings - Fork 420
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.34% 98.30% -0.04%
==========================================
Files 348 348
Lines 15829 15841 +12
Branches 1749 1753 +4
==========================================
+ Hits 15567 15573 +6
- Misses 125 129 +4
- Partials 137 139 +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_path
is 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_server
is needed in cases where the user setsapp.path
but does not defineservers
inOpenApiConfig