Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

StickKing
Copy link

Description

I would like to propose a solution for issue #3306. I have created two methods in OpenAPIPlugin:

  1. _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.
  2. _normalize_default_server is needed in cases where the user sets app.path but does not define servers in OpenApiConfig

@StickKing StickKing requested review from a team as code owners March 26, 2025 09:31
@github-actions github-actions bot added area/openapi This PR involves changes to the OpenAPI schema area/private-api This PR involves changes to the privatized API size: small type/bug pr/external Triage Required 🏥 This requires triage labels Mar 26, 2025
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.

Project coverage is 98.30%. Comparing base (8bcf051) to head (ef1a6d4).

Files with missing lines Patch % Lines
litestar/_openapi/plugin.py 53.84% 4 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

"""
path = route.path_format or "/"
if self.app.path != "/":
return path.replace(self.app.path, "") or "/"
Copy link
Member

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.

Copy link
Author

@StickKing StickKing Mar 28, 2025

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. ?

Copy link

github-actions bot commented Apr 3, 2025

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4072

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/openapi This PR involves changes to the OpenAPI schema area/private-api This PR involves changes to the privatized API pr/external size: small Triage Required 🏥 This requires triage type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants