Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/appDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ async function findAllFastAPIFiles(
)
continue
const content = await vscode.workspace.fs.readFile(uri)
if (new TextDecoder().decode(content).includes("FastAPI(")) {
const text = new TextDecoder().decode(content)
if (text.includes("FastAPI(") || text.includes("APIRouter(")) {
results.push(uri.toString())
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/core/routerResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,5 +517,28 @@ suite("routerResolver", () => {
"neon router should have routes",
)
})

test("builds graph from standalone APIRouter-only file", async () => {
const result = await buildRouterGraph(
fixtures.routerOnly.mainPy,
parser,
fixtures.routerOnly.root,
nodeFileSystem,
)

assert.ok(result, "Should find router in APIRouter-only file")
assert.strictEqual(result.type, "APIRouter")
assert.strictEqual(result.variableName, "router")
assert.strictEqual(result.prefix, "/api")

// Should have 2 routes: GET /items and POST /items
assert.strictEqual(result.routes.length, 2)
const getPaths = result.routes.map((r) => `${r.method} ${r.path}`)
assert.ok(getPaths.includes("get /items"), "Should have GET /items route")
assert.ok(
getPaths.includes("post /items"),
"Should have POST /items route",
)
})
})
})
4 changes: 4 additions & 0 deletions src/test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export const fixtures = {
root: uri(join(fixturesPath, "error-cases")),
mainPy: uri(join(fixturesPath, "error-cases", "main.py")),
},
routerOnly: {
root: uri(join(fixturesPath, "router-only")),
mainPy: uri(join(fixturesPath, "router-only", "main.py")),
},
nestedRouter: {
root: uri(join(fixturesPath, "nested-router")),
mainPy: uri(join(fixturesPath, "nested-router", "app", "main.py")),
Expand Down
Loading