From 6e9a7af27b41c7247f3addc30c68db6b8ffa7701 Mon Sep 17 00:00:00 2001 From: Vishal Shingala Date: Tue, 14 Apr 2020 12:11:04 +0530 Subject: [PATCH 1/3] Fixed invalid transaction paths and changed REQUEST_BODY to BODY for uniformity. --- lib/schemaUtils.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 6d4524dad..75183282f 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -60,7 +60,7 @@ const async = require('async'), QUERYPARAM: 'query parameter', PATHVARIABLE: 'path variable', HEADER: 'header', - REQUEST_BODY: 'request body', + BODY: 'request body', RESPONSE_HEADER: 'response header', RESPONSE_BODY: 'response body' }, @@ -1956,7 +1956,7 @@ module.exports = { /** * - * @param {*} property - one of QUERYPARAM, PATHVARIABLE, HEADER, REQUEST_BODY, RESPONSE_HEADER, RESPONSE_BODY + * @param {*} property - one of QUERYPARAM, PATHVARIABLE, HEADER, BODY, RESPONSE_HEADER, RESPONSE_BODY * @param {*} jsonPathPrefix - this will be prepended to all JSON schema paths on the request * @param {*} txnParamName - Optional - The name of the param being validated (useful for query params, * req headers, res headers) @@ -2371,7 +2371,7 @@ module.exports = { mismatches.push({ property: mismatchProperty, transactionJsonPath: transactionPathPrefix + '/' + pHeader.key, - schemaJsonPath: schemaPathPrefix + '/headers', + schemaJsonPath: schemaPathPrefix + '.headers', reasonCode: 'MISSING_IN_SCHEMA', reason: `The header ${pHeader.key} was not found in the schema` }); @@ -2451,7 +2451,7 @@ module.exports = { mismatches.push({ property: mismatchProperty, transactionJsonPath: transactionPathPrefix, - schemaJsonPath: schemaPathPrefix + 'requestBody.content.application.json.schema', + schemaJsonPath: schemaPathPrefix + '.requestBody.content.application.json.schema', reasonCode: 'INVALID_BODY', reason: 'The request body didn\'t match the specified schema' }); @@ -2460,9 +2460,9 @@ module.exports = { // _.each(validate.errors, (error) => { // // error.keyword can be https://ajv.js.org/keywords.html // mismatches.push({ - // property: 'REQUEST_BODY', + // property: 'BODY', // transactionJsonPath: transactionPathPrefix + error.dataPath, - // schemaJsonPath: schemaPathPrefix + 'requestBody.content.application.json.schema.' + error.schemaPath, + // schemaJsonPath: schemaPathPrefix + '.requestBody.content.application.json.schema.' + error.schemaPath, // reasonCode: error.keyword.toUpperCase(), // reason: error.message // }); @@ -2538,13 +2538,13 @@ module.exports = { async.parallel({ headers: (cb) => { this.checkResponseHeaders(thisSchemaResponse, response.header, - transactionPathPrefix + '[' + response.id + ']header', + transactionPathPrefix + '[' + response.id + '].header', schemaPathPrefix + '.responses.' + responsePathPrefix, components, options, schemaResolutionCache, cb); }, body: (cb) => { // assume it's JSON at this point this.checkResponseBody(thisSchemaResponse, response.body, - transactionPathPrefix + '[' + response.id + ']body', + transactionPathPrefix + '[' + response.id + '].body', schemaPathPrefix + '.responses.' + responsePathPrefix, components, options, schemaResolutionCache, cb); } }, (err, result) => { From 8bd37ae4eb993c685f7290ee447fedf83aa01ed9 Mon Sep 17 00:00:00 2001 From: Vishal Shingala Date: Tue, 14 Apr 2020 12:17:21 +0530 Subject: [PATCH 2/3] Fixed typo --- lib/schemaUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 75183282f..a3f5d88b5 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2500,7 +2500,7 @@ module.exports = { setTimeout(() => { return this.checkValueAgainstSchema(mismatchProperty, transactionPathPrefix, - null, // no param name for the request body + null, // no param name for the response body body, schemaPathPrefix + '.content[application/json].schema', deref.resolveRefs(schemaContent, 'response', components, schemaResolutionCache, From f2a56b4da7fe88067f2f1c441dab370c2d9365d7 Mon Sep 17 00:00:00 2001 From: Vishal Shingala Date: Wed, 15 Apr 2020 14:57:04 +0530 Subject: [PATCH 3/3] Use bracket resolution for application/json --- lib/schemaUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index a3f5d88b5..96dd8dcb0 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2451,7 +2451,7 @@ module.exports = { mismatches.push({ property: mismatchProperty, transactionJsonPath: transactionPathPrefix, - schemaJsonPath: schemaPathPrefix + '.requestBody.content.application.json.schema', + schemaJsonPath: schemaPathPrefix + '.requestBody.content[application/json].schema', reasonCode: 'INVALID_BODY', reason: 'The request body didn\'t match the specified schema' }); @@ -2462,7 +2462,7 @@ module.exports = { // mismatches.push({ // property: 'BODY', // transactionJsonPath: transactionPathPrefix + error.dataPath, - // schemaJsonPath: schemaPathPrefix + '.requestBody.content.application.json.schema.' + error.schemaPath, + // schemaJsonPath: schemaPathPrefix + '.requestBody.content[application/json].schema.' + error.schemaPath, // reasonCode: error.keyword.toUpperCase(), // reason: error.message // });