diff --git a/OPTIONS.md b/OPTIONS.md index b2c4c9439..12453b753 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 response status codes|CONVERSION diff --git a/lib/options.js b/lib/options.js index c0cc1b6f1..149a7f8e6 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 response status codes', + external: true, + usage: ['CONVERSION'] } ]; diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index e203f1d35..b71a0cbf3 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -954,7 +954,6 @@ module.exports = { subChild, i, requestCount; - // 3 options: // 1. folder with more than one request in its subtree @@ -2093,6 +2092,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 +2117,9 @@ module.exports = { localServers = _.get(operationItem, 'properties.servers'), exampleRequestBody, sanitizeResult, - globalServers = _.get(operationItem, 'servers'); + globalServers = _.get(operationItem, 'servers'), + separate = false, + items = []; // handling path templating in request url if any // convert all {anything} to {{anything}} @@ -2133,6 +2135,18 @@ module.exports = { // Updated reqParams.path reqParams.path = sanitizeResult.pathVars; + 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; + } + } + } + // Add collection variables to the variableStore. sanitizeResult.collectionVars.forEach((element) => { if (!variableStore[element.name]) { @@ -2391,11 +2405,31 @@ module.exports = { } convertedResponse = this.convertToPmResponse(swagResponse, code, thisOriginalRequest, components, options, schemaCache); - convertedResponse && item.responses.add(convertedResponse); + if (separate) { + 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); + } }); } - return item; + if (!items.length) { + return item; + } + + let itemGroup = new sdk.ItemGroup({ + name: utils.insertSpacesInName(item.name) + }); + for (let i = 0; i < items.length; i++) { + itemGroup.items.add(items[i]); + } + + return itemGroup; }, /** diff --git a/test/system/structure.test.js b/test/system/structure.test.js index f798d08d1..b99d106ae 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 response status codes' } };