Skip to content

Routes defined in base controller classes are not registered in child controllers #100

Description

@felipepmdias

I’ve identified an issue related to route registration when using inheritance in controllers.

Problem

When defining routes in a base controller class and extending it in a concrete controller annotated with @RestController, the routes declared in the base class are not registered.

Example:

abstract class BaseController {
  @Get('/ping')
  ping() {
    return 'pong';
  }
}

@RestController('/example')
class ExampleController extends BaseController {}

In this case, calling /example/ping does not work because the route is not registered, even though the method exists and is inherited.

Motivation

Using a base controller is a common and powerful pattern to:

  • reuse endpoint logic across different external integrations (e.g., multiple third-party providers)
  • enforce consistent API structure
  • apply shared behaviors (auth, validation, etc.)

Currently, this pattern is not supported due to how routes are discovered.

Root Cause

From analyzing the compiled code, route discovery appears to rely on:

Object.getOwnPropertyNames(prototype)

This only returns methods defined directly on the class prototype and does not traverse the prototype chain. As a result, inherited methods (and their decorators/metadata) are ignored.

Suggested Solution

Update the route discovery logic to traverse the prototype chain and collect methods from parent classes as well.

For example:

function getAllMethods(prototype: any): string[] {
  const methods = new Set<string>();

  while (prototype && prototype !== Object.prototype) {
    Object.getOwnPropertyNames(prototype).forEach(name => {
      if (name !== 'constructor') {
        methods.add(name);
      }
    });
    prototype = Object.getPrototypeOf(prototype);
  }

  return Array.from(methods);
}

This would allow Boot.gs to properly register routes defined in base classes while preserving current behavior.


Thanks again for the excellent framework — this enhancement would make it even more powerful and flexible for real-world use cases.

Metadata

Metadata

Labels

bugSomething isn't workingenhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions