From 13f5281a9b5a7ba6489bdde11f3d3ef336e3647d Mon Sep 17 00:00:00 2001 From: sarthak_saxena_72 Date: Mon, 26 Apr 2021 16:12:05 +0530 Subject: [PATCH 1/5] moving separate variable to the top --- lib/options.js | 9 +++++++++ lib/schemaUtils.js | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/options.js b/lib/options.js index c0cc1b6f1..761ab2da9 100644 --- a/lib/options.js +++ b/lib/options.js @@ -210,6 +210,15 @@ module.exports = { description: 'Whether to set optional parameters as disabled', external: true, usage: ['CONVERSION'] + }, + { + name: 'Separate requests', + id: 'separateRequests', + type: 'array', + default: null, + description: 'Whether to have separate requests for multiple responses', + external: true, + usage: ['CONVERSION'] } ]; diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index e203f1d35..88dc832bb 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -953,7 +953,8 @@ module.exports = { itemGroup, subChild, i, - requestCount; + requestCount, + separate; // 3 options: @@ -2093,6 +2094,7 @@ module.exports = { * @param {object} options - a standard list of options that's globally passed around. Check options.js for more. * @param {object} schemaCache - object storing schemaFaker and schmeResolution caches * @param {array} variableStore - array + * @param {Boolean} separate - Indicates whether separate requests are required for each response or not. * @returns {Object} postman request Item * @no-unit-test */ @@ -2117,7 +2119,18 @@ module.exports = { localServers = _.get(operationItem, 'properties.servers'), exampleRequestBody, sanitizeResult, - globalServers = _.get(operationItem, 'servers'); + globalServers = _.get(operationItem, 'servers'), + separate = false, + items = []; + + if(options.separateRequests) { + for(i = 0; i < options.separateRequests.length; i++) { + if(options.separateRequests[i].url == reqUrl && options.separateRequests[i].method == item.request.method) { + separate = true; + break; + } + } + } // handling path templating in request url if any // convert all {anything} to {{anything}} @@ -2392,10 +2405,24 @@ module.exports = { convertedResponse = this.convertToPmResponse(swagResponse, code, thisOriginalRequest, components, options, schemaCache); convertedResponse && item.responses.add(convertedResponse); + + if(separate) { + items.push(item) + } + }); } - return item; + if(!items.length) return item; + + let itemGroup = new sdk.ItemGroup({ + name: utils.insertSpacesInName(item.name) + }); + for(i = 0; i < items.length; i++) { + itemGroup.items.add(items[i]); + } + + return itemGroup; }, /** From 6e57b2aceab428b722f0589375161bec1fde7426 Mon Sep 17 00:00:00 2001 From: sarthak_saxena_72 Date: Mon, 26 Apr 2021 16:50:15 +0530 Subject: [PATCH 2/5] request method check --- lib/schemaUtils.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 88dc832bb..c00012066 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2123,15 +2123,6 @@ module.exports = { separate = false, items = []; - if(options.separateRequests) { - for(i = 0; i < options.separateRequests.length; i++) { - if(options.separateRequests[i].url == reqUrl && options.separateRequests[i].method == item.request.method) { - separate = true; - break; - } - } - } - // handling path templating in request url if any // convert all {anything} to {{anything}} reqUrl = this.fixPathVariablesInUrl(reqUrl); @@ -2146,6 +2137,15 @@ module.exports = { // Updated reqParams.path reqParams.path = sanitizeResult.pathVars; + if(options.separateRequests) { + for(i = 0; i < options.separateRequests.length; i++) { + if(options.separateRequests[i].url == reqUrl && options.separateRequests[i].method == operationItem.method.toUpperCase()) { + separate = true; + break; + } + } + } + // Add collection variables to the variableStore. sanitizeResult.collectionVars.forEach((element) => { if (!variableStore[element.name]) { From afca77af0b1043af171f18c41b56f7de65237f89 Mon Sep 17 00:00:00 2001 From: sarthak_saxena_72 Date: Tue, 27 Apr 2021 22:07:15 +0530 Subject: [PATCH 3/5] multiple requests --- lib/schemaUtils.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index c00012066..f5e1a2f9f 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2404,12 +2404,16 @@ module.exports = { } convertedResponse = this.convertToPmResponse(swagResponse, code, thisOriginalRequest, components, options, schemaCache); - convertedResponse && item.responses.add(convertedResponse); - if(separate) { - items.push(item) + let tempItem = new sdk.Item(); + tempItem.request = item.request; + tempItem.name = item.name; + convertedResponse && tempItem.responses.add(convertedResponse); + items.push(tempItem) + } + else { + convertedResponse && item.responses.add(convertedResponse); } - }); } From 09ca30583929804d306277f0988f349255645710 Mon Sep 17 00:00:00 2001 From: sarthak_saxena_72 Date: Tue, 27 Apr 2021 22:20:14 +0530 Subject: [PATCH 4/5] options test and lint fix --- OPTIONS.md | 1 + lib/schemaUtils.js | 23 +++++++++++++---------- test/system/structure.test.js | 9 ++++++++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/OPTIONS.md b/OPTIONS.md index b2c4c9439..181a54ce2 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -17,3 +17,4 @@ validateMetadata|boolean|-|false|Whether to show mismatches for incorrect name a ignoreUnresolvedVariables|boolean|-|false|Whether to ignore mismatches resulting from unresolved variables in the Postman request|VALIDATION strictRequestMatching|boolean|-|false|Whether requests should be strictly matched with schema operations. Setting to true will not include any matches where the URL path segments don't match exactly.|VALIDATION disableOptionalParameters|boolean|-|false|Whether to set optional parameters as disabled|CONVERSION +separateRequests|array|-|null|Whether to have separate requests for multiple responses|CONVERSION diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index f5e1a2f9f..b71a0cbf3 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -953,9 +953,7 @@ module.exports = { itemGroup, subChild, i, - requestCount, - separate; - + requestCount; // 3 options: // 1. folder with more than one request in its subtree @@ -2137,9 +2135,12 @@ module.exports = { // Updated reqParams.path reqParams.path = sanitizeResult.pathVars; - if(options.separateRequests) { - for(i = 0; i < options.separateRequests.length; i++) { - if(options.separateRequests[i].url == reqUrl && options.separateRequests[i].method == operationItem.method.toUpperCase()) { + if (options.separateRequests) { + for (let i = 0; i < options.separateRequests.length; i++) { + if ( + options.separateRequests[i].url === reqUrl && + options.separateRequests[i].method === operationItem.method.toUpperCase() + ) { separate = true; break; } @@ -2404,12 +2405,12 @@ module.exports = { } convertedResponse = this.convertToPmResponse(swagResponse, code, thisOriginalRequest, components, options, schemaCache); - if(separate) { + if (separate) { let tempItem = new sdk.Item(); tempItem.request = item.request; tempItem.name = item.name; convertedResponse && tempItem.responses.add(convertedResponse); - items.push(tempItem) + items.push(tempItem); } else { convertedResponse && item.responses.add(convertedResponse); @@ -2417,12 +2418,14 @@ module.exports = { }); } - if(!items.length) return item; + if (!items.length) { + return item; + } let itemGroup = new sdk.ItemGroup({ name: utils.insertSpacesInName(item.name) }); - for(i = 0; i < items.length; i++) { + for (let i = 0; i < items.length; i++) { itemGroup.items.add(items[i]); } diff --git a/test/system/structure.test.js b/test/system/structure.test.js index f798d08d1..900ecf1de 100644 --- a/test/system/structure.test.js +++ b/test/system/structure.test.js @@ -20,7 +20,8 @@ const optionIds = [ 'ignoreUnresolvedVariables', 'optimizeConversion', 'strictRequestMatching', - 'disableOptionalParameters' + 'disableOptionalParameters', + 'separateRequests' ], expectedOptions = { collapseFolders: { @@ -146,6 +147,12 @@ const optionIds = [ type: 'boolean', default: false, description: 'Whether to set optional parameters as disabled' + }, + separateRequests: { + name: 'Separate requests', + type: 'array', + default: null, + description: 'Whether to have separate requests for multiple responses' } }; From 8b522e30bbb029d80d333276878f1b294f45582b Mon Sep 17 00:00:00 2001 From: sarthak_saxena_72 Date: Tue, 27 Apr 2021 22:30:34 +0530 Subject: [PATCH 5/5] change in option description --- OPTIONS.md | 2 +- lib/options.js | 2 +- test/system/structure.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OPTIONS.md b/OPTIONS.md index 181a54ce2..12453b753 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -17,4 +17,4 @@ validateMetadata|boolean|-|false|Whether to show mismatches for incorrect name a ignoreUnresolvedVariables|boolean|-|false|Whether to ignore mismatches resulting from unresolved variables in the Postman request|VALIDATION strictRequestMatching|boolean|-|false|Whether requests should be strictly matched with schema operations. Setting to true will not include any matches where the URL path segments don't match exactly.|VALIDATION disableOptionalParameters|boolean|-|false|Whether to set optional parameters as disabled|CONVERSION -separateRequests|array|-|null|Whether to have separate requests for multiple responses|CONVERSION +separateRequests|array|-|null|Whether to have separate requests for multiple response status codes|CONVERSION diff --git a/lib/options.js b/lib/options.js index 761ab2da9..149a7f8e6 100644 --- a/lib/options.js +++ b/lib/options.js @@ -216,7 +216,7 @@ module.exports = { id: 'separateRequests', type: 'array', default: null, - description: 'Whether to have separate requests for multiple responses', + description: 'Whether to have separate requests for multiple response status codes', external: true, usage: ['CONVERSION'] } diff --git a/test/system/structure.test.js b/test/system/structure.test.js index 900ecf1de..b99d106ae 100644 --- a/test/system/structure.test.js +++ b/test/system/structure.test.js @@ -152,7 +152,7 @@ const optionIds = [ name: 'Separate requests', type: 'array', default: null, - description: 'Whether to have separate requests for multiple responses' + description: 'Whether to have separate requests for multiple response status codes' } };