Merge branch 'develop' of github.com:postmanlabs/openapi-to-postman into fix496/validateWithServers

This commit is contained in:
Vishal Shingala
2022-07-19 19:07:20 +05:30
16 changed files with 1795 additions and 51 deletions

View File

@@ -3333,7 +3333,7 @@ module.exports = {
/**
*
* @param {*} determinedPathVariables the key/determined-value pairs of the path variables (from Postman)
* @param {*} matchedPathData the matchedPath data
* @param {*} transactionPathPrefix the jsonpath for this validation (will be prepended to all identified mismatches)
* @param {*} schemaPath the applicable pathItem defined at the schema level
* @param {*} components the components + paths from the OAS spec that need to be used to resolve $refs
@@ -3344,7 +3344,7 @@ module.exports = {
* @returns {array} mismatches (in the callback)
*/
checkPathVariables: function (
determinedPathVariables,
matchedPathData,
transactionPathPrefix,
schemaPath,
components,
@@ -3358,7 +3358,9 @@ module.exports = {
var mismatchProperty = 'PATHVARIABLE',
// all path variables defined in this path. acc. to the spec, all path params are required
schemaPathVariables,
pmPathVariables;
pmPathVariables,
determinedPathVariables = matchedPathData.pathVariables,
unmatchedVariablesFromTransaction = matchedPathData.unmatchedVariablesFromTransaction;
if (options.validationPropertiesToIgnore.includes(mismatchProperty)) {
return callback(null, []);
@@ -3424,17 +3426,41 @@ module.exports = {
}, (err, res) => {
let mismatches = [],
mismatchObj;
const unmatchedSchemaVariableNames = determinedPathVariables.filter((pathVariable) => {
return !pathVariable._varMatched;
}).map((schemaPathVar) => {
return schemaPathVar.key;
});
if (err) {
return callback(err);
}
// go through required schemaPathVariables, and params that aren't found in the given transaction are errors
_.each(schemaPathVariables, (pathVar) => {
_.each(schemaPathVariables, (pathVar, index) => {
if (!_.find(determinedPathVariables, (param) => {
// only consider variable matching if url path variables is not allowed
return param.key === pathVar.name && (options.allowUrlPathVarMatching || param._varMatched);
})) {
let reasonCode = 'MISSING_IN_REQUEST',
reason,
actualValue,
currentUnmatchedVariableInTransaction = unmatchedVariablesFromTransaction[index],
isInvalidValue = currentUnmatchedVariableInTransaction !== undefined;
if (unmatchedSchemaVariableNames.length > 0 && isInvalidValue) {
reason = `The ${currentUnmatchedVariableInTransaction.key} path variable does not match with ` +
`path variable expected (${unmatchedSchemaVariableNames[index]}) in the schema at this position`;
actualValue = {
key: currentUnmatchedVariableInTransaction.key,
description: this.getParameterDescription(currentUnmatchedVariableInTransaction),
value: currentUnmatchedVariableInTransaction.value
};
}
else {
reason = `The required path variable "${pathVar.name}" was not found in the transaction`;
actualValue = null;
}
// assign parameter example(s) as schema examples;
this.assignParameterExamples(pathVar);
@@ -3443,14 +3469,14 @@ module.exports = {
property: mismatchProperty,
transactionJsonPath: transactionPathPrefix,
schemaJsonPath: pathVar.pathPrefix,
reasonCode: 'MISSING_IN_REQUEST',
reason: `The required path variable "${pathVar.name}" was not found in the transaction`
reasonCode,
reason
};
if (options.suggestAvailableFixes) {
mismatchObj.suggestedFix = {
key: pathVar.name,
actualValue: null,
actualValue,
suggestedValue: {
key: pathVar.name,
value: safeSchemaFaker(pathVar.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,