mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Merge branch 'develop' of github.com:postmanlabs/openapi-to-postman into fix496/validateWithServers
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user