Skip to content

Commit

Permalink
Merge pull request #693 from postmanlabs/release/v1.7.0
Browse files Browse the repository at this point in the history
Releasing v1.7.0
  • Loading branch information
Ankit Saini authored Mar 29, 2023
2 parents abfd151 + 1c1c08e commit b2f0477
Show file tree
Hide file tree
Showing 49 changed files with 1,288 additions and 72 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Test

on: [push, pull_request]
on:
push:
branches:
- develop
- master
pull_request:

jobs:
Unit-Tests:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ typings/
# next.js build output
.next

out/
# Cargo
target/

# Newman test generated files
out/
newmanResponses.json
dummyFile*.txt
dummyBinaryFile
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.7.0 (March 28, 2023)
* Fix for - [#192](https://github.com/postmanlabs/postman-code-generators/issues/192) Added support for Rust reqwest code snippets.

v1.6.1 (March 27, 2023)
* Fix backlashes being unescaped unnecessarily in cURL codegen

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

v1.5.1 (March 28, 2023)
* Fix backlashes being escaped unnecessarily in cURL codegen

v1.5.0 (March 2, 2023)
* Change minimum supported NodeJS version to 12
* Fix for - [#11049](https://github.com/postmanlabs/postman-app-support/issues/11049) Escape backslash character in raw bodies for curl codegen
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _Manage all of your organization's APIs in Postman, with the industry's most com

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
2 changes: 1 addition & 1 deletion codegens/http/test/resources/test-collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
2 changes: 1 addition & 1 deletion codegens/js-jquery/test/unit/fixtures/snippetFixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
13 changes: 7 additions & 6 deletions codegens/kotlin-okhttp/lib/okhttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const METHODS_WITHOUT_BODY = ['GET', 'HEAD', 'COPY', 'UNLOCK', 'UNLINK', 'PURGE'
function makeSnippet (request, indentString, options) {
let isBodyRequired = !(_.includes(METHODS_WITHOUT_BODY, request.method)),
snippet = 'val client = OkHttpClient',
hasNoOptions = !(options.requestTimeout || options.followRedirects),
requestBody;
hasNoOptions = !(options.requestTimeout || options.followRedirects);

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

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

Expand Down Expand Up @@ -73,10 +72,12 @@ function makeSnippet (request, indentString, options) {
formdata: formdataArray
});
}
requestBody = (request.body ? request.body.toJSON() : {});

const contentType = parseRequest.parseContentType(request),
requestBody = (request.body ? request.body.toJSON() : {});
// snippet for creating mediatype object in java based on content-type of request
snippet += `val mediaType = "${parseRequest.parseContentType(request)}".toMediaType()\n`;
snippet += parseRequest.parseBody(requestBody, indentString, options.trimRequestBody);
snippet += `val mediaType = "${contentType}".toMediaType()\n`;
snippet += parseRequest.parseBody(requestBody, indentString, options.trimRequestBody, contentType);
}

snippet += 'val request = Request.Builder()\n';
Expand Down
21 changes: 19 additions & 2 deletions codegens/kotlin-okhttp/lib/parseRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,38 @@ function parseFormData (requestBody, indentString, trimFields) {
}, '') + indentString + '.build()';
}

/**
* Parses request object and returns kotlin okhttp code snippet for raw body
*
* @param {Object} requestBody - JSON object representing body of request
* @param {Boolean} trimFields - indicates whether to trim fields of body
* @param {String} contentType - content type of request body
*/
function parseRawBody (requestBody, trimFields, contentType) {
if (contentType && contentType.startsWith('application/json')) {
return `val body = ${JSON.stringify(requestBody[requestBody.mode])}.toRequestBody(mediaType)\n`;
}

return `val body = "${sanitize(requestBody[requestBody.mode], trimFields)}".toRequestBody(mediaType)\n`;
}

/**
* parses request object and returns java okhttp code snippet for adding request body
*
* @param {Object} requestBody - JSON object representing body of request
* @param {String} indentString - string for indentation
* @param {Boolean} trimFields - indicates whether to trim fields of body
* @param {String} contentType - content type of request body
*
* @returns {String} - code snippet of java okhttp parsed from request object
*/
function parseBody (requestBody, indentString, trimFields) {
function parseBody (requestBody, indentString, trimFields, contentType) {
if (!_.isEmpty(requestBody)) {
switch (requestBody.mode) {
case 'urlencoded':
return `val body = "${parseUrlencode(requestBody, trimFields)}".toRequestBody(mediaType)\n`;
case 'raw':
return `val body = ${JSON.stringify(requestBody[requestBody.mode])}.toRequestBody(mediaType)\n`;
return parseRawBody(requestBody, trimFields, contentType);
case 'graphql':
// eslint-disable-next-line no-case-declarations
let query = requestBody[requestBody.mode].query,
Expand Down
8 changes: 7 additions & 1 deletion codegens/kotlin-okhttp/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ module.exports = {
if (typeof inputString !== 'string') {
return '';
}
inputString = inputString.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
inputString = inputString
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\$/g, '\\$')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/\t/g, '\\t');
return trim ? inputString.trim() : inputString;

},
Expand Down
21 changes: 1 addition & 20 deletions codegens/kotlin-okhttp/npm-shrinkwrap.json

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

8 changes: 4 additions & 4 deletions codegens/kotlin-okhttp/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@postman/codegen-kotlin-okhttp",
"version": "0.0.1",
"description": "Converts postman request into kotlin ktor code snippet",
"description": "Converts postman request into kotlin okhttp code snippet",
"com_postman_plugin": {
"type": "code_generator",
"lang": "kotlin",
"variant": "Ktor",
"syntax_mode": "java"
"lang": "Kotlin",
"variant": "Okhttp",
"syntax_mode": "kotlin"
},
"main": "index.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion codegens/kotlin-okhttp/test/unit/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('package.json', function () {
expect(package.com_postman_plugin.type).to.equal('code_generator');
expect(package.com_postman_plugin.lang).to.be.a('string');
expect(package.com_postman_plugin.variant).to.be.a('string');
expect(package.com_postman_plugin.syntax_mode).to.be.equal('java');
expect(package.com_postman_plugin.syntax_mode).to.be.equal('kotlin');
});
it('should have main property with relative path to object with convert property', function () {
var languageModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
6 changes: 3 additions & 3 deletions codegens/nodejs-native/npm-shrinkwrap.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
2 changes: 1 addition & 1 deletion codegens/r-httr/test/unit/fixtures/sample_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
2 changes: 1 addition & 1 deletion codegens/r-rcurl/test/unit/fixtures/sample_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@
"response": []
},
{
"name": "PROFIND request",
"name": "PROPFIND request",
"request": {
"method": "PROPFIND",
"header": [
Expand Down
Loading

0 comments on commit b2f0477

Please sign in to comment.