diff --git a/src/core/extractors.ts b/src/core/extractors.ts index 4ab9d09..8bcfd8e 100644 --- a/src/core/extractors.ts +++ b/src/core/extractors.ts @@ -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, @@ -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, @@ -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, } diff --git a/src/core/internal.ts b/src/core/internal.ts index 7acf254..fce7f17 100644 --- a/src/core/internal.ts +++ b/src/core/internal.ts @@ -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 @@ -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 } diff --git a/src/core/routerResolver.ts b/src/core/routerResolver.ts index 2d9827c..6e6e6c5 100644 --- a/src/core/routerResolver.ts +++ b/src/core/routerResolver.ts @@ -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, @@ -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, diff --git a/src/test/core/extractors.test.ts b/src/test/core/extractors.test.ts index c5b7ab0..712333d 100644 --- a/src/test/core/extractors.test.ts +++ b/src/test/core/extractors.test.ts @@ -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") @@ -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") }) @@ -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, "") }) @@ -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") })