Repository navigation
Keep a FastAPI router's prefix off routers the file didn't make (Python side of #71) - #161
Open
IdirBenSlama wants to merge 1 commit into
Open
IdirBenSlama wants to merge 1 commit into
IdirBenSlama wants to merge 1 commit into
Conversation
A Python mount whose name the file neither made nor imported from the project, such as what a factory returned (graphql_router = make_graphql_router(), then app.include_router(graphql_router, prefix="/api/v1/graphql")) or a router from an installed package, was taken for a router of the mounting file. Its prefix then went on every other router that file included (/api/v1/graphql/api/v1/items/list beside /api/v1/items/list), and a check added where it was included counted for them too, so Health could miss an open endpoint. This is the Python side of haydenschmitty#71: like jsMountTarget, mountTarget now returns null for such a name. A router the file makes, or declares routes on, is still the file's own. So that routers which only hold other routers keep handing their prefix on, the pattern for a router the file makes now also reads a type annotation and a longer module name (api_router: APIRouter = fastapi.routing.APIRouter()). The prefix a router declared that way is made with, APIRouter(prefix=...), is no longer dropped either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Fixes haydenschmitty#160.
IdirBenSlama
force-pushed
the
fix/160-python-unknown-mount-name
branch
from
November 20, 2026 22:55
f15ede5 to
8ab2f32
Compare
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.
What this changes
Fixes #160.
In a Python file, a router included under a name the file neither made nor imported from the project was taken for
a router of that file. Examples are what a factory returned, kept in a variable or called in place
(
app.include_router(make_admin_router(), prefix="/admin")), and a router from an installed package. Its prefixthen went on every other router the file included, so the map showed endpoints like
/api/v1/graphql/api/v1/items/listbeside the real/api/v1/items/list. A check added where it was included(
dependencies=[Depends(...)]) counted for those routers too, so Health could call an open endpoint protected.mountTarget's Python fallback now treats a name as the file's own router only in two cases:APIRouter(...),Blueprint(...)orRouter(...)(it is inrouters);APIRouter, whose routes are written in this file.Any other name returns
null, the same asjsMountTargethas done since #71.Narrowing the fallback means
routershas to find every router a file makes, or a router that only holds otherrouters (an
api_routerthat includes the rest) would stop handing its prefix on to them. Its pattern inextract.mjsdidn't read a type annotation (api_router: APIRouter = APIRouter(), or a Flask blueprint declaredthe same way) or more than one module name (
fastapi.routing.APIRouter()). It now reads both, with an annotation ofat most 200 characters, like the JS router pattern. A side effect people will notice: such a router's own prefix,
admin_router: APIRouter = APIRouter(prefix="/admin"), was dropped before and now applies.What this change doesn't do:
does. When the scan can see those routes, they keep their own path, which is the same as before this change.
Following the factory would need the Python extractor to record
name = factory()assignments, so I left it outto keep this change small.
api = TimedRouter(), a subclass ofAPIRouter) that declares no routes of itsown and only holds other routers isn't recognised, so the routers it holds lose its prefix. Before this change it
was recognised only because every unknown name was. Recording which router each Python mount is registered on
(the separate problem below) would cover this case too.
Changed files:
skills/floorplan/scripts/lib/routes.mjs: the Python fallback inmountTarget.skills/floorplan/scripts/lib/extract.mjs: the Pythonrouterspattern.tests/fastapi-mounts.test.mjsand the sampletests/fixtures/fastapi-mounts/: new.docs/development.md: a row for the new test file.CHANGELOG.md: a line under## Unreleased.How I tested it
npm test: 494 tests, 493 pass, 0 fail, 1 skipped (the Windows-only test). Run on macOS with Node 24.15.0.claude plugin validate .: passed.mainand all 6 pass with the change.fixtures/fastapi-mountscomes out as exactlyGET /api/v1/status/ping,GET /api/v1/items/listandDELETE /api/v1/items/{item_id}. Onmain, the two items endpoints also appearagain under
/api/v1/graphql.items, so Health reportsDELETE /items/{item_id}as open. This is checked before the endpoint list, so onmainthe test fails on theHealth result itself (no open endpoints).
fastapi.routing.APIRouter(prefix=...)gets its own prefix (onmain,POST /resetinstead ofPOST /admin/reset).maintoo, and guard against the fallback becoming too narrow: routers the file made (plain,annotated, or from a factory with routes declared on them) still get the prefix they are included with, and a
router that only holds other routers (annotated, under
fastapi.routing, or an annotated Flask blueprint)still hands its prefix on to them.
mainand with this branch. Onmain,359 endpoints sat under a factory router's prefix, and 352 of them were missing at their real address. With this
change, none are under that prefix, all 359 are at their real address, and every other endpoint kept its
address. One more of the project's own requests is matched to its endpoint (47 before, 48 after).
Checklist
npm testpassesclaude plugin validate .passesCHANGELOG.mdupdated, if people will notice the changeCreated with Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code