Skip to content

Commit

Permalink
Merge pull request #776 from postmanlabs/release/v1.14.0
Browse files Browse the repository at this point in the history
Release version v1.14.0
  • Loading branch information
aman-v-singh authored Oct 10, 2024
2 parents e5eb488 + d2c0a51 commit 4c8b85e
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 10 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased]

## [v1.14.0] - 2024-10-10

### Fixed

- 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.

- Fix for - [#540](https://github.com/postmanlabs/postman-code-generators/issues/540) Curl codesnippet's JSON body must follow multiLine option's configuration.

## [v1.13.0] - 2024-09-11

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

[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.13.0...HEAD
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.14.0...HEAD

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

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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _Manage all of your organization's APIs in Postman, with the industry's most com
*Supercharge your API workflow.*
*Modern software is built on APIs. Postman helps you develop APIs faster.*

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

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.

Expand Down Expand Up @@ -52,7 +52,7 @@ List of supported code generators:
| Swift | URLSession |
## Table of contents

- [postman-code-generators ![Build Status](https://travis-ci.com/postmanlabs/postman-code-generators)](#postman-code-generators-)
- [postman-code-generators
- [Table of contents](#table-of-contents)
- [Getting Started](#getting-started)
- [Prerequisite](#prerequisite)
Expand Down
19 changes: 15 additions & 4 deletions codegens/curl/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,20 @@ self = module.exports = {
let rawBody = body.raw.toString(),
isAsperandPresent = _.includes(rawBody, '@'),
// Use the long option if `@` is present in the request body otherwise follow user setting
optionName = isAsperandPresent ? '--data-raw' : form('-d', format);
// eslint-disable-next-line max-len
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType)}${quoteType}`;
optionName = isAsperandPresent ? '--data-raw' : form('-d', format),
sanitizedBody = sanitize(rawBody, trim, quoteType);

if (!multiLine) {
try {
sanitizedBody = JSON.stringify(JSON.parse(sanitizedBody));
}
catch (e) {
// Do nothing
}
}

snippet += indent + `${optionName} ${quoteType}${sanitizedBody}${quoteType}`;

break;
}

Expand Down Expand Up @@ -201,7 +212,7 @@ self = module.exports = {
});
break;
case 'file':
snippet += indent + form('-d', format);
snippet += indent + (format ? '--data-binary' : '-d');
snippet += ` ${quoteType}@${sanitize(body[body.mode].src, trim)}${quoteType}`;
break;
default:
Expand Down
76 changes: 76 additions & 0 deletions codegens/curl/test/unit/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,50 @@ describe('curl convert function', function () {
});
});

it('should return snippet with JSON body in single line if multiline option is false', function () {
request = new Request({
'method': 'POST',
'header': [],
'body': {
'mode': 'raw',
'raw': '{\n "name": "John",\n "type": "names",\n "id": "123sdaw"\n}',
'options': {
'raw': {
'language': 'json'
}
}
},
'url': {
'raw': 'https://postman-echo.com/post',
'protocol': 'https',
'host': [
'postman-echo',
'com'
],
'path': [
'post'
]
}
});
options = {
multiLine: false,
longFormat: false,
lineContinuationCharacter: '\\',
quoteType: 'single',
requestTimeoutInSeconds: 0,
followRedirect: true,
followOriginalHttpMethod: false
};

convert(request, options, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet).to.contain('-d \'{"name":"John","type":"names","id":"123sdaw"}\'');
});
});

it('should return snippet with backslash(\\) character as line continuation ' +
'character for multiline code generation', function () {
request = new Request({
Expand Down Expand Up @@ -1144,5 +1188,37 @@ describe('curl convert function', function () {
});
});
});

it('should use --data-binary when request body type is binary', function () {
var request = new Request({
'method': 'POST',
'header': [],
'body': {
'mode': 'file',
'file': {
'src': 'file-path/collection123.json'
}
},
'url': {
'raw': 'https://postman-echo.com/get',
'protocol': 'https',
'host': [
'postman-echo',
'com'
],
'path': [
'get'
]
}
});

convert(request, { longFormat: true }, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet).to.include('--data-binary \'@file-path/collection123.json\'');
});
});
});
});
7 changes: 6 additions & 1 deletion codegens/python-http.client/lib/python-httpclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ self = module.exports = {
snippet += 'from codecs import encode\n';
}
snippet += '\n';
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
if (request.url.protocol === 'http') {
snippet += `conn = http.client.HTTPConnection("${sanitize(host)}"`;
}
else {
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
}
snippet += url.port ? `, ${request.url.port}` : '';
snippet += options.requestTimeout !== 0 ? `, timeout = ${options.requestTimeout})\n` : ')\n';

Expand Down
23 changes: 23 additions & 0 deletions codegens/python-http.client/test/unit/converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,29 @@ describe('Python-http.client converter', function () {
});
});

it('should generate valid snippets when url uses http protocol', function () {
var request = new Request({
'method': 'GET',
'header': [],
'url': {
'raw': 'http://localhost:3000',
'protocol': 'http',
'host': [
'localhost'
],
'port': '3000'
},
'response': []
});
convert(request, {}, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet).to.include('conn = http.client.HTTPConnection("localhost", 3000)');
});
});

});

describe('parseBody function', function () {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postman-code-generators",
"version": "1.13.0",
"version": "1.14.0",
"description": "Generates code snippets for a postman collection",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 4c8b85e

Please sign in to comment.