Skip to content

Commit

Permalink
Merge pull request #675 from postmanlabs/bug/curl-gen-fix
Browse files Browse the repository at this point in the history
cURL codegen should work when request has a protocolProfileBehavior with null value
  • Loading branch information
Dhwaneet Bhatt authored Feb 22, 2023
2 parents d0156cf + 24495fe commit 77b4151
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
15 changes: 11 additions & 4 deletions codegens/curl/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,19 @@ var self = module.exports = {
* @returns {Boolean}
*/
shouldAddHttpMethod: function (request, options) {
const followRedirect = _.get(request, 'protocolProfileBehavior.followRedirects', options.followRedirect),
followOriginalHttpMethod =
_.get(request, 'protocolProfileBehavior.followOriginalHttpMethod', options.followOriginalHttpMethod),
disableBodyPruning = _.get(request, 'protocolProfileBehavior.disableBodyPruning', true),
let followRedirect = options.followRedirect,
followOriginalHttpMethod = options.followOriginalHttpMethod,
disableBodyPruning = true,
isBodyEmpty = self.isBodyEmpty(request.body);

// eslint-disable-next-line lodash/prefer-is-nil
if (request.protocolProfileBehavior !== null && request.protocolProfileBehavior !== undefined) {
followRedirect = _.get(request, 'protocolProfileBehavior.followRedirects', followRedirect);
followOriginalHttpMethod =
_.get(request, 'protocolProfileBehavior.followOriginalHttpMethod', followOriginalHttpMethod);
disableBodyPruning = _.get(request, 'protocolProfileBehavior.disableBodyPruning', true);
}

if (followRedirect && followOriginalHttpMethod) {
return true;
}
Expand Down
36 changes: 36 additions & 0 deletions codegens/curl/test/unit/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,42 @@ describe('curl convert function', function () {
expect(snippet).to.not.include('--request POST');
});
});

it('should work when protocolProfileBehavior is null in request settings', function () {
const request = new sdk.Request({
'method': 'POST',
'header': [],
'body': {
'mode': 'graphql',
'graphql': {
'query': '{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: "performers"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}', // eslint-disable-line
'variables': '{\n\t"variable_key": "variable_value"\n}'
}
},
'url': {
'raw': 'https://postman-echo.com/post',
'protocol': 'https',
'host': [
'postman-echo',
'com'
],
'path': [
'post'
]
}
});

// this needs to be done here because protocolProfileBehavior is not in collections SDK
request.protocolProfileBehavior = null;

convert(request, { followRedirect: true, followOriginalHttpMethod: true }, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet).to.include('--request POST');
});
});
});
});
});

0 comments on commit 77b4151

Please sign in to comment.