Skip to content

fix: don't serve FastAPI's /docs, /redoc and /openapi.json in Flet web apps - #7112

Open
joaoaracheski wants to merge 2 commits into
flet-dev:mainfrom
joaoaracheski:fix-fastapi-disable-docs-routes
Open

joaoaracheski wants to merge 2 commits into
flet-dev:mainfrom
joaoaracheski:fix-fastapi-disable-docs-routes

Conversation

@joaoaracheski

@joaoaracheski joaoaracheski commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #7111.

flet_web.fastapi.app() and flet run --web created FastAPI() with the defaults, so /docs, /redoc and /openapi.json were on. They are registered before the static files mounted at /, so a page route like /docs opened Swagger instead of the app, and Swagger UI and ReDoc loaded from a CDN even with no_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 by flet_web.fastapi.app();
  • flet_web/fastapi/serve_fastapi_web_app.py: the outer app of flet run --web (both places).

The flet_web.fastapi.FastAPI class wasn't changed, so a FastAPI app the user creates keeps its docs.

Test code

import flet as ft
import flet_web.fastapi as flet_fastapi
import uvicorn


def main(page: ft.Page):
    page.add(ft.Text("Hello"))


app = flet_fastapi.app(main, no_cdn=True)
uvicorn.run(app, port=8000)

Before: http://localhost:8000/docs opens Swagger UI.
After: it opens the app.

New tests/test_docs_routes.py checks both apps: no Swagger, ReDoc or schema on the three paths, and /docs and /redoc serve the app. The 10 new tests fail without the fix; the user's own FastAPI() keeping its docs passes either way. flet-web: 62 passed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I signed the CLA.
  • I have performed a self-review of my own code.
  • My code follows the style guidelines of this project.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.
  • New and existing tests pass locally with my changes.
  • I have made corresponding documentation changes, if applicable.
  • I have added changelog entries for user-facing changes, if applicable.
  • I have updated release guide pages and website/sidebars.yml for 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:

  • Prevent Flet-created web apps from serving FastAPI’s /docs, /redoc, and /openapi.json routes, allowing application routes with those paths to work and avoiding unintended CDN-loaded documentation interfaces.

Tests:

  • Add coverage for both Flet web app entry points to verify FastAPI documentation routes are disabled while user-created FastAPI applications retain their documentation.

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
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: web apps serve FastAPI's /docs, /redoc and /openapi.json, taking those routes from the app

2 participants