Expect
@epiphone I want to reduce the Source-code Size, so I wrote a Controller Abstract Class mixin:
import { Constructor } from 'web-utility';
import { Post, Body } from 'routing-controllers';
import { ResponseSchema } from 'routing-controllers-openapi';
export function Controller<M>(Model: Constructor<M>) {
abstract class BaseController {
@Post()
@ResponseSchema(Model)
// @ts-ignore
createOne(@Body() data: Model) {
// ORM logic
}
}
return BaseController;
}
Actual
But it thrown an error at:
|
/** Return full Express path of given route. */ |
|
export function getFullExpressPath(route: IRoute): string { |
|
const { action, controller, options } = route |
|
return ( |
|
(options.routePrefix || '') + |
|
(controller.route || '') + |
|
(action.route || '') |
|
) |
|
} |
TypeError: Cannot read property 'route' of undefined
at getFullExpressPath (D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\routing-controllers-openapi@3.1.0_routing-controllers@0.9.0\node_modules\routing-controllers-openapi\src\generateSpec.ts:18:17)
at getFullPath (D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\routing-controllers-openapi@3.1.0_routing-controllers@0.9.0\node_modules\routing-controllers-openapi\src\generateSpec.ts:27:31)
at D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\routing-controllers-openapi@3.1.0_routing-controllers@0.9.0\node_modules\routing-controllers-openapi\src\generateSpec.ts:77:6
at Array.map (<anonymous>)
at getPaths (D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\routing-controllers-openapi@3.1.0_routing-controllers@0.9.0\node_modules\routing-controllers-openapi\src\generateSpec.ts:76:29)
at Object.getSpec (D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\routing-controllers-openapi@3.1.0_routing-controllers@0.9.0\node_modules\routing-controllers-openapi\src\generateSpec.ts:291:12)
at routingControllersToSpec (D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\routing-controllers-openapi@3.1.0_routing-controllers@0.9.0\node_modules\routing-controllers-openapi\src\index.ts:28:16)
at createSwagger (D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\koagger@0.2.4\node_modules\koagger\dist\Swagger.js:16:77)
at createAPI (D:\Work\idea2app\REST-Node-ts\node_modules\.pnpm\koagger@0.2.4\node_modules\koagger\dist\index.js:10:44)
at Object.<anonymous> (D:\Work\idea2app\REST-Node-ts\source\controller\index.ts:10:53)
Reproduce code
idea2app/REST-Node-ts#1
Environment
| Software |
Version(s) |
| Node |
14.19.1 |
| PNPM |
7.11.0 |
| Operating System |
Windows 10 Pro 21H2 |
Expect
@epiphone I want to reduce the Source-code Size, so I wrote a Controller Abstract Class mixin:
Actual
But it thrown an error at:
routing-controllers-openapi/src/generateSpec.ts
Lines 13 to 21 in 7c5bc3e
Reproduce code
idea2app/REST-Node-ts#1
Environment