Skip to content

Commit

Permalink
fix: prevent crash when parameters is illegally not an array (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpopp07 committed Sep 9, 2019
1 parent 3cd439b commit 5d8a429
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/plugins/validation/2and3/semantic-validators/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
);
Expand Down
36 changes: 36 additions & 0 deletions test/plugins/validation/2and3/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 5d8a429

Please sign in to comment.