diff --git a/src/plugins/validation/2and3/semantic-validators/paths.js b/src/plugins/validation/2and3/semantic-validators/paths.js index dff521930..65566a4c2 100644 --- a/src/plugins/validation/2and3/semantic-validators/paths.js +++ b/src/plugins/validation/2and3/semantic-validators/paths.js @@ -73,14 +73,18 @@ module.exports.validate = function({ resolvedSpec }) { return param; }); - each(path, (thing, thingName) => { - if (thing && thing.parameters) { + each(path, (operation, operationName) => { + if ( + operation && + operation.parameters && + Array.isArray(operation.parameters) + ) { availableParameters.push( - ...thing.parameters.map((param, i) => { + ...operation.parameters.map((param, i) => { if (!isObject(param)) { return; } - param.$$path = `paths.${pathName}.${thingName}.parameters[${i}]`; + param.$$path = `paths.${pathName}.${operationName}.parameters[${i}]`; return param; }) ); diff --git a/test/plugins/validation/2and3/paths.js b/test/plugins/validation/2and3/paths.js index eeac51adb..6d611e447 100644 --- a/test/plugins/validation/2and3/paths.js +++ b/test/plugins/validation/2and3/paths.js @@ -352,4 +352,40 @@ describe('validation plugin - semantic - paths', function() { expect(res.warnings).toEqual([]); }); }); + + it('should not crash when `parameters` is not an array', function() { + const spec = { + paths: { + '/resource': { + get: { + operationId: 'listResources', + description: 'operation with bad parameters...', + summary: '...but it should not crash the code', + parameters: { + allOf: [ + { + name: 'one', + type: 'string' + }, + { + name: 'two', + type: 'string' + } + ] + }, + responses: { + '200': { + description: 'response' + } + } + } + } + } + }; + + const res = validate({ resolvedSpec: spec }); + // errors/warnings would be caught it parameters-ibm.js + expect(res.errors.length).toBe(0); + expect(res.warnings.length).toBe(0); + }); });