OvernightJS controllers cannot be extended
Opened this issue · 0 comments
Hello,
My project is currently using OvernightJS and I am exploring ways to do API versioning.
One of the ways I have attempted to maintain multiple API versions is to try and extend a currently functional Controller and leverage OOP.
I expected that if ControllerB extends ControllerA, ControllerB inherits the endpoints in ControllerA; after all, the endpoints in Controller A are just functions.
This does not seem to work.
See example code:
@Controller('api/pasta/v1')
export class ControllerA {
@Get('sauce')
public async getSauce(req, res, next): Promise<Response> {
// something happens here
}
@Get('fork')
public async getFork(req, res, next): Promise<Response> {
// something happens here
}
}
@Controller('api/pasta/v2')
export class ControllerB extends ControllerA {
@Get('sauce')
public async getSauce(req, res, next): Promise<Response> {
// something else happens here
}
}
Problem:
The behavior I see is that ControllerB's implementation of GET.api/pasta/v2/sauce is working, but GET.api/pasta/v2/fork is not even a recognized endpoint. This is what is being returned: 404 Not Found
Cannot GET /api/pasta/v2/fork
This means that ControllerB is not able to use its parent's endpoints.
Is this intentional? Or is this a bug?
Or is there a totally different way of approaching API Versioning with inheritance in OvernightJS?
Note: This problem exists for ChildControllers as well.