Local scope for mismatch aggregator - prevents duplicate mismatches

This commit is contained in:
Abhijit Kane
2020-01-03 19:35:20 +05:30
parent 76ef987f0b
commit b87a28e951

View File

@@ -1854,9 +1854,7 @@ module.exports = {
// schema path should have all parameters needed
// components need to be stored globally
var mismatches = [],
// a mismatch has to be {property: header/body etc., jsonPath: x/y/z, reason: ....}
mismatchProperty = 'PATHVARIABLE',
var mismatchProperty = 'PATHVARIABLE',
// all path variables defined in this path. acc. to the spec, all path params are required
schemaPathVariables,
schemaPathVar;
@@ -1870,6 +1868,8 @@ module.exports = {
});
async.map(determinedPathVariables, (pathVar, cb) => {
let mismatches = [];
schemaPathVar = _.find(schemaPathVariables, (param) => {
return param.name === pathVar.key;
});
@@ -1902,6 +1902,8 @@ module.exports = {
components, options, cb);
}, 0);
}, (err, res) => {
let mismatches = [];
if (err) {
return callback(err);
}
@@ -1929,8 +1931,7 @@ module.exports = {
schemaParams = _.filter(schemaPath.parameters, (param) => { return param.in === 'query'; }),
requestQueryArray = [],
requestQueryParams = [],
mismatchProperty = 'QUERYPARAM',
mismatches = [];
mismatchProperty = 'QUERYPARAM';
if (options.validationPropertiesToIgnore.includes(mismatchProperty)) {
return callback(null, []);
@@ -1956,6 +1957,7 @@ module.exports = {
});
return async.map(requestQueryParams, (pQuery, cb) => {
let mismatches = [];
const schemaParam = _.find(schemaParams, (param) => { return param.name === pQuery.key; });
if (!schemaParam) {
@@ -1988,6 +1990,7 @@ module.exports = {
);
}, 0);
}, (err, res) => {
let mismatches = [];
_.each(_.filter(schemaParams, (q) => { return q.required; }), (qp) => {
if (!_.find(requestQueryParams, (param) => { return param.key === qp.name; })) {
mismatches.push({
@@ -2005,8 +2008,7 @@ module.exports = {
checkRequestHeaders: function (headers, transactionPathPrefix, schemaPath, components, options, callback) {
let schemaHeaders = _.filter(schemaPath.parameters, (param) => { return param.in === 'header'; }),
mismatchProperty = 'HEADER',
mismatches = [];
mismatchProperty = 'HEADER';
if (options.validationPropertiesToIgnore.includes(mismatchProperty)) {
return callback(null, []);
@@ -2014,6 +2016,7 @@ module.exports = {
// 1. for each header, find relevant schemaPath property
return async.map(headers, (pHeader, cb) => {
let mismatches = [];
const schemaHeader = _.find(schemaHeaders, (header) => { return header.name === pHeader.key; });
if (!schemaHeader) {
@@ -2027,7 +2030,7 @@ module.exports = {
reason: `The header ${pHeader.key} was not found in the schema`
});
}
return cb(null, []);
return cb(null, mismatches);
}
// header found in spec. check header's schema
@@ -2046,6 +2049,7 @@ module.exports = {
);
}, 0);
}, (err, res) => {
let mismatches = [];
_.each(_.filter(schemaHeaders, (h) => { return h.required; }), (header) => {
if (!_.find(headers, (param) => { return param.key === header.name; })) {
mismatches.push({
@@ -2065,8 +2069,7 @@ module.exports = {
components, options, callback) {
// 0. Need to find relevant response from schemaPath.responses
let schemaHeaders,
mismatchProperty = 'RESPONSE_HEADER',
mismatches = [];
mismatchProperty = 'RESPONSE_HEADER';
if (options.validationPropertiesToIgnore.includes(mismatchProperty)) {
return callback(null, []);
@@ -2081,6 +2084,7 @@ module.exports = {
schemaHeaders = schemaResponse.headers;
return async.map(headers, (pHeader, cb) => {
let mismatches = [];
const schemaHeader = schemaHeaders[pHeader.key];
if (!schemaHeader) {
@@ -2114,6 +2118,7 @@ module.exports = {
);
}, 0);
}, (err, res) => {
let mismatches = [];
_.each(_.filter(schemaHeaders, (h, hName) => {
h.name = hName;
return h.required;