Problem
Three documented FastAPI registration patterns are invisible to the adapter (docs/PARSERS_AND_ADAPTERS.md, "FastAPI — Not yet"): programmatic app.add_api_route(...), ASGI middleware via app.add_middleware(...) / @app.middleware("http"), and mounted sub-applications via app.mount(...). Programmatic registration hides entire routes from the inventory, and middleware-based auth (centralized JWT/session verification, very common in production FastAPI) means guarded routes are reported as unguarded.
Current behavior
- The FastAPI adapter (
crates/authmap-adapters/src/lib.rs, FastApiAdapter) recognizes route decorators, @app.websocket, api_route, APIRouter/include_router with prefix and dependencies= (fastapi_dependencies_from_keyword), and Depends(...)/Security(...) guards.
- There is no code path for
add_api_route, add_middleware/@app.middleware, or mount; no diagnostic is emitted either, so the gap is silent.
Proposed implementation
app.add_api_route(path, endpoint, methods=[...], dependencies=[...])
- Detect the call on known app/router receivers; map onto the existing decorator-route model (path literal, methods list, endpoint symbol resolved via the same handler-resolution used for decorators,
dependencies= reusing fastapi_dependencies_from_keyword).
- Dynamic path/methods → emit a diagnostic (
fastapi_dynamic_route_registration) instead of guessing.
app.add_middleware(AuthMiddleware, ...) and @app.middleware("http")
- Emit app-scoped evidence classified by the middleware symbol name against evidence rules (same approach as Next.js
middleware.ts classification in crates/authmap-adapters/src/nextjs.rs: recognized auth helper → evidence; unrecognized → coverage left unclaimed plus a fastapi_middleware_unclassified diagnostic so reviewers know a middleware stack exists).
- Order matters less than for Express since FastAPI middleware wraps the whole app — safe to apply to all routes of that app instance.
app.mount("/prefix", subapp)
- Compose prefixes exactly like
include_router when subapp resolves to a FastAPI/APIRouter instance in the scanned tree; emit fastapi_unresolved_mount diagnostic when it doesn't (e.g., mounting third-party ASGI apps like static files — should not fabricate routes).
Acceptance criteria
References
docs/PARSERS_AND_ADAPTERS.md FastAPI limitations paragraph
crates/authmap-adapters/src/lib.rs (FastApiAdapter, fastapi_dependencies_from_keyword)
- Next.js middleware classification precedent:
crates/authmap-adapters/src/nextjs.rs (NEXTJS_MIDDLEWARE_AUTH_HELPERS)
Problem
Three documented FastAPI registration patterns are invisible to the adapter (
docs/PARSERS_AND_ADAPTERS.md, "FastAPI — Not yet"): programmaticapp.add_api_route(...), ASGI middleware viaapp.add_middleware(...)/@app.middleware("http"), and mounted sub-applications viaapp.mount(...). Programmatic registration hides entire routes from the inventory, and middleware-based auth (centralized JWT/session verification, very common in production FastAPI) means guarded routes are reported as unguarded.Current behavior
crates/authmap-adapters/src/lib.rs,FastApiAdapter) recognizes route decorators,@app.websocket,api_route,APIRouter/include_routerwithprefixanddependencies=(fastapi_dependencies_from_keyword), andDepends(...)/Security(...)guards.add_api_route,add_middleware/@app.middleware, ormount; no diagnostic is emitted either, so the gap is silent.Proposed implementation
app.add_api_route(path, endpoint, methods=[...], dependencies=[...])dependencies=reusingfastapi_dependencies_from_keyword).fastapi_dynamic_route_registration) instead of guessing.app.add_middleware(AuthMiddleware, ...)and@app.middleware("http")middleware.tsclassification incrates/authmap-adapters/src/nextjs.rs: recognized auth helper → evidence; unrecognized → coverage left unclaimed plus afastapi_middleware_unclassifieddiagnostic so reviewers know a middleware stack exists).app.mount("/prefix", subapp)include_routerwhensubappresolves to a FastAPI/APIRouter instance in the scanned tree; emitfastapi_unresolved_mountdiagnostic when it doesn't (e.g., mounting third-party ASGI apps like static files — should not fabricate routes).Acceptance criteria
add_api_routeyields the same route/evidence output as the equivalent decorator form.add_middlewareclassifies its routes as guarded; non-auth middleware leaves classification unchanged but emits the unclassified-middleware diagnostic.fastapi_unresolved_mount.authmap-coreanddocs/DIAGNOSTICS.md.docs/PARSERS_AND_ADAPTERS.mdFastAPI Not yet list updated; CHANGELOG entry.References
docs/PARSERS_AND_ADAPTERS.mdFastAPI limitations paragraphcrates/authmap-adapters/src/lib.rs(FastApiAdapter,fastapi_dependencies_from_keyword)crates/authmap-adapters/src/nextjs.rs(NEXTJS_MIDDLEWARE_AUTH_HELPERS)