Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/titiler/core/titiler/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,18 @@ def update_openapi(app: FastAPI) -> FastAPI:
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
# Find the route for the openapi_url in the app
openapi_route: Route = next(
route for route in app.router.routes if route.path == app.openapi_url
)
# Use a for-loop to traverse and locate the openapi route,
# which avoids creating a potentially expensive generator.
openapi_url = app.openapi_url
for route in app.router.routes:
if route.path == openapi_url:
openapi_route: Route = route
break
else:
# Defensive: This is not in original logic; keep behavior identical by using next(...)
# if not found, next(...) would raise StopIteration, so we can raise the same for clarity.
raise StopIteration

# Store the old endpoint function so we can call it from the patched function
old_endpoint = openapi_route.endpoint

Expand All @@ -335,7 +343,6 @@ async def patched_openapi_endpoint(req: Request) -> Response:
# our patched function and replace the existing app with it.
openapi_route.app = request_response(patched_openapi_endpoint)

# return the patched app
return app


Expand Down