diff --git a/src/middleware.js b/src/middleware.js index 977920d..32f0470 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -28,12 +28,13 @@ function init(swaggerPath, options) { .forEach(function (currentMethod) { schemas[parsedPath][currentMethod.toLowerCase()] = {}; - let bodySchema = dereferenced.paths[currentPath][currentMethod].parameters.filter(function (parameter) { return parameter.in === 'body' }); + const parameters = dereferenced.paths[currentPath][currentMethod].parameters || []; + let bodySchema = parameters.filter(function (parameter) { return parameter.in === 'body' }); if (bodySchema.length > 0) { schemas[parsedPath][currentMethod].body = buildBodyValidation(bodySchema[0].schema, dereferenced.definitions, swaggers[1], currentPath, currentMethod, parsedPath); } - let localParameters = dereferenced.paths[currentPath][currentMethod].parameters.filter(function (parameter) { + let localParameters = parameters.filter(function (parameter) { return parameter.in !== 'body'; }).concat(pathParameters); if (localParameters.length > 0) { @@ -49,9 +50,9 @@ function init(swaggerPath, options) { /** * The middleware - should be called for each express route - * @param {any} req - * @param {any} res - * @param {any} next + * @param {any} req + * @param {any} res + * @param {any} next * @returns In case of an error will call `next` with `InputValidationError` */ function validate(req, res, next) { diff --git a/test/pet-store-swagger.yaml b/test/pet-store-swagger.yaml index 25ca2dd..76aedc6 100644 --- a/test/pet-store-swagger.yaml +++ b/test/pet-store-swagger.yaml @@ -145,6 +145,19 @@ paths: description: unexpected error schema: $ref: '#/definitions/Error' + /heartbeat: + get: + summary: Info for current system status + operationId: getHearbeat + responses: + "200": + description: Expected response to a valid request + schema: + $ref: '#/definitions/StatusReport' + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' definitions: Pet: required: @@ -172,6 +185,15 @@ definitions: # format: int32 message: type: string + StatusReport: + required: + - text + - code + properties: + text: + type: string + code: + type: string parameters: ApiVersion: name: 'api-version'