fix: honor root_path in offline-docs redoc handler#89
Merged
Conversation
Sequences criticals + design issues from the audit into 7 small, dependency-ordered PRs with locked decisions per chunk. Refactor opportunities and low-priority items deferred to a future planning pass. Excluded from the mkdocs site like the parent audit doc. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The swagger handler in enable_offline_docs already reads root_path from the ASGI scope and prefixes asset/OpenAPI URLs. The redoc handler did not, so redoc 404'd on its JS and OpenAPI spec when the FastAPI app ran behind a reverse proxy. Mirror the swagger pattern: take Request, read root_path, prefix both redoc_js_url and openapi_url. Extends test_fastapi_offline_docs_root_path to fetch redoc and assert both URLs carry the prefix — the test fails on the prior code. Closes CRIT-1, TEST-1 from the audit.
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
enable_offline_docsnow readsroot_pathfrom the ASGI scope and prefixes bothredoc_js_urlandopenapi_url, matching the existing swagger handler pattern.test_fastapi_offline_docs_root_pathextended to fetch redoc and assert both URLs carry theroot_pathprefix. Test fails onmain, passes on this branch.Closes CRIT-1 and TEST-1 from an internal audit of the codebase.
Test plan
just test -- tests/test_fastapi_offline_docs.py -v— three tests pass.just test— full suite passes (79/79).just lint— clean (eof-fixer, ruff format, ruff check, ty check).root_pathpattern.🤖 Generated with Claude Code