diff --git a/package.json b/package.json index babd96a5..3d3cf09c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "inversify-express-utils", - "version": "5.1.1", + "version": "5.1.2", "description": "Some utilities for the development of express applications with Inversify", "main": "lib/index.js", "jsnext:main": "es/index.js", diff --git a/src/debug.ts b/src/debug.ts index aa5dbfc7..13e669c0 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -22,40 +22,43 @@ export function getRouteInfo(container: inversifyInterfaces.Container) { const method = m.method.toUpperCase(); const controllerPath = r.controllerMetadata.path; const actionPath = m.path; - const paramMetadata = r.parameterMetadata[m.key] || undefined; + const paramMetadata = r.parameterMetadata; let args: string[] | undefined = undefined; - if (paramMetadata) { - args = (r.parameterMetadata[m.key] || []).map(a => { - let type = ""; - switch (a.type) { - case PARAMETER_TYPE.RESPONSE: - type = "@response"; - break; - case PARAMETER_TYPE.REQUEST: - type = "@request"; - break; - case PARAMETER_TYPE.NEXT: - type = "@next"; - break; - case PARAMETER_TYPE.PARAMS: - type = "@requestParam"; - break; - case PARAMETER_TYPE.QUERY: - type = "queryParam"; - break; - case PARAMETER_TYPE.BODY: - type = "@requestBody"; - break; - case PARAMETER_TYPE.HEADERS: - type = "@requestHeaders"; - break; - case PARAMETER_TYPE.COOKIES: - type = "@cookies"; - break; - } - return `${type} ${a.parameterName}`; - }); + if (paramMetadata !== undefined ) { + const paramMetadataForKey = paramMetadata[m.key] || undefined; + if (paramMetadataForKey) { + args = (r.parameterMetadata[m.key] || []).map(a => { + let type = ""; + switch (a.type) { + case PARAMETER_TYPE.RESPONSE: + type = "@response"; + break; + case PARAMETER_TYPE.REQUEST: + type = "@request"; + break; + case PARAMETER_TYPE.NEXT: + type = "@next"; + break; + case PARAMETER_TYPE.PARAMS: + type = "@requestParam"; + break; + case PARAMETER_TYPE.QUERY: + type = "queryParam"; + break; + case PARAMETER_TYPE.BODY: + type = "@requestBody"; + break; + case PARAMETER_TYPE.HEADERS: + type = "@requestHeaders"; + break; + case PARAMETER_TYPE.COOKIES: + type = "@cookies"; + break; + } + return `${type} ${a.parameterName}`; + }); + } } const details = { diff --git a/test/debug.test.ts b/test/debug.test.ts index 5b9663b0..f19a7900 100644 --- a/test/debug.test.ts +++ b/test/debug.test.ts @@ -107,4 +107,43 @@ describe("Debug utils", () => { }); + it("should be able to handle missig parameter metadata", () => { + + let container = new Container(); + + @controller("/api/order") + class OrderController extends BaseHttpController { + @httpGet("/") + public get() { + return {}; + } + @httpPost("/") + public post() { + return {}; + } + } + + const TYPES = { + OrderController: OrderController.name + }; + + let server = new InversifyExpressServer(container); + let app = server.build(); + + const routeInfo = getRouteInfo(container); + + console.log( + prettyjson.render({ CONTROLLERS: routeInfo }) + ); + + console.log(routeInfo); + + expect(routeInfo[0].controller).to.eq(TYPES.OrderController); + expect(routeInfo[0].endpoints[0].route).to.eq("GET /api/order/"); + expect(routeInfo[0].endpoints[0].args).to.eq(undefined); + expect(routeInfo[0].endpoints[1].route).to.eq("POST /api/order/"); + expect(routeInfo[0].endpoints[1].args).to.eq(undefined); + + }); + });