Skip to content

Commit 4c8b85e

Browse files
authored
Merge pull request #776 from postmanlabs/release/v1.14.0
Release version v1.14.0
2 parents e5eb488 + d2c0a51 commit 4c8b85e

File tree

8 files changed

+135
-10
lines changed

8 files changed

+135
-10
lines changed

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## [Unreleased]
44

5+
## [v1.14.0] - 2024-10-10
6+
7+
### Fixed
8+
9+
- Fix for - [#5330](https://github.com/postmanlabs/postman-app-support/issues/5330) Added support for usage of --data-binary flag when using long format option for body type binary.
10+
11+
- Fix for - [#540](https://github.com/postmanlabs/postman-code-generators/issues/540) Curl codesnippet's JSON body must follow multiLine option's configuration.
12+
513
## [v1.13.0] - 2024-09-11
614

715
### Fixed
@@ -176,7 +184,9 @@ v1.0.0 (May 29, 2020)
176184
- Add ES6 syntax support for NodeJS Request, NodeJS Native and NodeJS Unirest
177185
- Fix snippet generation for powershell and jquery, where form data params had no type field
178186

179-
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.13.0...HEAD
187+
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.14.0...HEAD
188+
189+
[v1.14.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.13.0...v1.14.0
180190

181191
[v1.13.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.12.0...v1.13.0
182192

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _Manage all of your organization's APIs in Postman, with the industry's most com
55
*Supercharge your API workflow.*
66
*Modern software is built on APIs. Postman helps you develop APIs faster.*
77

8-
# postman-code-generators [![Build Status](https://travis-ci.com/postmanlabs/postman-code-generators.svg?branch=master)](https://travis-ci.com/postmanlabs/postman-code-generators)
8+
# postman-code-generators
99

1010
This module converts a [Postman SDK](https://github.com/postmanlabs/postman-collection) Request [Object](https://www.postmanlabs.com/postman-collection/Request.html) into a code snippet of chosen language.
1111

@@ -52,7 +52,7 @@ List of supported code generators:
5252
| Swift | URLSession |
5353
## Table of contents
5454

55-
- [postman-code-generators ![Build Status](https://travis-ci.com/postmanlabs/postman-code-generators)](#postman-code-generators-)
55+
- [postman-code-generators
5656
- [Table of contents](#table-of-contents)
5757
- [Getting Started](#getting-started)
5858
- [Prerequisite](#prerequisite)

codegens/curl/lib/index.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,20 @@ self = module.exports = {
151151
let rawBody = body.raw.toString(),
152152
isAsperandPresent = _.includes(rawBody, '@'),
153153
// Use the long option if `@` is present in the request body otherwise follow user setting
154-
optionName = isAsperandPresent ? '--data-raw' : form('-d', format);
155-
// eslint-disable-next-line max-len
156-
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType)}${quoteType}`;
154+
optionName = isAsperandPresent ? '--data-raw' : form('-d', format),
155+
sanitizedBody = sanitize(rawBody, trim, quoteType);
156+
157+
if (!multiLine) {
158+
try {
159+
sanitizedBody = JSON.stringify(JSON.parse(sanitizedBody));
160+
}
161+
catch (e) {
162+
// Do nothing
163+
}
164+
}
165+
166+
snippet += indent + `${optionName} ${quoteType}${sanitizedBody}${quoteType}`;
167+
157168
break;
158169
}
159170

@@ -201,7 +212,7 @@ self = module.exports = {
201212
});
202213
break;
203214
case 'file':
204-
snippet += indent + form('-d', format);
215+
snippet += indent + (format ? '--data-binary' : '-d');
205216
snippet += ` ${quoteType}@${sanitize(body[body.mode].src, trim)}${quoteType}`;
206217
break;
207218
default:

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

+76
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,50 @@ describe('curl convert function', function () {
289289
});
290290
});
291291

292+
it('should return snippet with JSON body in single line if multiline option is false', function () {
293+
request = new Request({
294+
'method': 'POST',
295+
'header': [],
296+
'body': {
297+
'mode': 'raw',
298+
'raw': '{\n "name": "John",\n "type": "names",\n "id": "123sdaw"\n}',
299+
'options': {
300+
'raw': {
301+
'language': 'json'
302+
}
303+
}
304+
},
305+
'url': {
306+
'raw': 'https://postman-echo.com/post',
307+
'protocol': 'https',
308+
'host': [
309+
'postman-echo',
310+
'com'
311+
],
312+
'path': [
313+
'post'
314+
]
315+
}
316+
});
317+
options = {
318+
multiLine: false,
319+
longFormat: false,
320+
lineContinuationCharacter: '\\',
321+
quoteType: 'single',
322+
requestTimeoutInSeconds: 0,
323+
followRedirect: true,
324+
followOriginalHttpMethod: false
325+
};
326+
327+
convert(request, options, function (error, snippet) {
328+
if (error) {
329+
expect.fail(null, null, error);
330+
}
331+
expect(snippet).to.be.a('string');
332+
expect(snippet).to.contain('-d \'{"name":"John","type":"names","id":"123sdaw"}\'');
333+
});
334+
});
335+
292336
it('should return snippet with backslash(\\) character as line continuation ' +
293337
'character for multiline code generation', function () {
294338
request = new Request({
@@ -1144,5 +1188,37 @@ describe('curl convert function', function () {
11441188
});
11451189
});
11461190
});
1191+
1192+
it('should use --data-binary when request body type is binary', function () {
1193+
var request = new Request({
1194+
'method': 'POST',
1195+
'header': [],
1196+
'body': {
1197+
'mode': 'file',
1198+
'file': {
1199+
'src': 'file-path/collection123.json'
1200+
}
1201+
},
1202+
'url': {
1203+
'raw': 'https://postman-echo.com/get',
1204+
'protocol': 'https',
1205+
'host': [
1206+
'postman-echo',
1207+
'com'
1208+
],
1209+
'path': [
1210+
'get'
1211+
]
1212+
}
1213+
});
1214+
1215+
convert(request, { longFormat: true }, function (error, snippet) {
1216+
if (error) {
1217+
expect.fail(null, null, error);
1218+
}
1219+
expect(snippet).to.be.a('string');
1220+
expect(snippet).to.include('--data-binary \'@file-path/collection123.json\'');
1221+
});
1222+
});
11471223
});
11481224
});

codegens/python-http.client/lib/python-httpclient.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ self = module.exports = {
140140
snippet += 'from codecs import encode\n';
141141
}
142142
snippet += '\n';
143-
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
143+
if (request.url.protocol === 'http') {
144+
snippet += `conn = http.client.HTTPConnection("${sanitize(host)}"`;
145+
}
146+
else {
147+
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
148+
}
144149
snippet += url.port ? `, ${request.url.port}` : '';
145150
snippet += options.requestTimeout !== 0 ? `, timeout = ${options.requestTimeout})\n` : ')\n';
146151

codegens/python-http.client/test/unit/converter.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,29 @@ describe('Python-http.client converter', function () {
336336
});
337337
});
338338

339+
it('should generate valid snippets when url uses http protocol', function () {
340+
var request = new Request({
341+
'method': 'GET',
342+
'header': [],
343+
'url': {
344+
'raw': 'http://localhost:3000',
345+
'protocol': 'http',
346+
'host': [
347+
'localhost'
348+
],
349+
'port': '3000'
350+
},
351+
'response': []
352+
});
353+
convert(request, {}, function (error, snippet) {
354+
if (error) {
355+
expect.fail(null, null, error);
356+
}
357+
expect(snippet).to.be.a('string');
358+
expect(snippet).to.include('conn = http.client.HTTPConnection("localhost", 3000)');
359+
});
360+
});
361+
339362
});
340363

341364
describe('parseBody function', function () {

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postman-code-generators",
3-
"version": "1.13.0",
3+
"version": "1.14.0",
44
"description": "Generates code snippets for a postman collection",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)