Repository navigation
fix: don't serve FastAPI's /docs, /redoc and /openapi.json in Flet web apps - #7112
Open
joaoaracheski wants to merge 2 commits into
Open
joaoaracheski wants to merge 2 commits into
joaoaracheski wants to merge 2 commits into
Conversation
flet_web.fastapi.app() and flet run --web created FastAPI() with the default /docs, /redoc and /openapi.json. Registered before the static files mounted at /, they took those paths from the app and loaded Swagger UI and ReDoc from a CDN even with no_cdn=True. Fixes flet-dev#7111
This branch has not been deployed
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.
Description
Fixes #7111.
flet_web.fastapi.app()andflet run --webcreatedFastAPI()with the defaults, so/docs,/redocand/openapi.jsonwere on. They are registered before the static files mounted at/, so a page route like/docsopened Swagger instead of the app, and Swagger UI and ReDoc loaded from a CDN even withno_cdn=True.Now the apps Flet creates pass
docs_url=None, redoc_url=None, openapi_url=None:flet_web/fastapi/app.py: the app returned byflet_web.fastapi.app();flet_web/fastapi/serve_fastapi_web_app.py: the outer app offlet run --web(both places).The
flet_web.fastapi.FastAPIclass wasn't changed, so a FastAPI app the user creates keeps its docs.Test code
Before: http://localhost:8000/docs opens Swagger UI.
After: it opens the app.
New
tests/test_docs_routes.pychecks both apps: no Swagger, ReDoc or schema on the three paths, and/docsand/redocserve the app. The 10 new tests fail without the fix; the user's ownFastAPI()keeping its docs passes either way. flet-web: 62 passed.Type of change
Checklist
website/sidebars.ymlfor breaking changes, removals, and deprecations, if applicable.Additional details
Found it in an internal tool at work that runs on Flet web. I was removing these routes by hand there.
Summary by Sourcery
Disable FastAPI’s interactive documentation routes in applications created by Flet while preserving them for user-created FastAPI apps.
Bug Fixes:
/docs,/redoc, and/openapi.jsonroutes, allowing application routes with those paths to work and avoiding unintended CDN-loaded documentation interfaces.Tests: