Skip to content

Commit b2f0477

Browse files
author
Ankit Saini
authored
Merge pull request #693 from postmanlabs/release/v1.7.0
Releasing v1.7.0
2 parents abfd151 + 1c1c08e commit b2f0477

File tree

49 files changed

+1288
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1288
-72
lines changed

.github/workflows/integration.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Test
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
49

510
jobs:
611
Unit-Tests:

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ typings/
6464
# next.js build output
6565
.next
6666

67-
out/
67+
# Cargo
68+
target/
6869

70+
# Newman test generated files
71+
out/
6972
newmanResponses.json
7073
dummyFile*.txt
7174
dummyBinaryFile

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v1.7.0 (March 28, 2023)
2+
* Fix for - [#192](https://github.com/postmanlabs/postman-code-generators/issues/192) Added support for Rust reqwest code snippets.
3+
14
v1.6.1 (March 27, 2023)
25
* Fix backlashes being unescaped unnecessarily in cURL codegen
36

@@ -6,6 +9,9 @@ v1.6.0 (March 17, 2023)
69
* Fix for - [#491](https://github.com/postmanlabs/postman-code-generators/issues/491) Added support for kotlin okhttp code snippets.
710
* Refactored code for nodejs-axios util.js.
811

12+
v1.5.1 (March 28, 2023)
13+
* Fix backlashes being escaped unnecessarily in cURL codegen
14+
915
v1.5.0 (March 2, 2023)
1016
* Change minimum supported NodeJS version to 12
1117
* Fix for - [#11049](https://github.com/postmanlabs/postman-app-support/issues/11049) Escape backslash character in raw bodies for curl codegen

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ _Manage all of your organization's APIs in Postman, with the industry's most com
77

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

10-
This module converts a [Postman SDK](https://github.com/postmanlabs/postman-collection) Request Object into a code snippet of chosen language.
10+
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

1212
Every code generator has two identifiers: `language` and `variant`.
1313
* `language` of a code generator is the programming language in which the code snippet is generated.
@@ -36,15 +36,16 @@ List of supported code generators:
3636
| NodeJs | Unirest |
3737
| Objective-C| NSURLSession|
3838
| OCaml | Cohttp |
39-
|PHP | cURL |
40-
|PHP | Guzzle |
41-
|PHP | pecl_http |
42-
|PHP | HTTP_Request2 |
39+
| PHP | cURL |
40+
| PHP | Guzzle |
41+
| PHP | pecl_http |
42+
| PHP | HTTP_Request2 |
4343
| PowerShell | RestMethod |
4444
| Python | http.client |
4545
| Python | Requests |
4646
| R | httr |
4747
| R | RCurl |
48+
| Rust | Reqwest |
4849
| Ruby | Net:HTTP |
4950
| Shell | Httpie |
5051
| Shell | wget |
@@ -170,7 +171,7 @@ var codegen = require('postman-code-generators'), // require postman-code-genera
170171
This function takes in five parameters and returns a callback with error and generated code snippet
171172
* `language` - lang key from the language list returned from getLanguageList function
172173
* `variant` - variant key provided by getLanguageList function
173-
* `request` - [Postman-SDK](https://github.com/postmanlabs/postman-collection) Request Object
174+
* `request` - [Postman-SDK](https://github.com/postmanlabs/postman-collection) Request [Object](https://www.postmanlabs.com/postman-collection/Request.html)
174175
* `options` - Options that can be used to configure generated code snippet. Defaults will be used for the unspecified attributes
175176
* `callback` - callback function with first parameter as error and second parameter as string for code snippet
176177

codegens/curl/test/unit/fixtures/testcollection/collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@
11151115
"response": []
11161116
},
11171117
{
1118-
"name": "PROFIND request",
1118+
"name": "PROPFIND request",
11191119
"request": {
11201120
"method": "PROPFIND",
11211121
"header": [

codegens/golang/test/unit/fixtures/testcollection/collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@
11141114
"response": []
11151115
},
11161116
{
1117-
"name": "PROFIND request",
1117+
"name": "PROPFIND request",
11181118
"request": {
11191119
"method": "PROPFIND",
11201120
"header": [

codegens/http/test/resources/test-collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@
10461046
"response": []
10471047
},
10481048
{
1049-
"name": "PROFIND request",
1049+
"name": "PROPFIND request",
10501050
"request": {
10511051
"method": "PROPFIND",
10521052
"header": [

codegens/js-jquery/test/unit/fixtures/sample_collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@
12401240
"response": []
12411241
},
12421242
{
1243-
"name": "PROFIND request",
1243+
"name": "PROPFIND request",
12441244
"request": {
12451245
"method": "PROPFIND",
12461246
"header": [

codegens/js-jquery/test/unit/fixtures/snippetFixtures.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"UNLINK request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//mockbin.org/request%22%2C%0A%20%20%20%20%22method%22%3A%20%22UNLINK%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%20%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22Content-Type%22%3A%20%22text/plain%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22data%22%3A%20%22Duis%20posuere%20augue%20vel%20cursus%20pharetra.%20In%20luctus%20a%20ex%20nec%20pretium.%20Praesent%20neque%20quam%2C%20tincidunt%20nec%20leo%20eget%2C%20rutrum%20vehicula%20magna.%5CnMaecenas%20consequat%20elementum%20elit%2C%20id%20semper%20sem%20tristique%20et.%20Integer%20pulvinar%20enim%20quis%20consectetur%20interdum%20volutpat.%22%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B",
2121
"LOCK request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//mockbin.org/request%22%2C%0A%20%20%20%20%22method%22%3A%20%22LOCK%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%20%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22Content-Type%22%3A%20%22text/plain%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22data%22%3A%20%22Duis%20posuere%20augue%20vel%20cursus%20pharetra.%20In%20luctus%20a%20ex%20nec%20pretium.%20Praesent%20neque%20quam%2C%20tincidunt%20nec%20leo%20eget%2C%20rutrum%20vehicula%20magna.%5CnMaecenas%20consequat%20elementum%20elit%2C%20id%20semper%20sem%20tristique%20et.%20Integer%20pulvinar%20enim%20quis%20consectetur%20interdum%20volutpat.%22%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B",
2222
"UNLOCK request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//mockbin.org/request%22%2C%0A%20%20%20%20%22method%22%3A%20%22UNLOCK%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B",
23-
"PROFIND request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//mockbin.org/request%22%2C%0A%20%20%20%20%22method%22%3A%20%22PROPFIND%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%20%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22Content-Type%22%3A%20%22text/plain%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22data%22%3A%20%22Duis%20posuere%20augue%20vel%20cursus%20pharetra.%20In%20luctus%20a%20ex%20nec%20pretium.%20Praesent%20neque%20quam%2C%20tincidunt%20nec%20leo%20eget%2C%20rutrum%20vehicula%20magna.%5CnMaecenas%20consequat%20elementum%20elit%2C%20id%20semper%20sem%20tristique%20et.%20Integer%20pulvinar%20enim%20quis%20consectetur%20interdum%20volutpat.%22%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B",
23+
"PROPFIND request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//mockbin.org/request%22%2C%0A%20%20%20%20%22method%22%3A%20%22PROPFIND%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%20%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22Content-Type%22%3A%20%22text/plain%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22data%22%3A%20%22Duis%20posuere%20augue%20vel%20cursus%20pharetra.%20In%20luctus%20a%20ex%20nec%20pretium.%20Praesent%20neque%20quam%2C%20tincidunt%20nec%20leo%20eget%2C%20rutrum%20vehicula%20magna.%5CnMaecenas%20consequat%20elementum%20elit%2C%20id%20semper%20sem%20tristique%20et.%20Integer%20pulvinar%20enim%20quis%20consectetur%20interdum%20volutpat.%22%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B",
2424
"VIEW request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//mockbin.org/request%22%2C%0A%20%20%20%20%22method%22%3A%20%22VIEW%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%20%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22Content-Type%22%3A%20%22text/plain%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22data%22%3A%20%22Duis%20posuere%20augue%20vel%20cursus%20pharetra.%20In%20luctus%20a%20ex%20nec%20pretium.%20Praesent%20neque%20quam%2C%20tincidunt%20nec%20leo%20eget%2C%20rutrum%20vehicula%20magna.%5CnMaecenas%20consequat%20elementum%20elit%2C%20id%20semper%20sem%20tristique%20et.%20Integer%20pulvinar%20enim%20quis%20consectetur%20interdum%20volutpat.%22%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B",
2525
"PURGE Request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io%22%2C%0A%20%20%20%20%22method%22%3A%20%22PURGE%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B",
2626
"COPY Request": "var%20settings%20%3D%20%7B%0A%20%20%20%20%22url%22%3A%20%22https%3A//9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io%22%2C%0A%20%20%20%20%22method%22%3A%20%22COPY%22%2C%0A%20%20%20%20%22timeout%22%3A%20100%2C%0A%7D%3B%0A%0A%24.ajax%28settings%29.done%28function%20%28response%29%20%7B%0A%20%20%20%20console.log%28response%29%3B%0A%7D%29%3B"

codegens/js-xhr/test/unit/fixtures/testcollection/collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@
10551055
"response": []
10561056
},
10571057
{
1058-
"name": "PROFIND request",
1058+
"name": "PROPFIND request",
10591059
"request": {
10601060
"method": "PROPFIND",
10611061
"header": [

codegens/kotlin-okhttp/lib/okhttp.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ const METHODS_WITHOUT_BODY = ['GET', 'HEAD', 'COPY', 'UNLOCK', 'UNLINK', 'PURGE'
1818
function makeSnippet (request, indentString, options) {
1919
let isBodyRequired = !(_.includes(METHODS_WITHOUT_BODY, request.method)),
2020
snippet = 'val client = OkHttpClient',
21-
hasNoOptions = !(options.requestTimeout || options.followRedirects),
22-
requestBody;
21+
hasNoOptions = !(options.requestTimeout || options.followRedirects);
2322

2423
if (hasNoOptions) {
2524
snippet += '()\n';
@@ -30,7 +29,7 @@ function makeSnippet (request, indentString, options) {
3029
snippet += indentString + `.connectTimeout(${options.requestTimeout}, TimeUnit.SECONDS)\n`;
3130
}
3231

33-
if (!options.followRedirect) {
32+
if (_.get(request, 'protocolProfileBehavior.followRedirects', options.followRedirect) === false) {
3433
snippet += indentString + '.followRedirects(false)\n';
3534
}
3635

@@ -73,10 +72,12 @@ function makeSnippet (request, indentString, options) {
7372
formdata: formdataArray
7473
});
7574
}
76-
requestBody = (request.body ? request.body.toJSON() : {});
75+
76+
const contentType = parseRequest.parseContentType(request),
77+
requestBody = (request.body ? request.body.toJSON() : {});
7778
// snippet for creating mediatype object in java based on content-type of request
78-
snippet += `val mediaType = "${parseRequest.parseContentType(request)}".toMediaType()\n`;
79-
snippet += parseRequest.parseBody(requestBody, indentString, options.trimRequestBody);
79+
snippet += `val mediaType = "${contentType}".toMediaType()\n`;
80+
snippet += parseRequest.parseBody(requestBody, indentString, options.trimRequestBody, contentType);
8081
}
8182

8283
snippet += 'val request = Request.Builder()\n';

codegens/kotlin-okhttp/lib/parseRequest.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,38 @@ function parseFormData (requestBody, indentString, trimFields) {
5858
}, '') + indentString + '.build()';
5959
}
6060

61+
/**
62+
* Parses request object and returns kotlin okhttp code snippet for raw body
63+
*
64+
* @param {Object} requestBody - JSON object representing body of request
65+
* @param {Boolean} trimFields - indicates whether to trim fields of body
66+
* @param {String} contentType - content type of request body
67+
*/
68+
function parseRawBody (requestBody, trimFields, contentType) {
69+
if (contentType && contentType.startsWith('application/json')) {
70+
return `val body = ${JSON.stringify(requestBody[requestBody.mode])}.toRequestBody(mediaType)\n`;
71+
}
72+
73+
return `val body = "${sanitize(requestBody[requestBody.mode], trimFields)}".toRequestBody(mediaType)\n`;
74+
}
75+
6176
/**
6277
* parses request object and returns java okhttp code snippet for adding request body
6378
*
6479
* @param {Object} requestBody - JSON object representing body of request
6580
* @param {String} indentString - string for indentation
6681
* @param {Boolean} trimFields - indicates whether to trim fields of body
82+
* @param {String} contentType - content type of request body
83+
*
6784
* @returns {String} - code snippet of java okhttp parsed from request object
6885
*/
69-
function parseBody (requestBody, indentString, trimFields) {
86+
function parseBody (requestBody, indentString, trimFields, contentType) {
7087
if (!_.isEmpty(requestBody)) {
7188
switch (requestBody.mode) {
7289
case 'urlencoded':
7390
return `val body = "${parseUrlencode(requestBody, trimFields)}".toRequestBody(mediaType)\n`;
7491
case 'raw':
75-
return `val body = ${JSON.stringify(requestBody[requestBody.mode])}.toRequestBody(mediaType)\n`;
92+
return parseRawBody(requestBody, trimFields, contentType);
7693
case 'graphql':
7794
// eslint-disable-next-line no-case-declarations
7895
let query = requestBody[requestBody.mode].query,

codegens/kotlin-okhttp/lib/util.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ module.exports = {
1111
if (typeof inputString !== 'string') {
1212
return '';
1313
}
14-
inputString = inputString.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
14+
inputString = inputString
15+
.replace(/\\/g, '\\\\')
16+
.replace(/"/g, '\\"')
17+
.replace(/\$/g, '\\$')
18+
.replace(/\n/g, '\\n')
19+
.replace(/\r/g, '\\r')
20+
.replace(/\t/g, '\\t');
1521
return trim ? inputString.trim() : inputString;
1622

1723
},

codegens/kotlin-okhttp/npm-shrinkwrap.json

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

codegens/kotlin-okhttp/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@postman/codegen-kotlin-okhttp",
33
"version": "0.0.1",
4-
"description": "Converts postman request into kotlin ktor code snippet",
4+
"description": "Converts postman request into kotlin okhttp code snippet",
55
"com_postman_plugin": {
66
"type": "code_generator",
7-
"lang": "kotlin",
8-
"variant": "Ktor",
9-
"syntax_mode": "java"
7+
"lang": "Kotlin",
8+
"variant": "Okhttp",
9+
"syntax_mode": "kotlin"
1010
},
1111
"main": "index.js",
1212
"directories": {

codegens/kotlin-okhttp/test/unit/validation.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('package.json', function () {
1111
expect(package.com_postman_plugin.type).to.equal('code_generator');
1212
expect(package.com_postman_plugin.lang).to.be.a('string');
1313
expect(package.com_postman_plugin.variant).to.be.a('string');
14-
expect(package.com_postman_plugin.syntax_mode).to.be.equal('java');
14+
expect(package.com_postman_plugin.syntax_mode).to.be.equal('kotlin');
1515
});
1616
it('should have main property with relative path to object with convert property', function () {
1717
var languageModule;

codegens/libcurl/test/unit/fixtures/testcollection/collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@
11411141
"response": []
11421142
},
11431143
{
1144-
"name": "PROFIND request",
1144+
"name": "PROPFIND request",
11451145
"request": {
11461146
"method": "PROPFIND",
11471147
"header": [

codegens/nodejs-native/npm-shrinkwrap.json

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

codegens/nodejs-native/test/unit/fixtures/testcollection/collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@
11761176
"response": []
11771177
},
11781178
{
1179-
"name": "PROFIND request",
1179+
"name": "PROPFIND request",
11801180
"request": {
11811181
"method": "PROPFIND",
11821182
"header": [

codegens/php-guzzle/test/unit/fixtures/sample_collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@
12361236
"response": []
12371237
},
12381238
{
1239-
"name": "PROFIND request",
1239+
"name": "PROPFIND request",
12401240
"request": {
12411241
"method": "PROPFIND",
12421242
"header": [

codegens/php-pecl-http/test/unit/fixtures/sample_collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@
12361236
"response": []
12371237
},
12381238
{
1239-
"name": "PROFIND request",
1239+
"name": "PROPFIND request",
12401240
"request": {
12411241
"method": "PROPFIND",
12421242
"header": [

codegens/r-httr/test/unit/fixtures/sample_collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@
12381238
"response": []
12391239
},
12401240
{
1241-
"name": "PROFIND request",
1241+
"name": "PROPFIND request",
12421242
"request": {
12431243
"method": "PROPFIND",
12441244
"header": [

codegens/r-rcurl/test/unit/fixtures/sample_collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@
12361236
"response": []
12371237
},
12381238
{
1239-
"name": "PROFIND request",
1239+
"name": "PROPFIND request",
12401240
"request": {
12411241
"method": "PROPFIND",
12421242
"header": [

0 commit comments

Comments
 (0)