Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple requests for different response codes #363

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
];

Expand Down
42 changes: 38 additions & 4 deletions lib/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,6 @@ module.exports = {
subChild,
i,
requestCount;

// 3 options:

// 1. folder with more than one request in its subtree
Expand Down Expand Up @@ -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
*/
Expand All @@ -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}}
Expand All @@ -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]) {
Expand Down Expand Up @@ -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;
},

/**
Expand Down
9 changes: 8 additions & 1 deletion test/system/structure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const optionIds = [
'ignoreUnresolvedVariables',
'optimizeConversion',
'strictRequestMatching',
'disableOptionalParameters'
'disableOptionalParameters',
'separateRequests'
],
expectedOptions = {
collapseFolders: {
Expand Down Expand Up @@ -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'
}
};

Expand Down