A FastAPI router gets its prefix where it is included, away from the routes that it applies to
What it finds
app.include_router(users, prefix="/users") puts part of every route's path far from the routes. APIRouter(prefix="/users") keeps it with them, so the router reads the same wherever it is included.
From the rule's source, router_prefix_at_include.rs.
from fastapi import APIRouter, FastAPI app = FastAPI()users = APIRouter(prefix="/users")items = APIRouter()app.include_router(users)app.include_router(items, prefix="/items")tx0 reports: the prefix belongs to the APIRouter(...) Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:router-prefix-at-include" = "note"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:router-prefix-at-include] reason="..."tx0 explain tx0/python:router-prefix-at-include shows the same in the terminal. Found a false positive? Report it.