Skip to content

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
@codecov
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.34%. Comparing base (1e0dc7c) to head (6949a39).

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

@github-actions
Copy link

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