Skip to content

Commit 77b4151

Browse files
author
Dhwaneet Bhatt
authored
Merge pull request #675 from postmanlabs/bug/curl-gen-fix
cURL codegen should work when request has a protocolProfileBehavior with null value
2 parents d0156cf + 24495fe commit 77b4151

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

codegens/curl/lib/util.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,19 @@ var self = module.exports = {
292292
* @returns {Boolean}
293293
*/
294294
shouldAddHttpMethod: function (request, options) {
295-
const followRedirect = _.get(request, 'protocolProfileBehavior.followRedirects', options.followRedirect),
296-
followOriginalHttpMethod =
297-
_.get(request, 'protocolProfileBehavior.followOriginalHttpMethod', options.followOriginalHttpMethod),
298-
disableBodyPruning = _.get(request, 'protocolProfileBehavior.disableBodyPruning', true),
295+
let followRedirect = options.followRedirect,
296+
followOriginalHttpMethod = options.followOriginalHttpMethod,
297+
disableBodyPruning = true,
299298
isBodyEmpty = self.isBodyEmpty(request.body);
300299

300+
// eslint-disable-next-line lodash/prefer-is-nil
301+
if (request.protocolProfileBehavior !== null && request.protocolProfileBehavior !== undefined) {
302+
followRedirect = _.get(request, 'protocolProfileBehavior.followRedirects', followRedirect);
303+
followOriginalHttpMethod =
304+
_.get(request, 'protocolProfileBehavior.followOriginalHttpMethod', followOriginalHttpMethod);
305+
disableBodyPruning = _.get(request, 'protocolProfileBehavior.disableBodyPruning', true);
306+
}
307+
301308
if (followRedirect && followOriginalHttpMethod) {
302309
return true;
303310
}

codegens/curl/test/unit/convert.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,42 @@ describe('curl convert function', function () {
976976
expect(snippet).to.not.include('--request POST');
977977
});
978978
});
979+
980+
it('should work when protocolProfileBehavior is null in request settings', function () {
981+
const request = new sdk.Request({
982+
'method': 'POST',
983+
'header': [],
984+
'body': {
985+
'mode': 'graphql',
986+
'graphql': {
987+
'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
988+
'variables': '{\n\t"variable_key": "variable_value"\n}'
989+
}
990+
},
991+
'url': {
992+
'raw': 'https://postman-echo.com/post',
993+
'protocol': 'https',
994+
'host': [
995+
'postman-echo',
996+
'com'
997+
],
998+
'path': [
999+
'post'
1000+
]
1001+
}
1002+
});
1003+
1004+
// this needs to be done here because protocolProfileBehavior is not in collections SDK
1005+
request.protocolProfileBehavior = null;
1006+
1007+
convert(request, { followRedirect: true, followOriginalHttpMethod: true }, function (error, snippet) {
1008+
if (error) {
1009+
expect.fail(null, null, error);
1010+
}
1011+
expect(snippet).to.be.a('string');
1012+
expect(snippet).to.include('--request POST');
1013+
});
1014+
});
9791015
});
9801016
});
9811017
});

0 commit comments

Comments
 (0)