Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/core/extractors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function decoratorExtractor(node: Node): RouteInfo | null {
const functionName = functionNameDefNode ? functionNameDefNode.text : ""

return {
object: objectNode.text,
owner: objectNode.text,
method: resolvedMethod,
path,
function: functionName,
Expand Down Expand Up @@ -360,7 +360,7 @@ export function includeRouterExtractor(node: Node): IncludeRouterInfo | null {
}

return {
object: call.object,
owner: call.object,
router: call.args[0]?.text ?? "",
prefix,
tags,
Expand All @@ -375,7 +375,7 @@ export function mountExtractor(node: Node): MountInfo | null {
}

return {
object: call.object,
owner: call.object,
path: extractPathFromNode(call.args[0]),
app: call.args[1].text,
}
Expand Down
9 changes: 6 additions & 3 deletions src/core/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function normalizeMethod(method: string): RouteMethod {
}

export interface RouteInfo {
object: string
// The router or app that owns this route
owner: string
method: string
path: string
function: string
Expand Down Expand Up @@ -61,14 +62,16 @@ export interface ImportInfo {
}

export interface IncludeRouterInfo {
object: string
// The app or router with the include_router call
owner: string
router: string
prefix: string
tags: string[]
}

export interface MountInfo {
object: string
// The app that owns this sub application mount
owner: string
path: string
app: string
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/routerResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function buildRouterGraphInternal(
// Find all routers included in the app
// Only include routes that belong directly to the app (not to local APIRouters)
const appRoutes = analysis.routes.filter(
(r) => r.object === appRouter.variableName,
(r) => r.owner === appRouter.variableName,
)
const rootRouter: RouterNode = {
filePath: resolvedEntryFile,
Expand Down Expand Up @@ -178,7 +178,7 @@ function resolveRouterReference(
)
if (localRouter) {
// Filter routes that belong to this router (decorated with @router.method)
const routerRoutes = analysis.routes.filter((r) => r.object === moduleName)
const routerRoutes = analysis.routes.filter((r) => r.owner === moduleName)
return {
filePath: currentFile,
variableName: localRouter.variableName,
Expand Down
8 changes: 4 additions & 4 deletions src/test/core/extractors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def list_users():

const result = decoratorExtractor(decoratedDefs[0])
assert.ok(result)
assert.strictEqual(result.object, "router")
assert.strictEqual(result.owner, "router")
assert.strictEqual(result.method, "get")
assert.strictEqual(result.path, "/users")
assert.strictEqual(result.function, "list_users")
Expand Down Expand Up @@ -82,7 +82,7 @@ def create_item():
const result = decoratorExtractor(decoratedDefs[0])

assert.ok(result)
assert.strictEqual(result.object, "app")
assert.strictEqual(result.owner, "app")
assert.strictEqual(result.method, "post")
assert.strictEqual(result.path, "/items")
})
Expand Down Expand Up @@ -385,7 +385,7 @@ def handler():
const result = includeRouterExtractor(calls[0])

assert.ok(result)
assert.strictEqual(result.object, "app")
assert.strictEqual(result.owner, "app")
assert.strictEqual(result.router, "users.router")
assert.strictEqual(result.prefix, "")
})
Expand Down Expand Up @@ -447,7 +447,7 @@ def handler():
const result = mountExtractor(calls[0])

assert.ok(result)
assert.strictEqual(result.object, "app")
assert.strictEqual(result.owner, "app")
assert.strictEqual(result.path, "/static")
assert.strictEqual(result.app, "static_app")
})
Expand Down