-
Notifications
You must be signed in to change notification settings - Fork 396
Description
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