Skip to content

fix: Param injection in case of controller inheritance gives null values #1538

@mschmitz-personal

Description

@mschmitz-personal

Description

When following the documentation about controller inheritance (https://github.com/typestack/routing-controllers?tab=readme-ov-file#controller-inheritance) and also the test/sample code (https://github.com/typestack/routing-controllers/pull/578/files#), the inheritance of the end-points appear to be working, but the injection of Params, Body, CTX on method level is delivering null values.

Scenario is to implement a generic base class handling CRUD operations, like also indicated in the documentation. Fully aware that this was discussed in older posts (2017, 2019) and some voices doubt the benefit of such a construct, but it would be helpful in my case.

Minimal code-snippet showcasing the problem

class ControllerTemplate {
  @Get('/hello/:name')
  public read(@Param('name') name: string) {
    return { data: name };
  }
}

@JsonController('/product')
export class ProductController extends ControllerTemplate {}

Expected behavior

When calling URL "GET //localhost:3000/product/hello/Markus" I am expecting a return of "{ data: "Markus" }".

Actual behavior

Receiving "{ }". Debugging also shows that name is simply null in the controller method. Tried the same also with other injections CTX(), REQ(), Body() etc

The following code works, but requires repeating the signature of all inherited end points:

class ControllerTemplate {
  public read(name: string) {
    return { data: name };
  }
}

@JsonController('/product')
export class ProductController extends ControllerTemplate {
  @Get('/hello/:name') public read(@Param('name') name: string) { return super.read(name); }
}

Is a specific setup required for this?

Thank you to the team,

Markus

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions