Skip to content

Release/1.0.2 #368

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

Merged
merged 66 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6d13a76
Remove unnecessary Ruby semicolon
vinibrsl Apr 27, 2020
0c5005e
Removes utf8 encoding from generated snippet (python-requests)
someshkoli May 27, 2020
998febe
Adds Content-Length header to HTTP snippets
someshkoli May 29, 2020
7671c77
Made raw bodies use multiline strings.
tooolbox May 29, 2020
6fb68a1
Adds content length header to all requests having non zero body length
someshkoli May 29, 2020
b29981f
Adds snippet to check err before using res in GoNative
someshkoli Jun 1, 2020
dc92439
Replaces double quote to single quote for body params
someshkoli Jun 22, 2020
ff8de81
Fixed PEP8
Jun 27, 2020
2d795d5
fix: upgrade eslint-plugin-jsdoc from 3.1.3 to 3.15.1
snyk-bot Jun 30, 2020
28bcf99
fix: upgrade chalk from 2.1.0 to 2.4.2
snyk-bot Jun 30, 2020
2a092e3
fix: upgrade eslint-plugin-lodash from 2.4.5 to 2.7.0
snyk-bot Jun 30, 2020
a0e7b16
fix: upgrade shelljs from 0.7.8 to 0.8.4
snyk-bot Jun 30, 2020
af23205
Adds additional err check snippet for read response
someshkoli Jun 30, 2020
208634c
fixes newline formatting for generated snippets
someshkoli Jun 30, 2020
5ddec72
Removes unwanted console logs
someshkoli Jun 30, 2020
d34b151
fix: upgrade mocha from 5.0.3 to 5.2.0
snyk-bot Jul 1, 2020
f5c6fa2
Signal the semaphore on a fail case as well
richardgroves Jul 2, 2020
58eb67b
Update swift.js
richardgroves Jul 2, 2020
bee8f4b
Bump lodash from 4.17.15 to 4.17.19
dependabot[bot] Jul 17, 2020
7cbb64f
Revert "Added PR template (#183)"
amymariaparker2401 Jul 28, 2020
48bec32
Bump elliptic from 6.4.1 to 6.5.3
dependabot[bot] Jul 30, 2020
d25b3dc
remove spaces around equals sign, as by PEP 8 style guide
maxxfrazer Aug 7, 2020
ca86c61
update tests to check for params without spaces
maxxfrazer Aug 10, 2020
a7afb82
fix: package.json & package-lock.json to reduce vulnerabilities
snyk-bot Aug 17, 2020
377d69b
Fix the type of output for http codegen docs
CSALS Aug 27, 2020
d697ec4
fix: upgrade follow-redirects from 1.4.1 to 1.13.0
snyk-bot Sep 1, 2020
c692ab7
Bump yargs-parser from 13.1.0 to 13.1.2
dependabot[bot] Sep 9, 2020
a11a133
Update NodeJs GraphQL query to support multiline string
HuyNVuong Sep 15, 2020
c24a7c4
Merge pull request #336 from postmanlabs/dependabot/npm_and_yarn/yarg…
abhijitkane Sep 17, 2020
9644383
Bump node-fetch from 2.1.1 to 2.6.1 in /codegens/js-fetch
dependabot[bot] Sep 17, 2020
60930b0
Merge pull request #316 from maxxfrazer/develop
abhijitkane Sep 17, 2020
21d3bf0
Merge pull request #323 from CSALS/develop
webholik Sep 28, 2020
02f34b3
Merge pull request #242 from vnbrs/patch-1
webholik Sep 28, 2020
ac221ca
Add return statement if err produced in NewRequest
webholik Sep 28, 2020
f6b64a8
Add return statement in error handling code
webholik Sep 28, 2020
238f9e1
Remove space from end of lines
webholik Sep 28, 2020
e543f8b
Add test to verify error handling in go codegen
webholik Sep 29, 2020
078a44c
Merge pull request #340 from postmanlabs/dependabot/npm_and_yarn/code…
webholik Sep 30, 2020
eb3c39c
Merge pull request #308 from postmanlabs/dependabot/npm_and_yarn/loda…
webholik Sep 30, 2020
b38ecff
Merge pull request #328 from postmanlabs/snyk-upgrade-21de6f582d7272e…
umeshp7 Sep 30, 2020
4a50003
Merge branch 'develop' into snyk-fix-7b2c250faed0aad27c987b826207e815
webholik Sep 30, 2020
5be02e0
Merge pull request #312 from postmanlabs/dependabot/npm_and_yarn/elli…
webholik Sep 30, 2020
9b12873
Merge pull request #321 from postmanlabs/snyk-fix-7b2c250faed0aad27c9…
webholik Sep 30, 2020
a5b689d
Merge branch 'develop' into snyk-upgrade-df1612ca972922a2cf6acead2846…
webholik Sep 30, 2020
5ad9287
Merge pull request #297 from postmanlabs/snyk-upgrade-31993015c4385f4…
webholik Sep 30, 2020
f85ccf6
Merge pull request #298 from postmanlabs/snyk-upgrade-df1612ca972922a…
webholik Sep 30, 2020
94a9efb
Merge pull request #296 from postmanlabs/snyk-upgrade-4d3f1fbe4e18ce8…
webholik Sep 30, 2020
51518c0
Merge pull request #295 from postmanlabs/snyk-upgrade-84c49e97792c438…
webholik Sep 30, 2020
6a239e6
Merge branch 'develop' into snyk-upgrade-76f4a250973dcfc74ebf29571edd…
webholik Sep 30, 2020
df5dcc8
Add space before '=' to comply with PEP8
webholik Sep 30, 2020
9fe832e
Merge pull request #293 from postmanlabs/snyk-upgrade-76f4a250973dcfc…
webholik Sep 30, 2020
98a0e53
Merge pull request #292 from Derad6709/patch-1
webholik Sep 30, 2020
7db2f94
Fix unit test, GET requests should not have a body
webholik Oct 5, 2020
cf4acef
Merge pull request #265 from someshkoli/fix/HTTPcontentlength
webholik Oct 5, 2020
cab17f7
Merge pull request #264 from tooolbox/fix/golang-multiline
webholik Oct 6, 2020
0ddafbd
Merge pull request #260 from someshkoli/fix/pythonrequeststest
webholik Oct 6, 2020
133f80a
Merge pull request #276 from someshkoli/fix/golangerrcheck
umeshp7 Oct 8, 2020
d1cbdf0
Merge pull request #311 from Lees78/revert-183-PR-template
webholik Oct 9, 2020
c4805e5
Merge pull request #299 from richardgroves/patch-1
umeshp7 Oct 9, 2020
3d2c213
Merge pull request #290 from someshkoli/bugfix/quotes-nodejs-request
umeshp7 Oct 9, 2020
f037bcf
Do not sanitize inside backticks
webholik Oct 9, 2020
a65009f
fix: upgrade form-data from 2.3.2 to 2.5.1
snyk-bot Oct 9, 2020
e02e32c
Merge pull request #339 from HuyNVuong/bugfix/nodejs-graphql-query-mu…
umeshp7 Oct 10, 2020
1dc773d
Merge pull request #355 from postmanlabs/snyk-upgrade-6f886d0942530dd…
webholik Oct 12, 2020
9236197
1.0.2
umeshp7 Oct 15, 2020
29f3f69
Changelog for 1.0.2
umeshp7 Oct 15, 2020
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
18 changes: 0 additions & 18 deletions .github/ISSUE_TEMPLATE/Pull_request.md

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v1.0.2 (Oct 15, 2020)
* Fixed spaces around variables and arguments in Python codgen to comply with PEP 8.
* Added Content-Length header to generated HTTP snippets.
* Switched to multiline strings for Raw bodies in Go.
* Stopped manually encoding response bodes in `utf8` for Python-requests.
* Removed unnecessary semicolons at the end of statements in Ruby.
* Fixed wrong name of HTTP codegen in README

v1.0.1 (Jun 29, 2020)
- 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.

Expand Down
20 changes: 14 additions & 6 deletions codegens/golang/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var _ = require('./lodash'),
sanitize = require('./util').sanitize,
sanitizeMultiline = require('./util').sanitizeMultiline,
sanitizeOptions = require('./util').sanitizeOptions,
addFormParam = require('./util').addFormParam,
isFile = false,
Expand All @@ -13,7 +14,7 @@ var _ = require('./lodash'),
*/
function parseRawBody (body, trim) {
var bodySnippet;
bodySnippet = `payload := strings.NewReader("${sanitize(body.toString(), trim)}")`;
bodySnippet = `payload := strings.NewReader(\`${sanitizeMultiline(body.toString(), trim)}\`)`;
return bodySnippet;
}

Expand Down Expand Up @@ -78,8 +79,9 @@ function parseFormData (body, trim, indent) {
errFile${index + 1} := writer.CreateFormFile("${sanitize(data.key, trim)}",` +
`filepath.Base("${data.src}"))\n`;
bodySnippet += `${indent}_, errFile${index + 1} = io.Copy(part${index + 1}, file)\n`;
bodySnippet += `${indent}if errFile${index + 1} !=nil {
\n${indent.repeat(2)}fmt.Println(errFile${index + 1})\n${indent}}\n`;
bodySnippet += `${indent}if errFile${index + 1} != nil {` +
`\n${indent.repeat(2)}fmt.Println(errFile${index + 1})\n` +
`${indent.repeat(2)}return\n${indent}}\n`;
}
else {
bodySnippet += `${indent}_ = writer.WriteField("${sanitize(data.key, trim)}",`;
Expand All @@ -88,7 +90,8 @@ function parseFormData (body, trim, indent) {
}
});
bodySnippet += `${indent}err := writer.Close()\n${indent}if err != nil ` +
`{\n${indent.repeat(2)}fmt.Println(err)\n${indent}}\n`;
`{\n${indent.repeat(2)}fmt.Println(err)\n` +
`${indent.repeat(2)}return\n${indent}}\n`;
return bodySnippet;
}

Expand Down Expand Up @@ -257,7 +260,8 @@ self = module.exports = {
else {
codeSnippet += `${indent}req, err := http.NewRequest(method, url, nil)\n\n`;
}
codeSnippet += `${indent}if err != nil {\n${indent.repeat(2)}fmt.Println(err)\n${indent}}\n`;
codeSnippet += `${indent}if err != nil {\n${indent.repeat(2)}fmt.Println(err)\n`;
codeSnippet += `${indent.repeat(2)}return\n${indent}}\n`;
if (request.body && !request.headers.has('Content-Type')) {
if (request.body.mode === 'file') {
request.addHeader({
Expand All @@ -280,7 +284,11 @@ self = module.exports = {
codeSnippet += `${indent}req.Header.Set("Content-Type", writer.FormDataContentType())\n`;
}
responseSnippet = `${indent}res, err := client.Do(req)\n`;
responseSnippet += `${indent}defer res.Body.Close()\n${indent}body, err := ioutil.ReadAll(res.Body)\n\n`;
responseSnippet += `${indent}if err != nil {\n${indent.repeat(2)}fmt.Println(err)\n`;
responseSnippet += `${indent.repeat(2)}return\n${indent}}\n`;
responseSnippet += `${indent}defer res.Body.Close()\n\n${indent}body, err := ioutil.ReadAll(res.Body)\n`;
responseSnippet += `${indent}if err != nil {\n${indent.repeat(2)}fmt.Println(err)\n`;
responseSnippet += `${indent.repeat(2)}return\n${indent}}\n`;
responseSnippet += `${indent}fmt.Println(string(body))\n}`;

codeSnippet += responseSnippet;
Expand Down
17 changes: 17 additions & 0 deletions codegens/golang/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ module.exports = {

},

/**
* sanitizes input string by handling escape characters eg: converts '''' to '\'\''
* and trim input if required
*
* @param {String} inputString
* @param {Boolean} [trim] - indicates whether to trim string or not
* @returns {String}
*/
sanitizeMultiline: function (inputString, trim) {
if (typeof inputString !== 'string') {
return '';
}
inputString = inputString.replace(/`/g, '`+"`"+`');
return trim ? inputString.trim() : inputString;

},

/**
* sanitizes input options
*
Expand Down
49 changes: 49 additions & 0 deletions codegens/golang/test/unit/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,54 @@ describe('Golang convert function', function () {
expect(snippet).to.include('writer.CreateFormFile("invalid src",filepath.Base("/path/to/file"))');
});
});

it('should add error handling code everytime an error is possible', function () {
var requests = [];
requests.push(new sdk.Request({
'method': 'GET',
'header': [
{
'key': 'foo',
'value': 'bar'
}
],
'url': {
'raw': 'https://example.com',
'protocol': 'http',
'host': [
'example',
'com'
]
}
}));
requests.push(new sdk.Request({
'method': 'POST',
'header': [],
'body': {
'mode': 'raw',
'raw': 'hello world'
},
'url': {
'raw': 'https://postman-echo.com/post',
'protocol': 'https',
'host': [
'postman-echo',
'com'
],
'path': [
'post'
]
}
}));
requests.forEach(function (request) {
convert(request, {}, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet.match('err := ').length).to.be.equal(snippet.match('if err != nil {').length);
});
});
});
});
});
2 changes: 1 addition & 1 deletion codegens/http/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# codegen-http

> Converts Postman-SDK Request into code snippet for cURL.
> Converts Postman-SDK Request into code snippet for RAW HTTP request.

#### Prerequisites
To run Code-Gen, ensure that you have NodeJS >= v8. A copy of the NodeJS installable can be downloaded from
Expand Down
14 changes: 11 additions & 3 deletions codegens/http/lib/code-http-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function getOptions () {
* @returns {Function} returns the snippet with the callback function.
*/
function convert (request, options, callback) {
let snippet = '';
let snippet = '',
body;
options = utils.sanitizeOptions(options, getOptions());
utils.parseURLVariable(request);
snippet = `${request.method} ${utils.getEndPoint(request)} HTTP/1.1\n`;
Expand All @@ -46,6 +47,7 @@ function convert (request, options, callback) {
});
}
}

// The following code handles multiple files in the same formdata param.
// It removes the form data params where the src property is an array of filepath strings
// Splits that array into different form data params with src set as a single filepath string
Expand Down Expand Up @@ -87,9 +89,15 @@ function convert (request, options, callback) {
formdata: formdataArray
});
}
body = utils.getBody(request, options.trimRequestBody);
if (body && body.length !== 0 && !request.headers.has('Content-Length')) {
request.addHeader({
key: 'Content-Length',
value: body.length
});
}
snippet += `${utils.getHeaders(request)}\n`;
snippet += `\n${utils.getBody(request, options.trimRequestBody)}`;

snippet += `\n${body}`;
return callback(null, snippet);
}

Expand Down
2 changes: 1 addition & 1 deletion codegens/http/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function getHeaders (request) {
});
headers = convertPropertyListToString(request.headers, '\n', false);
if (request.body && request.body.mode === 'formdata' && contentTypeIndex < 0) {
headers += `Content-Type: ${formDataHeader}`;
headers += `\nContent-Type: ${formDataHeader}`;
}
return headers;
}
Expand Down
Loading