From 6f5fc3173b032f51319a1f4b5237c6e1e16e93f5 Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Fri, 18 Feb 2022 20:54:03 -0600 Subject: [PATCH 01/11] Set new mismatch reason and reasonCode in path validation when path variables from transaction does not match with path variables in schema, Adding the same scenario when there are local servers in validating path --- lib/schemaUtils.js | 32 ++- lib/schemapack.js | 29 ++- .../issues/issue#478/issueCollection.json | 146 +++++++++++++ .../issues/issue#478/issueSpec.yaml | 65 ++++++ ...cal-servers-path-variables-collection.json | 195 ++++++++++++++++++ .../local-servers-path-variables-spec.yaml | 80 +++++++ test/unit/x30schemapack.test.js | 69 +++++++ 7 files changed, 607 insertions(+), 9 deletions(-) create mode 100644 test/data/validationData/issues/issue#478/issueCollection.json create mode 100644 test/data/validationData/issues/issue#478/issueSpec.yaml create mode 100644 test/data/validationData/issues/issue#478/local-servers-path-variables-collection.json create mode 100644 test/data/validationData/issues/issue#478/local-servers-path-variables-spec.yaml create mode 100644 test/unit/x30schemapack.test.js diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 220710d..a7bd5ea 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -3311,7 +3311,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 @@ -3322,7 +3322,7 @@ module.exports = { * @returns {array} mismatches (in the callback) */ checkPathVariables: function ( - determinedPathVariables, + matchedPathData, transactionPathPrefix, schemaPath, components, @@ -3336,7 +3336,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, []); @@ -3376,6 +3378,7 @@ module.exports = { // don't validate variable if not present in transaction and URL path vars are not allowed if (!pathVar._varMatched && !options.allowUrlPathVarMatching) { return cb(null, mismatches); + // return cb(null, mismatches).bind(null, mismatches, { unmatchedVariablesFromTransaction }); } // assign parameter example(s) as schema examples @@ -3414,6 +3417,25 @@ module.exports = { return param.key === pathVar.name && (options.allowUrlPathVarMatching || param._varMatched); })) { + const unmatchedSchemaVariables = _.filter(determinedPathVariables, (pathVariable) => { + return !pathVariable._varMatched; + }), + unmatchedSchemaVariableNames = _.map(unmatchedSchemaVariables, (schemaVariable) => { + return schemaVariable.key; + }); + let reasonCode, + reason; + + if (unmatchedSchemaVariableNames.length > 0 && unmatchedVariablesFromTransaction.length > 0) { + reasonCode = 'INVALID_VALUE'; + reason = `Some provided path variables in transaction (${unmatchedVariablesFromTransaction.join(',')})` + + ` does not match with path variables expected in schema (${unmatchedSchemaVariableNames.join(',')})`; + } + else { + reasonCode = 'MISSING_IN_REQUEST'; + reason = `The required path variable "${pathVar.name}" was not found in the transaction`; + } + // assign parameter example(s) as schema examples; this.assignParameterExamples(pathVar); @@ -3421,8 +3443,8 @@ 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) { diff --git a/lib/schemapack.js b/lib/schemapack.js index c4227a3..be97aab 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -472,12 +472,33 @@ class SchemaPack { return setTimeout(() => { // 2. perform validation for each identified matchedPath (schema endpoint) return async.map(matchedPaths, (matchedPath, pathsCallback) => { - + const transactionPathVariables = _.get(transaction, 'request.url.variable', []), + getLocalServersPathVars = () => { + return matchedPath.path.servers.reduce((acc, current) => { + let newVarNames = current.hasOwnProperty('variables') ? + Object.keys(current.variables).filter((varName) => { + return !acc.includes(varName); + }) : + []; + return [...acc, ...newVarNames]; + }, []); + }, + localServersPathVars = matchedPath.path.hasOwnProperty('servers') ? + getLocalServersPathVars() : + [], + isNotALocalServerPathVar = (pathVarName) => { + return !localServersPathVars.includes(pathVarName); + }; + matchedPath.unmatchedVariablesFromTransaction = []; // override path variable value with actual value present in transaction // as matched pathvariable contains key as value, as it is generated from url only _.forEach(matchedPath.pathVariables, (pathVar) => { - let mappedPathVar = _.find(_.get(transaction, 'request.url.variable', []), (transactionPathVar) => { - return transactionPathVar.key === pathVar.key; + let mappedPathVar = _.find(transactionPathVariables, (transactionPathVar) => { + let matched = transactionPathVar.key === pathVar.key; + if (!matched && isNotALocalServerPathVar(transactionPathVar.key)) { + matchedPath.unmatchedVariablesFromTransaction.push(transactionPathVar.key); + } + return matched; }); pathVar.value = _.get(mappedPathVar, 'value', pathVar.value); // set _varMatched flag which represents if variable was found in transaction or not @@ -499,7 +520,7 @@ class SchemaPack { schemaUtils.checkMetadata(transaction, '$', matchedPath.path, matchedPath.name, options, cb); }, path: function(cb) { - schemaUtils.checkPathVariables(matchedPath.pathVariables, '$.request.url.variable', matchedPath.path, + schemaUtils.checkPathVariables(matchedPath, '$.request.url.variable', matchedPath.path, componentsAndPaths, options, schemaCache, jsonSchemaDialect, cb); }, queryparams: function(cb) { diff --git a/test/data/validationData/issues/issue#478/issueCollection.json b/test/data/validationData/issues/issue#478/issueCollection.json new file mode 100644 index 0000000..a0cb8c2 --- /dev/null +++ b/test/data/validationData/issues/issue#478/issueCollection.json @@ -0,0 +1,146 @@ +{ + "item": [ + { + "id": "6e5b8ef6-6d5c-4e02-9f04-e26cb8b7b16e", + "name": "pets", + "description": { + "content": "", + "type": "text/plain" + }, + "item": [ + { + "id": "79c48c16-3de3-49ab-a92b-e86034a85ea8", + "name": "Info for a specific pet", + "request": { + "name": "Info for a specific pet", + "description": {}, + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "disabled": false, + "type": "any", + "value": "eu consectetur", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "header": [ + { + "key": "Accept", + "value": "application/json" + } + ], + "method": "GET", + "auth": null + }, + "response": [ + { + "id": "897e412c-6070-4bb4-bdcd-ee21fe96af8e", + "name": "Expected response to a valid request", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "disabled": false, + "type": "any", + "value": "eu consectetur", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "OK", + "code": 200, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"id\": -29008976,\n \"name\": \"laborum nostrud\",\n \"tag\": \"et veni\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + }, + { + "id": "64c06a83-0235-47c3-b59a-d715a4fb0813", + "name": "unexpected error", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "disabled": false, + "type": "any", + "value": "eu consectetur", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "Internal Server Error", + "code": 500, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"code\": -96155831,\n \"message\": \"ex consectetur commodo\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + } + ], + "event": [] + } + ], + "event": [] + } + ], + "event": [], + "variable": [ + { + "type": "string", + "value": "http://petstore.swagger.io/v1", + "key": "baseUrl" + } + ], + "info": { + "_postman_id": "4cf22e75-4c05-4d03-85a8-4eca00651300", + "name": "Swagger Petstore", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "description": { + "content": "", + "type": "text/plain" + } + } +} \ No newline at end of file diff --git a/test/data/validationData/issues/issue#478/issueSpec.yaml b/test/data/validationData/issues/issue#478/issueSpec.yaml new file mode 100644 index 0000000..7d45f84 --- /dev/null +++ b/test/data/validationData/issues/issue#478/issueSpec.yaml @@ -0,0 +1,65 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +servers: + - url: http://petstore.swagger.io/v1 +paths: + /pets/{peterId}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: peterId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + responses: + '200': + description: Expected response to a valid request + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string \ No newline at end of file diff --git a/test/data/validationData/issues/issue#478/local-servers-path-variables-collection.json b/test/data/validationData/issues/issue#478/local-servers-path-variables-collection.json new file mode 100644 index 0000000..c257207 --- /dev/null +++ b/test/data/validationData/issues/issue#478/local-servers-path-variables-collection.json @@ -0,0 +1,195 @@ +{ + "item": [ + { + "id": "37bb14ea-6f8b-4aed-ba84-65dba00f2866", + "name": "Info for a specific pet", + "request": { + "name": "Info for a specific pet", + "description": {}, + "url": { + "protocol": "https", + "port": "{{port}}", + "path": [ + ":basePath", + "pets", + ":petId" + ], + "host": [ + "{{username}}", + "myTestServer", + "com" + ], + "query": [], + "variable": [ + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "v2", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "header": [ + { + "key": "Accept", + "value": "application/json" + } + ], + "method": "GET", + "auth": null + }, + "response": [ + { + "id": "788af746-16c3-45aa-a06e-e438c72199ba", + "name": "Expected response to a valid request", + "originalRequest": { + "url": { + "protocol": "https", + "port": "{{port}}", + "path": [ + ":basePath", + "pets", + ":petId" + ], + "host": [ + "{{username}}", + "myTestServer", + "com" + ], + "query": [], + "variable": [ + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "v2", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "OK", + "code": 200, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"id\": -3764386,\n \"name\": \"minim nulla aliqua fugiat\",\n \"tag\": \"ex commodo irure\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + }, + { + "id": "39776355-ccef-4e5b-921c-98ef03af5b71", + "name": "unexpected error", + "originalRequest": { + "url": { + "protocol": "https", + "port": "{{port}}", + "path": [ + ":basePath", + "pets", + ":petId" + ], + "host": [ + "{{username}}", + "myTestServer", + "com" + ], + "query": [], + "variable": [ + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "v2", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "Internal Server Error", + "code": 500, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"code\": 77941721,\n \"message\": \"deserunt eu quis\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + } + ], + "event": [] + } + ], + "event": [], + "variable": [ + { + "type": "string", + "value": "http://petstore.swagger.io/v1", + "key": "baseUrl" + }, + { + "description": { + "content": "Assigned by the service provider", + "type": "text/plain" + }, + "type": "any", + "value": "demo", + "key": "username" + }, + { + "description": { + "content": " (This can only be one of 8843,443)", + "type": "text/plain" + }, + "type": "any", + "value": "8843", + "key": "port" + } + ], + "info": { + "_postman_id": "e1ba04ca-04d6-4993-bfd5-47b17c7e5f29", + "name": "Swagger Petstore", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "description": { + "content": "", + "type": "text/plain" + } + } +} \ No newline at end of file diff --git a/test/data/validationData/issues/issue#478/local-servers-path-variables-spec.yaml b/test/data/validationData/issues/issue#478/local-servers-path-variables-spec.yaml new file mode 100644 index 0000000..0ac4de3 --- /dev/null +++ b/test/data/validationData/issues/issue#478/local-servers-path-variables-spec.yaml @@ -0,0 +1,80 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +servers: + - url: http://petstore.swagger.io/v1 +paths: + /pets/{peterId}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: peterId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + responses: + '200': + description: Expected response to a valid request + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + servers: + - url: https://{username}.myTestServer.com:{port}/{basePath} + description: Common url for all operations in this path + variables: + username: + default: demo + description: Assigned by the service provider + port: + enum: + - '8843' + - '443' + + default: '8843' + basePath: + default: v2 +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string \ No newline at end of file diff --git a/test/unit/x30schemapack.test.js b/test/unit/x30schemapack.test.js new file mode 100644 index 0000000..56543c5 --- /dev/null +++ b/test/unit/x30schemapack.test.js @@ -0,0 +1,69 @@ +const expect = require('chai').expect, + Converter = require('../../index.js'), + fs = require('fs'), + path = require('path'), + _ = require('lodash'), + VALIDATION_DATA_FOLDER_PATH = '../data/validationData'; + +function getAllTransactions (collection, allRequests) { + if (!_.has(collection, 'item') || !_.isArray(collection.item)) { + return; + } + _.forEach(collection.item, (item) => { + if (_.has(item, 'request') || _.has(item, 'response')) { + allRequests.push(item); + } + else { + getAllTransactions(item, allRequests); + } + }); +} + +describe('validateTransaction method', function() { + it('Should validate correctly while a path param in spec does not matches with collection' + + ' (issue#478)', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/issueSpec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/issueCollection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(1); + done(); + }); + }); + + it('Should validate correctly when a path param in spec does not matches with collection ' + + 'and there are path variables in servers object (issue#478)', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/local-servers-path-variables-spec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/local-servers-path-variables-collection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(1); + expect(resultObj.mismatches[0].reason).to.equal( + 'Some provided path variables in transaction (petId) does not' + + ' match with path variables expected in schema (peterId)' + ); + expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + done(); + }); + }); +}); From 4b3555a97f7c21ae63444bc93de857fa557e6f37 Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Fri, 18 Feb 2022 21:44:00 -0600 Subject: [PATCH 02/11] Adding invalid value scenario in path variables validation when there are path variables in global servers --- lib/schemaUtils.js | 1 - lib/schemapack.js | 13 +- ...bal-servers-path-variables-collection.json | 225 ++++++++++++++++++ .../global-servers-path-variables-spec.yaml | 78 ++++++ test/unit/x30schemapack.test.js | 28 ++- 5 files changed, 337 insertions(+), 8 deletions(-) create mode 100644 test/data/validationData/issues/issue#478/global-servers-path-variables-collection.json create mode 100644 test/data/validationData/issues/issue#478/global-servers-path-variables-spec.yaml diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index a7bd5ea..ad4c10b 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -3378,7 +3378,6 @@ module.exports = { // don't validate variable if not present in transaction and URL path vars are not allowed if (!pathVar._varMatched && !options.allowUrlPathVarMatching) { return cb(null, mismatches); - // return cb(null, mismatches).bind(null, mismatches, { unmatchedVariablesFromTransaction }); } // assign parameter example(s) as schema examples diff --git a/lib/schemapack.js b/lib/schemapack.js index be97aab..25d5d6f 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -473,8 +473,11 @@ class SchemaPack { // 2. perform validation for each identified matchedPath (schema endpoint) return async.map(matchedPaths, (matchedPath, pathsCallback) => { const transactionPathVariables = _.get(transaction, 'request.url.variable', []), - getLocalServersPathVars = () => { - return matchedPath.path.servers.reduce((acc, current) => { + localServers = matchedPath.path.hasOwnProperty('servers') ? + matchedPath.path.servers : + [], + getServersPathVars = (servers) => { + return servers.reduce((acc, current) => { let newVarNames = current.hasOwnProperty('variables') ? Object.keys(current.variables).filter((varName) => { return !acc.includes(varName); @@ -483,11 +486,9 @@ class SchemaPack { return [...acc, ...newVarNames]; }, []); }, - localServersPathVars = matchedPath.path.hasOwnProperty('servers') ? - getLocalServersPathVars() : - [], + serversPathVars = [...getServersPathVars(localServers), ...getServersPathVars(schema.servers)], isNotALocalServerPathVar = (pathVarName) => { - return !localServersPathVars.includes(pathVarName); + return !serversPathVars.includes(pathVarName); }; matchedPath.unmatchedVariablesFromTransaction = []; // override path variable value with actual value present in transaction diff --git a/test/data/validationData/issues/issue#478/global-servers-path-variables-collection.json b/test/data/validationData/issues/issue#478/global-servers-path-variables-collection.json new file mode 100644 index 0000000..ba4cdf9 --- /dev/null +++ b/test/data/validationData/issues/issue#478/global-servers-path-variables-collection.json @@ -0,0 +1,225 @@ +{ + "item": [ + { + "id": "1c9e80af-cc42-47c7-beae-f4b78e1bd3e1", + "name": "Info for a specific pet", + "request": { + "name": "Info for a specific pet", + "description": {}, + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "header": [ + { + "key": "Accept", + "value": "application/json" + } + ], + "method": "GET", + "auth": null + }, + "response": [ + { + "id": "291f119a-d162-4676-83c0-91ce6595407b", + "name": "Expected response to a valid request", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "OK", + "code": 200, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"id\": -74238905,\n \"name\": \"et aliqua officia\",\n \"tag\": \"qui do\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + }, + { + "id": "c00295c6-c859-46a4-8aae-8e2a6a2f64f3", + "name": "unexpected error", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "Internal Server Error", + "code": 500, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"code\": -79318973,\n \"message\": \"ex c\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + } + ], + "event": [] + } + ], + "event": [], + "variable": [ + { + "description": { + "content": "Assigned by the service provider", + "type": "text/plain" + }, + "type": "any", + "value": "demo", + "key": "username" + }, + { + "description": { + "content": " (This can only be one of 8843,443)", + "type": "text/plain" + }, + "type": "any", + "value": "8843", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "v2", + "key": "basePath" + }, + { + "type": "string", + "value": "https://{{username}}.myTestServer.com:{{port}}/{{basePath}}", + "key": "baseUrl" + } + ], + "info": { + "_postman_id": "a1d9a3d3-6195-46b3-95ff-016edd9b283d", + "name": "Swagger Petstore", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "description": { + "content": "", + "type": "text/plain" + } + } +} \ No newline at end of file diff --git a/test/data/validationData/issues/issue#478/global-servers-path-variables-spec.yaml b/test/data/validationData/issues/issue#478/global-servers-path-variables-spec.yaml new file mode 100644 index 0000000..7311261 --- /dev/null +++ b/test/data/validationData/issues/issue#478/global-servers-path-variables-spec.yaml @@ -0,0 +1,78 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +servers: + - url: https://{username}.myTestServer.com:{port}/{basePath} + description: Common url for all operations in this path + variables: + username: + default: demo + description: Assigned by the service provider + port: + enum: + - '8843' + - '443' + + default: '8843' + basePath: + default: v2 +paths: + /pets/{peterId}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: peterId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + responses: + '200': + description: Expected response to a valid request + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string \ No newline at end of file diff --git a/test/unit/x30schemapack.test.js b/test/unit/x30schemapack.test.js index 56543c5..a425bfc 100644 --- a/test/unit/x30schemapack.test.js +++ b/test/unit/x30schemapack.test.js @@ -42,7 +42,7 @@ describe('validateTransaction method', function() { }); it('Should validate correctly when a path param in spec does not matches with collection ' + - 'and there are path variables in servers object (issue#478)', function(done) { + 'and there are path variables in local servers object (issue#478)', function(done) { let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), issueSpec = fs.readFileSync(issueFolder + '/local-servers-path-variables-spec.yaml', 'utf-8'), issueCollection = fs.readFileSync(issueFolder + '/local-servers-path-variables-collection.json', 'utf-8'), @@ -66,4 +66,30 @@ describe('validateTransaction method', function() { done(); }); }); + + it('Should validate correctly when a path param in spec does not matches with collection ' + + 'and there are path variables in global servers object (issue#478)', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/global-servers-path-variables-spec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/global-servers-path-variables-collection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(1); + expect(resultObj.mismatches[0].reason).to.equal( + 'Some provided path variables in transaction (petId) does not' + + ' match with path variables expected in schema (peterId)' + ); + expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + done(); + }); + }); }); From 44c4d2ed54de6ba79d16758fb6bd4c52d89a8e40 Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Thu, 24 Feb 2022 20:51:55 -0600 Subject: [PATCH 03/11] Fixing issue #478, path variables matching validation The path variables provided in transactions will be validated with the path variables in spec. If they does not match it will be generated a mismatch with INVALID_VALUE reasonCode. --- lib/schemaUtils.js | 29 ++- lib/schemapack.js | 6 +- ...ables-two-vars-missing-one-collection.json | 225 +++++++++++++++++ ...h-variables-two-vars-missing-one-spec.yaml | 84 +++++++ ...h-variables-two-vars-wrong-collection.json | 233 ++++++++++++++++++ ...rs-path-variables-two-vars-wrong-spec.yaml | 84 +++++++ test/unit/validator.test.js | 230 +++++++++++++++++ 7 files changed, 877 insertions(+), 14 deletions(-) create mode 100644 test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-collection.json create mode 100644 test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-spec.yaml create mode 100644 test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-collection.json create mode 100644 test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-spec.yaml diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index ad4c10b..b0e6f0f 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -3404,35 +3404,38 @@ 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); })) { - - const unmatchedSchemaVariables = _.filter(determinedPathVariables, (pathVariable) => { - return !pathVariable._varMatched; - }), - unmatchedSchemaVariableNames = _.map(unmatchedSchemaVariables, (schemaVariable) => { - return schemaVariable.key; - }); let reasonCode, - reason; + reason, + key, + currentUnmatchedVariableInTransaction = unmatchedVariablesFromTransaction[index], + isInvalidValue = currentUnmatchedVariableInTransaction !== undefined; - if (unmatchedSchemaVariableNames.length > 0 && unmatchedVariablesFromTransaction.length > 0) { + if (unmatchedSchemaVariableNames.length > 0 && isInvalidValue) { reasonCode = 'INVALID_VALUE'; - reason = `Some provided path variables in transaction (${unmatchedVariablesFromTransaction.join(',')})` + - ` does not match with path variables expected in schema (${unmatchedSchemaVariableNames.join(',')})`; + reason = `The ${currentUnmatchedVariableInTransaction} path variable does not match with path variable` + + ` expected in in schema at this position (${unmatchedSchemaVariableNames[index]})`; + key = currentUnmatchedVariableInTransaction; } else { reasonCode = 'MISSING_IN_REQUEST'; reason = `The required path variable "${pathVar.name}" was not found in the transaction`; + key = null; } // assign parameter example(s) as schema examples; @@ -3449,7 +3452,7 @@ module.exports = { if (options.suggestAvailableFixes) { mismatchObj.suggestedFix = { key: pathVar.name, - actualValue: null, + actualValue: key, suggestedValue: { key: pathVar.name, value: safeSchemaFaker(pathVar.schema || {}, 'example', PROCESSING_TYPE.VALIDATION, diff --git a/lib/schemapack.js b/lib/schemapack.js index 25d5d6f..e62977f 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -496,7 +496,11 @@ class SchemaPack { _.forEach(matchedPath.pathVariables, (pathVar) => { let mappedPathVar = _.find(transactionPathVariables, (transactionPathVar) => { let matched = transactionPathVar.key === pathVar.key; - if (!matched && isNotALocalServerPathVar(transactionPathVar.key)) { + if ( + !matched && + isNotALocalServerPathVar(transactionPathVar.key) && + !matchedPath.unmatchedVariablesFromTransaction.includes(transactionPathVar.key) + ) { matchedPath.unmatchedVariablesFromTransaction.push(transactionPathVar.key); } return matched; diff --git a/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-collection.json b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-collection.json new file mode 100644 index 0000000..aa97e95 --- /dev/null +++ b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-collection.json @@ -0,0 +1,225 @@ +{ + "item": [ + { + "id": "1c9e80af-cc42-47c7-beae-f4b78e1bd3e1", + "name": "Info for a specific pet", + "request": { + "name": "Info for a specific pet", + "description": {}, + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) A test id" + } + ] + }, + "header": [ + { + "key": "Accept", + "value": "application/json" + } + ], + "method": "GET", + "auth": null + }, + "response": [ + { + "id": "291f119a-d162-4676-83c0-91ce6595407b", + "name": "Expected response to a valid request", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "OK", + "code": 200, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"id\": -74238905,\n \"name\": \"et aliqua officia\",\n \"tag\": \"qui do\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + }, + { + "id": "c00295c6-c859-46a4-8aae-8e2a6a2f64f3", + "name": "unexpected error", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "Internal Server Error", + "code": 500, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"code\": -79318973,\n \"message\": \"ex c\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + } + ], + "event": [] + } + ], + "event": [], + "variable": [ + { + "description": { + "content": "Assigned by the service provider", + "type": "text/plain" + }, + "type": "any", + "value": "demo", + "key": "username" + }, + { + "description": { + "content": " (This can only be one of 8843,443)", + "type": "text/plain" + }, + "type": "any", + "value": "8843", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "v2", + "key": "basePath" + }, + { + "type": "string", + "value": "https://{{username}}.myTestServer.com:{{port}}/{{basePath}}", + "key": "baseUrl" + } + ], + "info": { + "_postman_id": "a1d9a3d3-6195-46b3-95ff-016edd9b283d", + "name": "Swagger Petstore", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "description": { + "content": "", + "type": "text/plain" + } + } +} \ No newline at end of file diff --git a/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-spec.yaml b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-spec.yaml new file mode 100644 index 0000000..17b1bfb --- /dev/null +++ b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-missing-one-spec.yaml @@ -0,0 +1,84 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +servers: + - url: https://{username}.myTestServer.com:{port}/{basePath} + description: Common url for all operations in this path + variables: + username: + default: demo + description: Assigned by the service provider + port: + enum: + - '8843' + - '443' + + default: '8843' + basePath: + default: v2 +paths: + /pets/{peterId}/{correctName}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: peterId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + - name: correctName + in: path + required: true + description: A test id + schema: + type: string + responses: + '200': + description: Expected response to a valid request + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string \ No newline at end of file diff --git a/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-collection.json b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-collection.json new file mode 100644 index 0000000..e5a4d83 --- /dev/null +++ b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-collection.json @@ -0,0 +1,233 @@ +{ + "item": [ + { + "id": "1c9e80af-cc42-47c7-beae-f4b78e1bd3e1", + "name": "Info for a specific pet", + "request": { + "name": "Info for a specific pet", + "description": {}, + "url": { + "path": [ + "pets", + ":petId", + "wrongNamedId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) A test id" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "wrongNamedId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "header": [ + { + "key": "Accept", + "value": "application/json" + } + ], + "method": "GET", + "auth": null + }, + "response": [ + { + "id": "291f119a-d162-4676-83c0-91ce6595407b", + "name": "Expected response to a valid request", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "OK", + "code": 200, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"id\": -74238905,\n \"name\": \"et aliqua officia\",\n \"tag\": \"qui do\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + }, + { + "id": "c00295c6-c859-46a4-8aae-8e2a6a2f64f3", + "name": "unexpected error", + "originalRequest": { + "url": { + "path": [ + "pets", + ":petId" + ], + "host": [ + "{{baseUrl}}" + ], + "query": [], + "variable": [ + { + "description": "Assigned by the service provider", + "type": "any", + "value": "{{username}}", + "key": "username" + }, + { + "description": " (This can only be one of 8843,443)", + "type": "any", + "value": "{{port}}", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "{{basePath}}", + "key": "basePath" + }, + { + "disabled": false, + "type": "any", + "value": "", + "key": "petId", + "description": "(Required) The id of the pet to retrieve" + } + ] + }, + "method": "GET", + "body": {} + }, + "status": "Internal Server Error", + "code": 500, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": "{\n \"code\": -79318973,\n \"message\": \"ex c\"\n}", + "cookie": [], + "_postman_previewlanguage": "json" + } + ], + "event": [] + } + ], + "event": [], + "variable": [ + { + "description": { + "content": "Assigned by the service provider", + "type": "text/plain" + }, + "type": "any", + "value": "demo", + "key": "username" + }, + { + "description": { + "content": " (This can only be one of 8843,443)", + "type": "text/plain" + }, + "type": "any", + "value": "8843", + "key": "port" + }, + { + "description": { + "content": "", + "type": "text/plain" + }, + "type": "any", + "value": "v2", + "key": "basePath" + }, + { + "type": "string", + "value": "https://{{username}}.myTestServer.com:{{port}}/{{basePath}}", + "key": "baseUrl" + } + ], + "info": { + "_postman_id": "a1d9a3d3-6195-46b3-95ff-016edd9b283d", + "name": "Swagger Petstore", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "description": { + "content": "", + "type": "text/plain" + } + } +} \ No newline at end of file diff --git a/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-spec.yaml b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-spec.yaml new file mode 100644 index 0000000..17b1bfb --- /dev/null +++ b/test/data/validationData/issues/issue#478/global-servers-path-variables-two-vars-wrong-spec.yaml @@ -0,0 +1,84 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +servers: + - url: https://{username}.myTestServer.com:{port}/{basePath} + description: Common url for all operations in this path + variables: + username: + default: demo + description: Assigned by the service provider + port: + enum: + - '8843' + - '443' + + default: '8843' + basePath: + default: v2 +paths: + /pets/{peterId}/{correctName}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: peterId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + - name: correctName + in: path + required: true + description: A test id + schema: + type: string + responses: + '200': + description: Expected response to a valid request + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string \ No newline at end of file diff --git a/test/unit/validator.test.js b/test/unit/validator.test.js index c1a6f45..a769f90 100644 --- a/test/unit/validator.test.js +++ b/test/unit/validator.test.js @@ -1308,3 +1308,233 @@ describe('VALIDATE FUNCTION TESTS ', function () { }); }); }); + +describe('validateTransaction method. Path variables matching validation (issue #478)', function() { + it('Should validate correctly while a path param in spec does not matches with collection' + + ' (issue#478)', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/issueSpec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/issueCollection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(1); + expect(resultObj.mismatches[0].reasonCode).to.be.equal('INVALID_VALUE'); + expect(resultObj.mismatches[0].reason).to.be.equal( + 'The petId path variable does not match with path variable' + + ' expected in in schema at this position (peterId)' + ); + done(); + }); + }); + + it('Should validate correctly while a path param in spec does not matches with collection' + + ' (issue#478), allowUrlPathVarMatching: true', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/issueSpec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/issueCollection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: true }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(0); + done(); + }); + }); + + it('Should validate correctly when a path param in spec does not matches with collection ' + + 'and there are path variables in local servers object (issue#478)', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/local-servers-path-variables-spec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/local-servers-path-variables-collection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(1); + expect(resultObj.mismatches[0].reason).to.equal( + 'The petId path variable does not match with path variable' + + ' expected in in schema at this position (peterId)' + ); + expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + done(); + }); + }); + + it('Should validate correctly when a path param in spec does not matches with collection ' + + 'and there are path variables in global servers object (issue#478)', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/global-servers-path-variables-spec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/global-servers-path-variables-collection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(1); + expect(resultObj.mismatches[0].reason).to.equal( + 'The petId path variable does not match with path variable' + + ' expected in in schema at this position (peterId)' + ); + expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + done(); + }); + }); + + it('Should validate correctly when a path param in spec does not matches with collection ' + + 'and there are path variables in global servers object (issue#478), suggestAvailableFixes: true', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync(issueFolder + '/global-servers-path-variables-spec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/global-servers-path-variables-collection.json', 'utf-8'), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack( + { type: 'string', data: issueSpec }, + { allowUrlPathVarMatching: false, suggestAvailableFixes: true }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(1); + expect(resultObj.mismatches[0].reason).to.equal( + 'The petId path variable does not match with path variable' + + ' expected in in schema at this position (peterId)' + ); + expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + done(); + }); + }); + + it('Should validate correctly when two path params in spec does not matches with collection ' + + 'and there are path variables in global servers object (issue#478), suggestAvailableFixes: true', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync( + issueFolder + '/global-servers-path-variables-two-vars-wrong-spec.yaml', 'utf-8' + ), + issueCollection = fs.readFileSync( + issueFolder + '/global-servers-path-variables-two-vars-wrong-collection.json', 'utf-8' + ), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack( + { type: 'string', data: issueSpec }, + { allowUrlPathVarMatching: false, suggestAvailableFixes: true }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(2); + expect(resultObj.mismatches[0].reason).to.equal( + 'The petId path variable does not match with path variable' + + ' expected in in schema at this position (peterId)' + ); + expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[1].reason).to.equal( + 'The wrongNamedId path variable does not match with path ' + + 'variable expected in in schema at this position (correctName)' + ); + expect(resultObj.mismatches[1].reasonCode).to.equal('INVALID_VALUE'); + done(); + }); + }); + + it('Should validate correctly when one path param in spec does not matches with collection ' + + ', global servers and one path var is not provided (issue#478), suggestAvailableFixes: true', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync( + issueFolder + '/global-servers-path-variables-two-vars-missing-one-spec.yaml', 'utf-8' + ), + issueCollection = fs.readFileSync( + issueFolder + '/global-servers-path-variables-two-vars-missing-one-collection.json', 'utf-8' + ), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack( + { type: 'string', data: issueSpec }, + { allowUrlPathVarMatching: false, suggestAvailableFixes: true }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(2); + expect(resultObj.mismatches[0].reason).to.equal( + 'The petId path variable does not match with path variable' + + ' expected in in schema at this position (peterId)' + ); + expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[1].reason).to.equal( + 'The required path variable "correctName" was not found in the transaction' + ); + expect(resultObj.mismatches[1].reasonCode).to.equal('MISSING_IN_REQUEST'); + done(); + }); + }); + + it('Should validate correctly when one path param in spec does not matches with collection ' + + ', global servers and one path var is not provided (issue#478), ' + + 'suggestAvailableFixes: true, allowUrlPathVarMatching: true', function(done) { + let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), + issueSpec = fs.readFileSync( + issueFolder + '/global-servers-path-variables-two-vars-missing-one-spec.yaml', 'utf-8' + ), + issueCollection = fs.readFileSync( + issueFolder + '/global-servers-path-variables-two-vars-missing-one-collection.json', 'utf-8' + ), + resultObj, + historyRequest = [], + schemaPack = new Converter.SchemaPack( + { type: 'string', data: issueSpec }, + { allowUrlPathVarMatching: true, suggestAvailableFixes: true }); + + getAllTransactions(JSON.parse(issueCollection), historyRequest); + + schemaPack.validateTransaction(historyRequest, (err, result) => { + // Schema is sample petsore with one of parameter as empty, expect no mismatch / error + expect(err).to.be.null; + expect(result).to.be.an('object'); + resultObj = result.requests[historyRequest[0].id].endpoints[0]; + expect(resultObj.mismatches).to.have.length(0); + done(); + }); + }); +}); From 423ee6521e770ba5271ca030d083546a90fdcc20 Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Thu, 24 Feb 2022 21:09:40 -0600 Subject: [PATCH 04/11] deleting tests that were moved to validator.test.js --- test/unit/x30schemapack.test.js | 95 --------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 test/unit/x30schemapack.test.js diff --git a/test/unit/x30schemapack.test.js b/test/unit/x30schemapack.test.js deleted file mode 100644 index a425bfc..0000000 --- a/test/unit/x30schemapack.test.js +++ /dev/null @@ -1,95 +0,0 @@ -const expect = require('chai').expect, - Converter = require('../../index.js'), - fs = require('fs'), - path = require('path'), - _ = require('lodash'), - VALIDATION_DATA_FOLDER_PATH = '../data/validationData'; - -function getAllTransactions (collection, allRequests) { - if (!_.has(collection, 'item') || !_.isArray(collection.item)) { - return; - } - _.forEach(collection.item, (item) => { - if (_.has(item, 'request') || _.has(item, 'response')) { - allRequests.push(item); - } - else { - getAllTransactions(item, allRequests); - } - }); -} - -describe('validateTransaction method', function() { - it('Should validate correctly while a path param in spec does not matches with collection' + - ' (issue#478)', function(done) { - let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), - issueSpec = fs.readFileSync(issueFolder + '/issueSpec.yaml', 'utf-8'), - issueCollection = fs.readFileSync(issueFolder + '/issueCollection.json', 'utf-8'), - resultObj, - historyRequest = [], - schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); - - getAllTransactions(JSON.parse(issueCollection), historyRequest); - - schemaPack.validateTransaction(historyRequest, (err, result) => { - // Schema is sample petsore with one of parameter as empty, expect no mismatch / error - expect(err).to.be.null; - expect(result).to.be.an('object'); - resultObj = result.requests[historyRequest[0].id].endpoints[0]; - expect(resultObj.mismatches).to.have.length(1); - done(); - }); - }); - - it('Should validate correctly when a path param in spec does not matches with collection ' + - 'and there are path variables in local servers object (issue#478)', function(done) { - let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), - issueSpec = fs.readFileSync(issueFolder + '/local-servers-path-variables-spec.yaml', 'utf-8'), - issueCollection = fs.readFileSync(issueFolder + '/local-servers-path-variables-collection.json', 'utf-8'), - resultObj, - historyRequest = [], - schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); - - getAllTransactions(JSON.parse(issueCollection), historyRequest); - - schemaPack.validateTransaction(historyRequest, (err, result) => { - // Schema is sample petsore with one of parameter as empty, expect no mismatch / error - expect(err).to.be.null; - expect(result).to.be.an('object'); - resultObj = result.requests[historyRequest[0].id].endpoints[0]; - expect(resultObj.mismatches).to.have.length(1); - expect(resultObj.mismatches[0].reason).to.equal( - 'Some provided path variables in transaction (petId) does not' + - ' match with path variables expected in schema (peterId)' - ); - expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); - done(); - }); - }); - - it('Should validate correctly when a path param in spec does not matches with collection ' + - 'and there are path variables in global servers object (issue#478)', function(done) { - let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), - issueSpec = fs.readFileSync(issueFolder + '/global-servers-path-variables-spec.yaml', 'utf-8'), - issueCollection = fs.readFileSync(issueFolder + '/global-servers-path-variables-collection.json', 'utf-8'), - resultObj, - historyRequest = [], - schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); - - getAllTransactions(JSON.parse(issueCollection), historyRequest); - - schemaPack.validateTransaction(historyRequest, (err, result) => { - // Schema is sample petsore with one of parameter as empty, expect no mismatch / error - expect(err).to.be.null; - expect(result).to.be.an('object'); - resultObj = result.requests[historyRequest[0].id].endpoints[0]; - expect(resultObj.mismatches).to.have.length(1); - expect(resultObj.mismatches[0].reason).to.equal( - 'Some provided path variables in transaction (petId) does not' + - ' match with path variables expected in schema (peterId)' - ); - expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); - done(); - }); - }); -}); From 7005ff538e2d876c9fd87f4635779121b8de91e6 Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Fri, 25 Feb 2022 14:28:57 -0600 Subject: [PATCH 05/11] Fix the naming and extracting function to commonUtils Renaming some variables and extracting a method to common utils --- lib/common/schemaUtilsCommon.js | 11 +++++++++++ lib/schemapack.js | 18 ++++-------------- ...th-variable-does-not-match-collection.json} | 0 ... => path-variable-does-not-match-spec.yaml} | 0 test/unit/validator.test.js | 8 ++++---- 5 files changed, 19 insertions(+), 18 deletions(-) rename test/data/validationData/issues/issue#478/{issueCollection.json => path-variable-does-not-match-collection.json} (100%) rename test/data/validationData/issues/issue#478/{issueSpec.yaml => path-variable-does-not-match-spec.yaml} (100%) diff --git a/lib/common/schemaUtilsCommon.js b/lib/common/schemaUtilsCommon.js index 3e50340..3b15ec8 100644 --- a/lib/common/schemaUtilsCommon.js +++ b/lib/common/schemaUtilsCommon.js @@ -345,5 +345,16 @@ module.exports = { isKnownType: function(schema) { return typeof schemaTypeToJsValidator[schema.type] === 'function'; + }, + + getServersPathVars: function(servers) { + return servers.reduce((acc, current) => { + let newVarNames = current.hasOwnProperty('variables') ? + Object.keys(current.variables).filter((varName) => { + return !acc.includes(varName); + }) : + []; + return [...acc, ...newVarNames]; + }, []); } }; diff --git a/lib/schemapack.js b/lib/schemapack.js index e62977f..dd4c63f 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -1,5 +1,4 @@ 'use strict'; - // This is the default collection name if one can't be inferred from the OpenAPI spec const COLLECTION_NAME = 'Imported from OpenAPI 3.0', { getConcreteSchemaUtils } = require('./common/versionUtils.js'), @@ -24,7 +23,8 @@ const COLLECTION_NAME = 'Imported from OpenAPI 3.0', // This provides the base class for // errors with the input OpenAPI spec OpenApiErr = require('./error.js'), - schemaUtils = require('./schemaUtils'); + schemaUtils = require('./schemaUtils'), + { getServersPathVars } = require('./common/schemaUtilsCommon.js'); let path = require('path'), concreteUtils, @@ -476,18 +476,8 @@ class SchemaPack { localServers = matchedPath.path.hasOwnProperty('servers') ? matchedPath.path.servers : [], - getServersPathVars = (servers) => { - return servers.reduce((acc, current) => { - let newVarNames = current.hasOwnProperty('variables') ? - Object.keys(current.variables).filter((varName) => { - return !acc.includes(varName); - }) : - []; - return [...acc, ...newVarNames]; - }, []); - }, serversPathVars = [...getServersPathVars(localServers), ...getServersPathVars(schema.servers)], - isNotALocalServerPathVar = (pathVarName) => { + isNotAServerPathVar = (pathVarName) => { return !serversPathVars.includes(pathVarName); }; matchedPath.unmatchedVariablesFromTransaction = []; @@ -498,7 +488,7 @@ class SchemaPack { let matched = transactionPathVar.key === pathVar.key; if ( !matched && - isNotALocalServerPathVar(transactionPathVar.key) && + isNotAServerPathVar(transactionPathVar.key) && !matchedPath.unmatchedVariablesFromTransaction.includes(transactionPathVar.key) ) { matchedPath.unmatchedVariablesFromTransaction.push(transactionPathVar.key); diff --git a/test/data/validationData/issues/issue#478/issueCollection.json b/test/data/validationData/issues/issue#478/path-variable-does-not-match-collection.json similarity index 100% rename from test/data/validationData/issues/issue#478/issueCollection.json rename to test/data/validationData/issues/issue#478/path-variable-does-not-match-collection.json diff --git a/test/data/validationData/issues/issue#478/issueSpec.yaml b/test/data/validationData/issues/issue#478/path-variable-does-not-match-spec.yaml similarity index 100% rename from test/data/validationData/issues/issue#478/issueSpec.yaml rename to test/data/validationData/issues/issue#478/path-variable-does-not-match-spec.yaml diff --git a/test/unit/validator.test.js b/test/unit/validator.test.js index a769f90..e7e6543 100644 --- a/test/unit/validator.test.js +++ b/test/unit/validator.test.js @@ -1313,8 +1313,8 @@ describe('validateTransaction method. Path variables matching validation (issue it('Should validate correctly while a path param in spec does not matches with collection' + ' (issue#478)', function(done) { let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), - issueSpec = fs.readFileSync(issueFolder + '/issueSpec.yaml', 'utf-8'), - issueCollection = fs.readFileSync(issueFolder + '/issueCollection.json', 'utf-8'), + issueSpec = fs.readFileSync(issueFolder + '/path-variable-does-not-match-spec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/path-variable-does-not-match-collection.json', 'utf-8'), resultObj, historyRequest = [], schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: false }); @@ -1339,8 +1339,8 @@ describe('validateTransaction method. Path variables matching validation (issue it('Should validate correctly while a path param in spec does not matches with collection' + ' (issue#478), allowUrlPathVarMatching: true', function(done) { let issueFolder = path.join(__dirname, VALIDATION_DATA_FOLDER_PATH + '/issues/issue#478'), - issueSpec = fs.readFileSync(issueFolder + '/issueSpec.yaml', 'utf-8'), - issueCollection = fs.readFileSync(issueFolder + '/issueCollection.json', 'utf-8'), + issueSpec = fs.readFileSync(issueFolder + '/path-variable-does-not-match-spec.yaml', 'utf-8'), + issueCollection = fs.readFileSync(issueFolder + '/path-variable-does-not-match-collection.json', 'utf-8'), resultObj, historyRequest = [], schemaPack = new Converter.SchemaPack({ type: 'string', data: issueSpec }, { allowUrlPathVarMatching: true }); From 13c451e455bd311d0ca96bdff143dbb56a5fcfb5 Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Wed, 2 Mar 2022 16:38:10 -0600 Subject: [PATCH 06/11] Fix the suggestedValue when reason code is INVALID_VALUE, validating the suggestedFix values in related tests --- lib/schemaUtils.js | 25 ++++++++++++++----------- lib/schemapack.js | 1 + test/unit/validator.test.js | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index b0e6f0f..f8bfa2e 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -3422,7 +3422,8 @@ module.exports = { })) { let reasonCode, reason, - key, + suggestedValue, + actualValue, currentUnmatchedVariableInTransaction = unmatchedVariablesFromTransaction[index], isInvalidValue = currentUnmatchedVariableInTransaction !== undefined; @@ -3430,12 +3431,20 @@ module.exports = { reasonCode = 'INVALID_VALUE'; reason = `The ${currentUnmatchedVariableInTransaction} path variable does not match with path variable` + ` expected in in schema at this position (${unmatchedSchemaVariableNames[index]})`; - key = currentUnmatchedVariableInTransaction; + actualValue = currentUnmatchedVariableInTransaction; + suggestedValue = unmatchedSchemaVariableNames[index]; } else { reasonCode = 'MISSING_IN_REQUEST'; reason = `The required path variable "${pathVar.name}" was not found in the transaction`; - key = null; + actualValue = null; + suggestedValue = { + key: pathVar.name, + value: safeSchemaFaker(pathVar.schema || {}, 'example', PROCESSING_TYPE.VALIDATION, + PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache, + options.stackLimit), + description: this.getParameterDescription(pathVar) + }; } // assign parameter example(s) as schema examples; @@ -3452,14 +3461,8 @@ module.exports = { if (options.suggestAvailableFixes) { mismatchObj.suggestedFix = { key: pathVar.name, - actualValue: key, - suggestedValue: { - key: pathVar.name, - value: safeSchemaFaker(pathVar.schema || {}, 'example', PROCESSING_TYPE.VALIDATION, - PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache, - options.stackLimit), - description: this.getParameterDescription(pathVar) - } + actualValue, + suggestedValue }; } mismatches.push(mismatchObj); diff --git a/lib/schemapack.js b/lib/schemapack.js index dd4c63f..164fe7a 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -480,6 +480,7 @@ class SchemaPack { isNotAServerPathVar = (pathVarName) => { return !serversPathVars.includes(pathVarName); }; + matchedPath.unmatchedVariablesFromTransaction = []; // override path variable value with actual value present in transaction // as matched pathvariable contains key as value, as it is generated from url only diff --git a/test/unit/validator.test.js b/test/unit/validator.test.js index e7e6543..ff93874 100644 --- a/test/unit/validator.test.js +++ b/test/unit/validator.test.js @@ -1433,6 +1433,9 @@ describe('validateTransaction method. Path variables matching validation (issue ' expected in in schema at this position (peterId)' ); expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.equal('petId'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.equal('peterId'); + expect(resultObj.mismatches[0].suggestedFix.key).to.be.equal('peterId'); done(); }); }); @@ -1470,6 +1473,14 @@ describe('validateTransaction method. Path variables matching validation (issue 'variable expected in in schema at this position (correctName)' ); expect(resultObj.mismatches[1].reasonCode).to.equal('INVALID_VALUE'); + + expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.equal('petId'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.equal('peterId'); + expect(resultObj.mismatches[0].suggestedFix.key).to.be.equal('peterId'); + + expect(resultObj.mismatches[1].suggestedFix.actualValue).to.be.equal('wrongNamedId'); + expect(resultObj.mismatches[1].suggestedFix.suggestedValue).to.be.equal('correctName'); + expect(resultObj.mismatches[1].suggestedFix.key).to.be.equal('correctName'); done(); }); }); @@ -1506,6 +1517,15 @@ describe('validateTransaction method. Path variables matching validation (issue 'The required path variable "correctName" was not found in the transaction' ); expect(resultObj.mismatches[1].reasonCode).to.equal('MISSING_IN_REQUEST'); + + expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.equal('petId'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.equal('peterId'); + expect(resultObj.mismatches[0].suggestedFix.key).to.be.equal('peterId'); + + expect(resultObj.mismatches[1].suggestedFix.actualValue).to.be.equal(null); + expect(resultObj.mismatches[1].suggestedFix.suggestedValue).to.be.an('object') + .to.include.keys(['description', 'key', 'value']); + expect(resultObj.mismatches[1].suggestedFix.key).to.be.equal('correctName'); done(); }); }); From a5af6ae93117daa757f9684216983b3cfea8205f Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Thu, 3 Mar 2022 17:31:22 -0600 Subject: [PATCH 07/11] Fix typo, change INVALID_VALUE reason message --- lib/common/schemaUtilsCommon.js | 2 +- lib/schemaUtils.js | 2 +- lib/schemapack.js | 2 +- test/unit/validator.test.js | 28 ++++++++++++++-------------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/common/schemaUtilsCommon.js b/lib/common/schemaUtilsCommon.js index 3b15ec8..4ed5f34 100644 --- a/lib/common/schemaUtilsCommon.js +++ b/lib/common/schemaUtilsCommon.js @@ -349,7 +349,7 @@ module.exports = { getServersPathVars: function(servers) { return servers.reduce((acc, current) => { - let newVarNames = current.hasOwnProperty('variables') ? + const newVarNames = current.hasOwnProperty('variables') ? Object.keys(current.variables).filter((varName) => { return !acc.includes(varName); }) : diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index f8bfa2e..b985128 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -3430,7 +3430,7 @@ module.exports = { if (unmatchedSchemaVariableNames.length > 0 && isInvalidValue) { reasonCode = 'INVALID_VALUE'; reason = `The ${currentUnmatchedVariableInTransaction} path variable does not match with path variable` + - ` expected in in schema at this position (${unmatchedSchemaVariableNames[index]})`; + ` expected (${unmatchedSchemaVariableNames[index]}) in the schema at this position`; actualValue = currentUnmatchedVariableInTransaction; suggestedValue = unmatchedSchemaVariableNames[index]; } diff --git a/lib/schemapack.js b/lib/schemapack.js index 164fe7a..01c409c 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -485,7 +485,7 @@ class SchemaPack { // override path variable value with actual value present in transaction // as matched pathvariable contains key as value, as it is generated from url only _.forEach(matchedPath.pathVariables, (pathVar) => { - let mappedPathVar = _.find(transactionPathVariables, (transactionPathVar) => { + const mappedPathVar = _.find(transactionPathVariables, (transactionPathVar) => { let matched = transactionPathVar.key === pathVar.key; if ( !matched && diff --git a/test/unit/validator.test.js b/test/unit/validator.test.js index ff93874..5d9f6ad 100644 --- a/test/unit/validator.test.js +++ b/test/unit/validator.test.js @@ -1329,8 +1329,8 @@ describe('validateTransaction method. Path variables matching validation (issue expect(resultObj.mismatches).to.have.length(1); expect(resultObj.mismatches[0].reasonCode).to.be.equal('INVALID_VALUE'); expect(resultObj.mismatches[0].reason).to.be.equal( - 'The petId path variable does not match with path variable' + - ' expected in in schema at this position (peterId)' + 'The petId path variable does not match with path variable expected (peterId)' + + ' in the schema at this position' ); done(); }); @@ -1375,8 +1375,8 @@ describe('validateTransaction method. Path variables matching validation (issue resultObj = result.requests[historyRequest[0].id].endpoints[0]; expect(resultObj.mismatches).to.have.length(1); expect(resultObj.mismatches[0].reason).to.equal( - 'The petId path variable does not match with path variable' + - ' expected in in schema at this position (peterId)' + 'The petId path variable does not match with path variable expected (peterId)' + + ' in the schema at this position' ); expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); done(); @@ -1401,8 +1401,8 @@ describe('validateTransaction method. Path variables matching validation (issue resultObj = result.requests[historyRequest[0].id].endpoints[0]; expect(resultObj.mismatches).to.have.length(1); expect(resultObj.mismatches[0].reason).to.equal( - 'The petId path variable does not match with path variable' + - ' expected in in schema at this position (peterId)' + 'The petId path variable does not match with path variable expected (peterId)' + + ' in the schema at this position' ); expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); done(); @@ -1429,8 +1429,8 @@ describe('validateTransaction method. Path variables matching validation (issue resultObj = result.requests[historyRequest[0].id].endpoints[0]; expect(resultObj.mismatches).to.have.length(1); expect(resultObj.mismatches[0].reason).to.equal( - 'The petId path variable does not match with path variable' + - ' expected in in schema at this position (peterId)' + 'The petId path variable does not match with path variable expected (peterId)' + + ' in the schema at this position' ); expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.equal('petId'); @@ -1464,13 +1464,13 @@ describe('validateTransaction method. Path variables matching validation (issue resultObj = result.requests[historyRequest[0].id].endpoints[0]; expect(resultObj.mismatches).to.have.length(2); expect(resultObj.mismatches[0].reason).to.equal( - 'The petId path variable does not match with path variable' + - ' expected in in schema at this position (peterId)' + 'The petId path variable does not match with path variable expected (peterId)' + + ' in the schema at this position' ); expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); expect(resultObj.mismatches[1].reason).to.equal( - 'The wrongNamedId path variable does not match with path ' + - 'variable expected in in schema at this position (correctName)' + 'The wrongNamedId path variable does not match with path variable expected (correctName)' + + ' in the schema at this position' ); expect(resultObj.mismatches[1].reasonCode).to.equal('INVALID_VALUE'); @@ -1509,8 +1509,8 @@ describe('validateTransaction method. Path variables matching validation (issue resultObj = result.requests[historyRequest[0].id].endpoints[0]; expect(resultObj.mismatches).to.have.length(2); expect(resultObj.mismatches[0].reason).to.equal( - 'The petId path variable does not match with path variable' + - ' expected in in schema at this position (peterId)' + 'The petId path variable does not match with path variable expected (peterId)' + + ' in the schema at this position' ); expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); expect(resultObj.mismatches[1].reason).to.equal( From 06b4d776106b7fc479eb77c8888b32d838c87010 Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Wed, 16 Mar 2022 15:50:56 -0600 Subject: [PATCH 08/11] Change INVALID_VALUE to MISSING_IN_REQUEST, actualValue is now the varPath object from the transaction, suggestedValue is the object faked from the schema --- lib/schemaUtils.js | 31 ++++++++++++------------- lib/schemapack.js | 4 ++-- test/unit/validator.test.js | 46 +++++++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index b985128..7c77bcc 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -3420,31 +3420,24 @@ module.exports = { // only consider variable matching if url path variables is not allowed return param.key === pathVar.name && (options.allowUrlPathVarMatching || param._varMatched); })) { - let reasonCode, + let reasonCode = 'MISSING_IN_REQUEST', reason, - suggestedValue, actualValue, currentUnmatchedVariableInTransaction = unmatchedVariablesFromTransaction[index], isInvalidValue = currentUnmatchedVariableInTransaction !== undefined; if (unmatchedSchemaVariableNames.length > 0 && isInvalidValue) { - reasonCode = 'INVALID_VALUE'; - reason = `The ${currentUnmatchedVariableInTransaction} path variable does not match with path variable` + - ` expected (${unmatchedSchemaVariableNames[index]}) in the schema at this position`; - actualValue = currentUnmatchedVariableInTransaction; - suggestedValue = unmatchedSchemaVariableNames[index]; + 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 { - reasonCode = 'MISSING_IN_REQUEST'; reason = `The required path variable "${pathVar.name}" was not found in the transaction`; actualValue = null; - suggestedValue = { - key: pathVar.name, - value: safeSchemaFaker(pathVar.schema || {}, 'example', PROCESSING_TYPE.VALIDATION, - PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache, - options.stackLimit), - description: this.getParameterDescription(pathVar) - }; } // assign parameter example(s) as schema examples; @@ -3462,7 +3455,13 @@ module.exports = { mismatchObj.suggestedFix = { key: pathVar.name, actualValue, - suggestedValue + suggestedValue: { + key: pathVar.name, + value: safeSchemaFaker(pathVar.schema || {}, 'example', PROCESSING_TYPE.VALIDATION, + PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache, + options.stackLimit), + description: this.getParameterDescription(pathVar) + } }; } mismatches.push(mismatchObj); diff --git a/lib/schemapack.js b/lib/schemapack.js index 01c409c..d2ddd0e 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -490,9 +490,9 @@ class SchemaPack { if ( !matched && isNotAServerPathVar(transactionPathVar.key) && - !matchedPath.unmatchedVariablesFromTransaction.includes(transactionPathVar.key) + !matchedPath.unmatchedVariablesFromTransaction.includes(transactionPathVar) ) { - matchedPath.unmatchedVariablesFromTransaction.push(transactionPathVar.key); + matchedPath.unmatchedVariablesFromTransaction.push(transactionPathVar); } return matched; }); diff --git a/test/unit/validator.test.js b/test/unit/validator.test.js index 5d9f6ad..e4a7626 100644 --- a/test/unit/validator.test.js +++ b/test/unit/validator.test.js @@ -1327,7 +1327,7 @@ describe('validateTransaction method. Path variables matching validation (issue expect(result).to.be.an('object'); resultObj = result.requests[historyRequest[0].id].endpoints[0]; expect(resultObj.mismatches).to.have.length(1); - expect(resultObj.mismatches[0].reasonCode).to.be.equal('INVALID_VALUE'); + expect(resultObj.mismatches[0].reasonCode).to.be.equal('MISSING_IN_REQUEST'); expect(resultObj.mismatches[0].reason).to.be.equal( 'The petId path variable does not match with path variable expected (peterId)' + ' in the schema at this position' @@ -1378,7 +1378,7 @@ describe('validateTransaction method. Path variables matching validation (issue 'The petId path variable does not match with path variable expected (peterId)' + ' in the schema at this position' ); - expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[0].reasonCode).to.equal('MISSING_IN_REQUEST'); done(); }); }); @@ -1404,7 +1404,7 @@ describe('validateTransaction method. Path variables matching validation (issue 'The petId path variable does not match with path variable expected (peterId)' + ' in the schema at this position' ); - expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[0].reasonCode).to.equal('MISSING_IN_REQUEST'); done(); }); }); @@ -1432,9 +1432,13 @@ describe('validateTransaction method. Path variables matching validation (issue 'The petId path variable does not match with path variable expected (peterId)' + ' in the schema at this position' ); - expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); - expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.equal('petId'); - expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.equal('peterId'); + expect(resultObj.mismatches[0].reasonCode).to.equal('MISSING_IN_REQUEST'); + expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); + expect(resultObj.mismatches[0].suggestedFix.actualValue.key).to.be.equal('petId'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue.key).to.be.equal('peterId'); expect(resultObj.mismatches[0].suggestedFix.key).to.be.equal('peterId'); done(); }); @@ -1467,19 +1471,27 @@ describe('validateTransaction method. Path variables matching validation (issue 'The petId path variable does not match with path variable expected (peterId)' + ' in the schema at this position' ); - expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[0].reasonCode).to.equal('MISSING_IN_REQUEST'); expect(resultObj.mismatches[1].reason).to.equal( 'The wrongNamedId path variable does not match with path variable expected (correctName)' + ' in the schema at this position' ); - expect(resultObj.mismatches[1].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[1].reasonCode).to.equal('MISSING_IN_REQUEST'); - expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.equal('petId'); - expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.equal('peterId'); + expect(resultObj.mismatches[0].suggestedFix.actualValue.key).to.be.equal('petId'); + expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue.key).to.be.equal('peterId'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); expect(resultObj.mismatches[0].suggestedFix.key).to.be.equal('peterId'); - expect(resultObj.mismatches[1].suggestedFix.actualValue).to.be.equal('wrongNamedId'); - expect(resultObj.mismatches[1].suggestedFix.suggestedValue).to.be.equal('correctName'); + expect(resultObj.mismatches[1].suggestedFix.actualValue.key).to.be.equal('wrongNamedId'); + expect(resultObj.mismatches[1].suggestedFix.actualValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); + expect(resultObj.mismatches[1].suggestedFix.suggestedValue.key).to.be.equal('correctName'); + expect(resultObj.mismatches[1].suggestedFix.suggestedValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); expect(resultObj.mismatches[1].suggestedFix.key).to.be.equal('correctName'); done(); }); @@ -1512,14 +1524,18 @@ describe('validateTransaction method. Path variables matching validation (issue 'The petId path variable does not match with path variable expected (peterId)' + ' in the schema at this position' ); - expect(resultObj.mismatches[0].reasonCode).to.equal('INVALID_VALUE'); + expect(resultObj.mismatches[0].reasonCode).to.equal('MISSING_IN_REQUEST'); expect(resultObj.mismatches[1].reason).to.equal( 'The required path variable "correctName" was not found in the transaction' ); expect(resultObj.mismatches[1].reasonCode).to.equal('MISSING_IN_REQUEST'); - expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.equal('petId'); - expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.equal('peterId'); + expect(resultObj.mismatches[0].suggestedFix.actualValue.key).to.be.equal('petId'); + expect(resultObj.mismatches[0].suggestedFix.actualValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue.key).to.be.equal('peterId'); + expect(resultObj.mismatches[0].suggestedFix.suggestedValue).to.be.an('object') + .to.have.all.keys('key', 'value', 'description'); expect(resultObj.mismatches[0].suggestedFix.key).to.be.equal('peterId'); expect(resultObj.mismatches[1].suggestedFix.actualValue).to.be.equal(null); From c029563cda1788a48e3fbc22c889ee3464937c1f Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Tue, 19 Jul 2022 00:06:47 +0000 Subject: [PATCH 09/11] fix: upgrade postman-collection from 4.0.0 to 4.1.4 Snyk has created this PR to upgrade postman-collection from 4.0.0 to 4.1.4. See this package in npm: https://www.npmjs.com/package/postman-collection See this project in Snyk: https://app.snyk.io/org/postman/project/a5c111c7-1bc9-4d89-849d-6732a81fc539?utm_source=github&utm_medium=referral&page=upgrade-pr --- package-lock.json | 56 +++++++++++++++++++++++------------------------ package.json | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0034add..5dc4967 100644 --- a/package-lock.json +++ b/package-lock.json @@ -334,6 +334,11 @@ "resolved": "https://registry.npmjs.org/@exodus/schemasafe/-/schemasafe-1.0.0-rc.6.tgz", "integrity": "sha512-dDnQizD94EdBwEj/fh3zPRa/HWCS9O5au2PuHhZBbuM3xWHxuaKzPBOEWze7Nn0xW68MIpZ7Xdyn1CoCpjKCuQ==" }, + "@faker-js/faker": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-5.5.3.tgz", + "integrity": "sha512-R11tGE6yIFwqpaIqcfkcg7AICXzFg14+5h5v0TfF/9+RMDL6jhzCy/pxHVOfbALGdtVYdt6JdR21tuxEgl34dw==" + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1193,11 +1198,6 @@ "tmp": "^0.0.33" } }, - "faker": { - "version": "5.5.3", - "resolved": "https://registry.npmjs.org/faker/-/faker-5.5.3.tgz", - "integrity": "sha512-wLTv2a28wjUyWkbnX7u/ABZBkUkIF2fCd73V6P2oFqEGEktDfzWx4UxrSqtPRw0xPRAcjeAOIiJWqZm3pP4u3g==" - }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -1241,7 +1241,7 @@ "file-type": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", - "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" + "integrity": "sha512-RLoqTXE8/vPmMuTI88DAzhMYC99I8BWv7zYP4A1puo5HIjEJ5EX48ighy4ZyKMG9EDXxBgW6e++cn7d1xuFghA==" }, "fill-range": { "version": "7.0.1", @@ -1529,7 +1529,7 @@ "http-reasons": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/http-reasons/-/http-reasons-0.1.0.tgz", - "integrity": "sha1-qVPKZwB4Zp3eFCzomUAbnW6F07Q=" + "integrity": "sha512-P6kYh0lKZ+y29T2Gqz+RlC9WBLhKe8kDmcJ+A+611jFfxdPsbMRQ5aNmFRM3lENqFkK+HTTL+tlQviAiv0AbLQ==" }, "http2-client": { "version": "1.3.5", @@ -2011,7 +2011,7 @@ "liquid-json": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/liquid-json/-/liquid-json-0.3.1.tgz", - "integrity": "sha1-kVWhgTbYprJhXl8W+aJEira1Duo=" + "integrity": "sha512-wUayTU8MS827Dam6MxgD72Ui+KOSF+u/eIqpatOtjnvgJ0+mnDq33uC2M7J0tPK+upe/DpUAuK4JUU89iBoNKQ==" }, "locate-path": { "version": "5.0.0", @@ -2070,9 +2070,9 @@ } }, "mime-db": { - "version": "1.48.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.48.0.tgz", - "integrity": "sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==" + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" }, "mime-format": { "version": "2.0.1", @@ -2083,11 +2083,11 @@ } }, "mime-types": { - "version": "2.1.31", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.31.tgz", - "integrity": "sha512-XGZnNzm3QvgKxa8dpzyhFTHmpP3l5YNusmne07VUOXxou9CqUqYa/HBy124RqtVh/O2pECas/MOcsDgpilPOPg==", + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "requires": { - "mime-db": "1.48.0" + "mime-db": "1.52.0" } }, "mimic-fn": { @@ -2908,20 +2908,20 @@ } }, "postman-collection": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/postman-collection/-/postman-collection-4.0.0.tgz", - "integrity": "sha512-vDrXG/dclSu6RMqPqBz4ZqoQBwcj/a80sJYsQZmzWJ6dWgXiudPhwu6Vm3C1Hy7zX5W8A6am1Z6vb/TB4eyURA==", + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/postman-collection/-/postman-collection-4.1.4.tgz", + "integrity": "sha512-3b/ZUrCIXRG3Eh3P6usiBYSZbCHTwMsJJ1l2RID/rdv/EC8YyhVS5PKGKdpYrRB69F/fETD9lOAuhvCwj0h71w==", "requires": { - "faker": "5.5.3", + "@faker-js/faker": "5.5.3", "file-type": "3.9.0", "http-reasons": "0.1.0", "iconv-lite": "0.6.3", "liquid-json": "0.3.1", "lodash": "4.17.21", "mime-format": "2.0.1", - "mime-types": "2.1.31", - "postman-url-encoder": "3.0.1", - "semver": "7.3.5", + "mime-types": "2.1.35", + "postman-url-encoder": "3.0.5", + "semver": "7.3.7", "uuid": "8.3.2" }, "dependencies": { @@ -2941,9 +2941,9 @@ } }, "postman-url-encoder": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/postman-url-encoder/-/postman-url-encoder-3.0.1.tgz", - "integrity": "sha512-dMPqXnkDlstM2Eya+Gw4MIGWEan8TzldDcUKZIhZUsJ/G5JjubfQPhFhVWKzuATDMvwvrWbSjF+8VmAvbu6giw==", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/postman-url-encoder/-/postman-url-encoder-3.0.5.tgz", + "integrity": "sha512-jOrdVvzUXBC7C+9gkIkpDJ3HIxOHTIqjpQ4C1EMt1ZGeMvSEpbFCKq23DEfgsj46vMnDgyQf+1ZLp2Wm+bKSsA==", "requires": { "punycode": "^2.1.1" } @@ -3107,9 +3107,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", "requires": { "lru-cache": "^6.0.0" }, diff --git a/package.json b/package.json index 1610cf8..c9fdd96 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "lodash": "4.17.21", "oas-resolver-browser": "2.5.6", "path-browserify": "1.0.1", - "postman-collection": "4.0.0", + "postman-collection": "4.1.4", "swagger2openapi": "7.0.8", "traverse": "0.6.6", "yaml": "1.10.2" From 899cec9027aa748f637d0efd20bf16b4b0912319 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Tue, 19 Jul 2022 00:06:51 +0000 Subject: [PATCH 10/11] fix: upgrade chai from 4.3.4 to 4.3.6 Snyk has created this PR to upgrade chai from 4.3.4 to 4.3.6. See this package in npm: https://www.npmjs.com/package/chai See this project in Snyk: https://app.snyk.io/org/postman/project/a5c111c7-1bc9-4d89-849d-6732a81fc539?utm_source=github&utm_medium=referral&page=upgrade-pr --- package-lock.json | 20 +++++++++++++++----- package.json | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0034add..fd4ab1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -583,15 +583,16 @@ "dev": true }, "chai": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz", - "integrity": "sha1-tV5lWzHh6scJm+TAjCGWT84ubEk=", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.6.tgz", + "integrity": "sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==", "dev": true, "requires": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", "deep-eql": "^3.0.1", "get-func-name": "^2.0.0", + "loupe": "^2.3.1", "pathval": "^1.1.1", "type-detect": "^4.0.5" } @@ -621,7 +622,7 @@ "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==", "dev": true }, "chokidar": { @@ -1397,7 +1398,7 @@ "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", "dev": true }, "get-intrinsic": { @@ -2042,6 +2043,15 @@ "chalk": "^2.4.2" } }, + "loupe": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.4.tgz", + "integrity": "sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==", + "dev": true, + "requires": { + "get-func-name": "^2.0.0" + } + }, "lru-cache": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", diff --git a/package.json b/package.json index 1610cf8..8bce515 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,7 @@ "author": "Postman Labs ", "license": "Apache-2.0", "devDependencies": { - "chai": "4.3.4", + "chai": "4.3.6", "editorconfig": "0.15.3", "eslint": "5.16.0", "eslint-plugin-jsdoc": "3.8.0", From 3b47eab771b4cdc3d394f5ceaaf53430850e3cef Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Tue, 19 Jul 2022 00:06:54 +0000 Subject: [PATCH 11/11] fix: upgrade async from 3.2.3 to 3.2.4 Snyk has created this PR to upgrade async from 3.2.3 to 3.2.4. See this package in npm: https://www.npmjs.com/package/async See this project in Snyk: https://app.snyk.io/org/postman/project/a5c111c7-1bc9-4d89-849d-6732a81fc539?utm_source=github&utm_medium=referral&page=upgrade-pr --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0034add..6389a46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -483,9 +483,9 @@ "dev": true }, "async": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", - "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" }, "balanced-match": { "version": "1.0.0", diff --git a/package.json b/package.json index 1610cf8..9f7ff92 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,7 @@ "dependencies": { "ajv": "8.1.0", "ajv-formats": "2.1.1", - "async": "3.2.3", + "async": "3.2.4", "commander": "2.20.3", "js-yaml": "3.14.1", "json-schema-merge-allof": "0.8.1",