Skip to content

Commit 40fbece

Browse files
author
Ankit Saini
authored
Release v1.5.0
Release v1.5.0
2 parents 397aa0a + b7853e2 commit 40fbece

File tree

23 files changed

+368
-663
lines changed

23 files changed

+368
-663
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
"object-curly-newline": "off",
230230
"object-curly-spacing": "off",
231231
"object-property-newline": "off",
232-
"one-var": ["error", "always"],
232+
"one-var": ["error", "consecutive"],
233233
"one-var-declaration-per-line": "error",
234234
"operator-assignment": "error",
235235
"operator-linebreak": ["error", "after"],

.github/workflows/integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Setup Node JS
1212
uses: actions/setup-node@v1
1313
with:
14-
node-version: '8.x'
14+
node-version: '12.x'
1515
- name: Install system dependencies
1616
run: npm run cirequirements
1717
- name: Install package dependencies

CHANGELOG.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
v1.5.0 (March 2, 2023)
2+
* Change minimum supported NodeJS version to 12
3+
* Fix for - [#11049](https://github.com/postmanlabs/postman-app-support/issues/11049) Escape backslash character in raw bodies for curl codegen
4+
* Fix for - [#302](https://github.com/postmanlabs/postman-code-generators/issues/302) Add option to use async/await in NodeJS Axios codegen
5+
* Fix for - [#322](https://github.com/postmanlabs/postman-code-generators/issues/322) Use multiline quotes in Powershell to simplify generated code
6+
* Add long form option for -g flag in curl codegen
7+
* Minor Swift codegen improvements
8+
9+
v1.4.1 (February 22, 2023)
10+
* cURL codegen should work when request has a protocolProfileBehavior with null value
11+
112
v1.4.0 (February 6, 2023)
213
* Add support for C# HttpClient Codegen
3-
* Use short options in CURL as long as possible (9511)[https://github.com/postmanlabs/postman-app-support/issues/9511]
4-
* Do not add HTTP method explicitly in CURL when not required (10581)[https://github.com/postmanlabs/postman-app-support/issues/10581]
5-
* Remove usage of semaphore from Swift Codegen (10053)[https://github.com/postmanlabs/postman-app-support/issues/10053]
14+
* Fix for - [#9511](https://github.com/postmanlabs/postman-app-support/issues/9511) - Use short options in CURL as long as possible
15+
* Fix for - [#10581](https://github.com/postmanlabs/postman-app-support/issues/10581) - Do not add HTTP method explicitly in CURL when not required
16+
* Fix for - [#10053](https://github.com/postmanlabs/postman-app-support/issues/10053) - Remove usage of semaphore from Swift Codegen
617

718
v1.3.0 (December 16, 2022)
8-
* Update C# restsharp codegen to support (107)[https://restsharp.dev/v107/]
9-
* Fixes an issue where HTTP code snippet was generating wrong boundaries (11084)[https://github.com/postmanlabs/postman-app-support/issues/11084]
19+
* Update C# restsharp codegen to support [107](https://restsharp.dev/v107/)
20+
* Fix for - [#11084](https://github.com/postmanlabs/postman-app-support/issues/11084) Fixes an issue where HTTP code snippet was generating wrong boundaries
1021
* Fixes an issue with Axios code snippets not including maxBodyLength param
1122

1223
v1.2.1 (April 26, 2022)
@@ -15,8 +26,8 @@ v1.2.1 (April 26, 2022)
1526
v1.2.0 (April 22, 2022)
1627
* Add new codegens - php-guzzle, R-httr, R-rcurl
1728
* Fix issue with pipeline failing due to updated version of RestSharp
18-
* Fix for - [502](https://github.com/postmanlabs/postman-code-generators/issues/502) Allow GET method to have a body in java-okhttp if present in input request
19-
* Fix for - [476](https://github.com/postmanlabs/postman-code-generators/pull/476) Properly escape already escaped double quotes in curl body
29+
* Fix for - [#502](https://github.com/postmanlabs/postman-code-generators/issues/502) Allow GET method to have a body in java-okhttp if present in input request
30+
* Fix for - [#476](https://github.com/postmanlabs/postman-code-generators/pull/476) Properly escape already escaped double quotes in curl body
2031

2132
v1.1.5 (May 10, 2021)
2233
* Fixed an issue with how JSON bodies are shown in code snippets for Ruby, C#, and Dart.
@@ -26,15 +37,15 @@ v1.1.4 (May 6, 2021)
2637

2738
v1.1.3 (Mar 2, 2021)
2839
* Use proper indentation for JSON bodies in Javascript and Nodejs codegens
29-
* Fix for - [445](https://github.com/postmanlabs/postman-code-generators/issues/445) Add proper indentation in nodejs-axios when bodytype is urlencoded
30-
* Fix for - [248](https://github.com/postmanlabs/postman-code-generators/issues/248) Use quoteType everywhere in curl, not just in the url
31-
* Fix for - [454](https://github.com/postmanlabs/postman-code-generators/issues/454) Fix encoding when generating HTTP code snippets
32-
* Fix for - [426](https://github.com/postmanlabs/postman-code-generators/issues/426) Use json.dumps in Python codegens if Content-Type is JSON
40+
* Fix for - [#445](https://github.com/postmanlabs/postman-code-generators/issues/445) Add proper indentation in nodejs-axios when bodytype is urlencoded
41+
* Fix for - [#248](https://github.com/postmanlabs/postman-code-generators/issues/248) Use quoteType everywhere in curl, not just in the url
42+
* Fix for - [#454](https://github.com/postmanlabs/postman-code-generators/issues/454) Fix encoding when generating HTTP code snippets
43+
* Fix for - [#426](https://github.com/postmanlabs/postman-code-generators/issues/426) Use json.dumps in Python codegens if Content-Type is JSON
3344

3445
v1.1.2 (Dec 15, 2020)
35-
* Fix for - [8736](https://github.com/postmanlabs/postman-app-support/issues/8736) Add content type support for individual form-data fields
36-
* Fix for - [8635](https://github.com/postmanlabs/postman-app-support/issues/8635) Use Json.parse for all json like application types
37-
* Fix for - [9212](https://github.com/postmanlabs/postman-app-support/issues/9212) Add semicolon after header key in curl codegen if the value is empty string.
46+
* Fix for - [#8736](https://github.com/postmanlabs/postman-app-support/issues/8736) Add content type support for individual form-data fields
47+
* Fix for - [#8635](https://github.com/postmanlabs/postman-app-support/issues/8635) Use Json.parse for all json like application types
48+
* Fix for - [#9212](https://github.com/postmanlabs/postman-app-support/issues/9212) Add semicolon after header key in curl codegen if the value is empty string.
3849
* Add Newman test for powershell
3950

4051
v1.1.1 (Nov 10, 2020)
@@ -44,19 +55,19 @@ v1.1.1 (Nov 10, 2020)
4455

4556
v1.1.0 (Nov 2, 2020)
4657
* Added support for Dart http
47-
* Fix for - [315](https://github.com/postmanlabs/postman-code-generators/issues/315): Manually parse url provided in the request.
48-
* Fix for - [253](https://github.com/postmanlabs/postman-code-generators/issues/253): Add -g flag to curl if braces ({}) or brackets ([]) are present in the url.
49-
* Fix for - [257](https://github.com/postmanlabs/postman-code-generators/issues/257): Use double quotes to escape semicolon in curl requests
50-
* Fix for - [247](https://github.com/postmanlabs/postman-code-generators/issues/247): Add ContentType to python snippets for multipart/formdata
51-
* Fix for - [186](https://github.com/postmanlabs/postman-code-generators/issues/186): Add ` as line continuation delimiter for curl codegen
52-
* Fix for - [248](https://github.com/postmanlabs/postman-code-generators/issues/248): Add quoteType as an additional option in curl codegen
58+
* Fix for - [#315](https://github.com/postmanlabs/postman-code-generators/issues/315): Manually parse url provided in the request.
59+
* Fix for - [#253](https://github.com/postmanlabs/postman-code-generators/issues/253): Add -g flag to curl if braces ({}) or brackets ([#]) are present in the url.
60+
* Fix for - [#257](https://github.com/postmanlabs/postman-code-generators/issues/257): Use double quotes to escape semicolon in curl requests
61+
* Fix for - [#247](https://github.com/postmanlabs/postman-code-generators/issues/247): Add ContentType to python snippets for multipart/formdata
62+
* Fix for - [#186](https://github.com/postmanlabs/postman-code-generators/issues/186): Add ` as line continuation delimiter for curl codegen
63+
* Fix for - [#248](https://github.com/postmanlabs/postman-code-generators/issues/248): Add quoteType as an additional option in curl codegen
5364
* Fix deadlock in error case in Swift and Objective-C codegens.
54-
* Fix for - [325](https://github.com/postmanlabs/postman-code-generators/issues/325): Use encodeURIComponent instead of escape for urlencoded request body.
55-
* Fix for - [350](https://github.com/postmanlabs/postman-code-generators/issues/350): Sanitize \r in request body.
56-
* Fix for - [366](https://github.com/postmanlabs/postman-code-generators/issues/366): Add support for uploading binary files for multipart/form-data bodies in python-http.client.
57-
* Fix for - [353](https://github.com/postmanlabs/postman-code-generators/issues/353): Add optional import of FoundationNetworking in swift codegen
58-
* Fix for - [284](https://github.com/postmanlabs/postman-code-generators/issues/284): Replace double-quotes by single-quotes in codegen/php-curl
59-
* Fix for - [330](https://github.com/postmanlabs/postman-code-generators/issues/330): Use url.toString method for converting url in shell-httpie codegen
65+
* Fix for - [#325](https://github.com/postmanlabs/postman-code-generators/issues/325): Use encodeURIComponent instead of escape for urlencoded request body.
66+
* Fix for - [#350](https://github.com/postmanlabs/postman-code-generators/issues/350): Sanitize \r in request body.
67+
* Fix for - [#366](https://github.com/postmanlabs/postman-code-generators/issues/366): Add support for uploading binary files for multipart/form-data bodies in python-http.client.
68+
* Fix for - [#353](https://github.com/postmanlabs/postman-code-generators/issues/353): Add optional import of FoundationNetworking in swift codegen
69+
* Fix for - [#284](https://github.com/postmanlabs/postman-code-generators/issues/284): Replace double-quotes by single-quotes in codegen/php-curl
70+
* Fix for - [#330](https://github.com/postmanlabs/postman-code-generators/issues/330): Use url.toString method for converting url in shell-httpie codegen
6071

6172
v1.0.2 (Oct 15, 2020)
6273
* Fixed spaces around variables and arguments in Python codgen to comply with PEP 8.
@@ -67,7 +78,7 @@ v1.0.2 (Oct 15, 2020)
6778
* Fixed wrong name of HTTP codegen in README
6879

6980
v1.0.1 (Jun 29, 2020)
70-
- Fix for - [8674](https://github.com/postmanlabs/postman-app-support/issues/8674): Add URL sanitization for quotes in cURL, Java Unirest, NodeJS Native, Python http.client, and Swift.
81+
- Fix for - [#8674](https://github.com/postmanlabs/postman-app-support/issues/8674): Add URL sanitization for quotes in cURL, Java Unirest, NodeJS Native, Python http.client, and Swift.
7182

7283
v1.0.0 (May 29, 2020)
7384
- Add axios framework support

codegens/curl/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ self = module.exports = {
3636
snippet += ` ${form('-m', format)} ${timeout}`;
3737
}
3838
if ((url.match(/[{[}\]]/g) || []).length > 0) {
39-
snippet += ' -g';
39+
snippet += ` ${form('-g', format)}`;
4040
}
4141
if (multiLine) {
4242
indent = options.indentType === 'Tab' ? '\t' : ' ';
@@ -141,7 +141,7 @@ self = module.exports = {
141141
isAsperandPresent = _.includes(rawBody, '@'),
142142
// Use the long option if `@` is present in the request body otherwise follow user setting
143143
optionName = isAsperandPresent ? '--data-raw' : form('-d', format);
144-
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType)}${quoteType}`;
144+
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType, true)}${quoteType}`;
145145
break;
146146
}
147147

codegens/curl/lib/util.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ var self = module.exports = {
5757
return '--data';
5858
case '-F':
5959
return '--form';
60+
case '-g':
61+
return '--globoff';
6062
default:
6163
return '';
6264
}
@@ -292,12 +294,19 @@ var self = module.exports = {
292294
* @returns {Boolean}
293295
*/
294296
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),
297+
let followRedirect = options.followRedirect,
298+
followOriginalHttpMethod = options.followOriginalHttpMethod,
299+
disableBodyPruning = true,
299300
isBodyEmpty = self.isBodyEmpty(request.body);
300301

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

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

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,41 @@ describe('curl convert function', function () {
3434
});
3535
});
3636

37+
it('should escape backslash in raw bodies', function () {
38+
request = new sdk.Request({
39+
'method': 'POST',
40+
'header': [
41+
{
42+
'key': 'Content-Type',
43+
'value': 'application/json'
44+
}
45+
],
46+
'body': {
47+
'mode': 'raw',
48+
'raw': '{ "foo": "\\" }'
49+
},
50+
'url': {
51+
'raw': 'https://postman-echo.com/post',
52+
'protocol': 'https',
53+
'host': [
54+
'postman-echo',
55+
'com'
56+
],
57+
'path': [
58+
'post'
59+
]
60+
}
61+
});
62+
63+
convert(request, {}, function (error, snippet) {
64+
if (error) {
65+
expect.fail(null, null, error);
66+
}
67+
68+
expect(snippet).to.contain('{ "foo": "\\\\" }');
69+
});
70+
});
71+
3772
it('should return snippet with url in single quote(\')', function () {
3873
request = new sdk.Request({
3974
'method': 'POST',
@@ -230,7 +265,7 @@ describe('curl convert function', function () {
230265
']world',
231266
'world}'
232267
].forEach(function (value) {
233-
request = new sdk.Request({
268+
const request = new sdk.Request({
234269
'method': 'GET',
235270
'url': {
236271
'raw': `http://example.com?hello=${value}`,
@@ -253,6 +288,12 @@ describe('curl convert function', function () {
253288
}
254289
expect(snippet).to.include('-g');
255290
});
291+
convert(request, { longFormat: true }, function (error, snippet) {
292+
if (error) {
293+
expect.fail(null, null, error);
294+
}
295+
expect(snippet).to.include('--globoff');
296+
});
256297
});
257298
});
258299

@@ -941,6 +982,42 @@ describe('curl convert function', function () {
941982
expect(snippet).to.not.include('--request POST');
942983
});
943984
});
985+
986+
it('should work when protocolProfileBehavior is null in request settings', function () {
987+
const request = new sdk.Request({
988+
'method': 'POST',
989+
'header': [],
990+
'body': {
991+
'mode': 'graphql',
992+
'graphql': {
993+
'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
994+
'variables': '{\n\t"variable_key": "variable_value"\n}'
995+
}
996+
},
997+
'url': {
998+
'raw': 'https://postman-echo.com/post',
999+
'protocol': 'https',
1000+
'host': [
1001+
'postman-echo',
1002+
'com'
1003+
],
1004+
'path': [
1005+
'post'
1006+
]
1007+
}
1008+
});
1009+
1010+
// this needs to be done here because protocolProfileBehavior is not in collections SDK
1011+
request.protocolProfileBehavior = null;
1012+
1013+
convert(request, { followRedirect: true, followOriginalHttpMethod: true }, function (error, snippet) {
1014+
if (error) {
1015+
expect.fail(null, null, error);
1016+
}
1017+
expect(snippet).to.be.a('string');
1018+
expect(snippet).to.include('--request POST');
1019+
});
1020+
});
9441021
});
9451022
});
9461023
});

codegens/nodejs-axios/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Convert function will take three parameters
1818
* `requestTimeout` : Integer denoting time after which the request will bail out in milli-seconds
1919
* `trimRequestBody` : Trim request body fields
2020
* `followRedirect` : Boolean denoting whether to redirect a request
21+
* `asyncAwaitEnabled` : Boolean denoting whether to use async/await syntax
2122

2223
* `callback`- callback function with first parameter as error and second parameter as string for code snippet
2324

@@ -27,7 +28,7 @@ var request = new sdk.Request('www.google.com'), //using postman sdk to create
2728
options = {
2829
indentType: 'Space',
2930
indentCount: 2,
30-
ES6_enabled: true
31+
asyncAwaitEnabled: true
3132
};
3233
convert(request, options, function(error, snippet) {
3334
if (error) {

0 commit comments

Comments
 (0)