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

cURL codegen should work when request has a protocolProfileBehavior with null value #675

Merged
merged 2 commits into from
Feb 22, 2023
Merged
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
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');
});
});
});
});
});