postman-code-generators
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -5,2 +5,8 @@ # Postman Code Generators Changelog | ||
## [v1.9.0] - 2024-01-18 | ||
### Fixed | ||
- Fix for - [#10139](https://github.com/postmanlabs/postman-app-support/issues/10139) Modify Swift codegen to work with multipart/form-data format, used for video file upload | ||
## [v1.8.0] - 2023-06-27 | ||
@@ -144,4 +150,6 @@ | ||
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.8.0...HEAD | ||
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.9.0...HEAD | ||
[v1.9.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.8.0...v1.9.0 | ||
[v1.8.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.7.2...v1.8.0 | ||
@@ -148,0 +156,0 @@ |
@@ -27,3 +27,3 @@ var _ = require('./lodash'), | ||
function parseURLEncodedBody (body, trim) { | ||
var bodySnippet = 'var urlencoded = new URLSearchParams();\n'; | ||
var bodySnippet = 'const urlencoded = new URLSearchParams();\n'; | ||
_.forEach(body, function (data) { | ||
@@ -44,3 +44,3 @@ if (!data.disabled) { | ||
function parseFormData (body, trim) { | ||
var bodySnippet = 'var formdata = new FormData();\n'; | ||
var bodySnippet = 'const formdata = new FormData();\n'; | ||
_.forEach(body, function (data) { | ||
@@ -70,3 +70,3 @@ if (!data.disabled) { | ||
function parseRawBody (body, trim, contentType, indentString) { | ||
var bodySnippet = 'var raw = '; | ||
var bodySnippet = 'const raw = '; | ||
// Match any application type whose underlying structure is json | ||
@@ -107,3 +107,3 @@ // For example application/vnd.api+json | ||
} | ||
bodySnippet = 'var graphql = JSON.stringify({\n'; | ||
bodySnippet = 'const graphql = JSON.stringify({\n'; | ||
bodySnippet += `${indentString}query: "${sanitize(query, trim)}",\n`; | ||
@@ -120,3 +120,3 @@ bodySnippet += `${indentString}variables: ${JSON.stringify(graphqlVariables)}\n})`; | ||
function parseFileData () { | ||
var bodySnippet = 'var file = "<file contents here>";\n'; | ||
var bodySnippet = 'const file = "<file contents here>";\n'; | ||
return bodySnippet; | ||
@@ -162,3 +162,3 @@ } | ||
if (!_.isEmpty(headers)) { | ||
headerSnippet = 'var myHeaders = new Headers();\n'; | ||
headerSnippet = 'const myHeaders = new Headers();\n'; | ||
headers = _.reject(headers, 'disabled'); | ||
@@ -218,2 +218,9 @@ _.forEach(headers, function (header) { | ||
description: 'Remove white space and additional lines that may affect the server\'s response' | ||
}, | ||
{ | ||
name: 'Use async/await', | ||
id: 'asyncAwaitEnabled', | ||
type: 'boolean', | ||
default: false, | ||
description: 'Modifies code snippet to use async/await' | ||
} | ||
@@ -248,3 +255,2 @@ ]; | ||
optionsSnippet = '', | ||
timeoutSnippet = '', | ||
fetchSnippet = ''; | ||
@@ -305,4 +311,8 @@ indent = indent.repeat(options.indentCount); | ||
optionsSnippet = `var requestOptions = {\n${indent}`; | ||
optionsSnippet += `method: '${request.method}',\n${indent}`; | ||
if (options.requestTimeout > 0) { | ||
codeSnippet += 'const controller = new AbortController();\n'; | ||
codeSnippet += `const timerId = setTimeout(() => controller.abort(), ${options.requestTimeout});\n`; | ||
} | ||
optionsSnippet = `const requestOptions = {\n${indent}`; | ||
optionsSnippet += `method: "${request.method}",\n${indent}`; | ||
if (headerSnippet !== '') { | ||
@@ -317,26 +327,35 @@ optionsSnippet += `headers: myHeaders,\n${indent}`; | ||
} | ||
optionsSnippet += `redirect: '${redirectMode(options.followRedirect)}'\n};\n`; | ||
if (options.requestTimeout > 0) { | ||
optionsSnippet += `signal: controller.signal,\n${indent}`; | ||
} | ||
optionsSnippet += `redirect: "${redirectMode(options.followRedirect)}"\n};\n`; | ||
codeSnippet += optionsSnippet + '\n'; | ||
fetchSnippet = `fetch("${sanitize(request.url.toString())}", requestOptions)\n${indent}`; | ||
fetchSnippet += `.then(response => response.text())\n${indent}`; | ||
fetchSnippet += `.then(result => console.log(result))\n${indent}`; | ||
fetchSnippet += '.catch(error => console.log(\'error\', error));'; | ||
if (options.requestTimeout > 0) { | ||
timeoutSnippet = `var promise = Promise.race([\n${indent}`; | ||
timeoutSnippet += `fetch('${request.url.toString()}', requestOptions)\n${indent}${indent}`; | ||
timeoutSnippet += `.then(response => response.text()),\n${indent}`; | ||
timeoutSnippet += `new Promise((resolve, reject) =>\n${indent}${indent}`; | ||
timeoutSnippet += `setTimeout(() => reject(new Error('Timeout')), ${options.requestTimeout})\n${indent}`; | ||
timeoutSnippet += ')\n]);\n\n'; | ||
timeoutSnippet += 'promise.then(result => console.log(result)),\n'; | ||
timeoutSnippet += 'promise.catch(error => console.log(error));'; | ||
codeSnippet += timeoutSnippet; | ||
if (options.asyncAwaitEnabled) { | ||
fetchSnippet += `try {\n${indent}`; | ||
fetchSnippet += `const response = await fetch("${sanitize(request.url.toString())}", requestOptions);\n${indent}`; | ||
fetchSnippet += `const result = await response.text();\n${indent}`; | ||
fetchSnippet += 'console.log(result)\n'; | ||
fetchSnippet += `} catch (error) {\n${indent}`; | ||
fetchSnippet += 'console.error(error);\n'; | ||
if (options.requestTimeout > 0) { | ||
fetchSnippet += `} finally {\n${indent}`; | ||
fetchSnippet += 'clearTimeout(timerId);\n'; | ||
} | ||
fetchSnippet += '};'; | ||
} | ||
else { | ||
codeSnippet += fetchSnippet; | ||
fetchSnippet = `fetch("${sanitize(request.url.toString())}", requestOptions)\n${indent}`; | ||
fetchSnippet += `.then((response) => response.text())\n${indent}`; | ||
fetchSnippet += `.then((result) => console.log(result))\n${indent}`; | ||
fetchSnippet += '.catch((error) => console.error(error))'; | ||
if (options.requestTimeout > 0) { | ||
fetchSnippet += `\n${indent}.finally(() => clearTimeout(timerId))`; | ||
} | ||
fetchSnippet += ';'; | ||
} | ||
codeSnippet += fetchSnippet; | ||
callback(null, codeSnippet); | ||
@@ -343,0 +362,0 @@ } |
@@ -22,2 +22,3 @@ # codegen-js-fetch | ||
* `requestTimeout` - Integer denoting time after which the request will bail out in milli-seconds | ||
* `asyncAwaitEnabled` : Boolean denoting whether to use async/await syntax | ||
@@ -24,0 +25,0 @@ * `callback` - callback function with first parameter as error and second parameter as string for code snippet |
@@ -217,2 +217,5 @@ var sanitize = require('./util').sanitize, | ||
} | ||
if (headersData) { | ||
snippet += indentString + 'curl_slist_free_all(headers);\n'; | ||
} | ||
snippet += '}\n'; | ||
@@ -219,0 +222,0 @@ snippet += 'curl_easy_cleanup(curl);\n'; |
@@ -114,11 +114,11 @@ var _ = require('./lodash'), | ||
bodySnippet += 'let boundary = "Boundary-\\(UUID().uuidString)"\n'; | ||
bodySnippet += 'var body = ""\nvar error: Error? = nil\n'; | ||
bodySnippet += 'var body = Data()\nvar error: Error? = nil\n'; | ||
bodySnippet += 'for param in parameters {\n'; | ||
bodySnippet += `${indent}if param["disabled"] != nil { continue }\n`; | ||
bodySnippet += `${indent}let paramName = param["key"]!\n`; | ||
bodySnippet += `${indent}body += "--\\(boundary)\\r\\n"\n`; | ||
bodySnippet += `${indent}body += Data("--\\(boundary)\\r\\n".utf8)\n`; | ||
// eslint-disable-next-line no-useless-escape | ||
bodySnippet += `${indent}body += "Content-Disposition:form-data; name=\\"\\(paramName)\\"\"\n`; | ||
bodySnippet += `${indent}body += Data("Content-Disposition:form-data; name=\\"\\(paramName)\\"\".utf8)\n`; | ||
bodySnippet += `${indent}if param["contentType"] != nil {\n`; | ||
bodySnippet += `${indent.repeat(2)}body += "\\r\\nContent-Type: \\(param["contentType"] as! String)"\n`; | ||
bodySnippet += `${indent.repeat(2)}body += Data("\\r\\nContent-Type: \\(param["contentType"] as! String)".utf8)\n`; | ||
bodySnippet += `${indent}}\n`; | ||
@@ -128,12 +128,17 @@ bodySnippet += `${indent}let paramType = param["type"] as! String\n`; | ||
bodySnippet += `${indent.repeat(2)}let paramValue = param["value"] as! String\n`; | ||
bodySnippet += `${indent.repeat(2)}body += "\\r\\n\\r\\n\\(paramValue)\\r\\n"\n`; | ||
bodySnippet += `${indent.repeat(2)}body += Data("\\r\\n\\r\\n\\(paramValue)\\r\\n".utf8)\n`; | ||
bodySnippet += `${indent}} else {\n`; | ||
bodySnippet += `${indent.repeat(2)}let paramSrc = param["src"] as! String\n`; | ||
bodySnippet += `${indent.repeat(2)}let fileData = try NSData(contentsOfFile: paramSrc, options: []) as Data\n`; | ||
bodySnippet += `${indent.repeat(2)}let fileContent = String(data: fileData, encoding: .utf8)!\n`; | ||
bodySnippet += `${indent.repeat(2)}body += "; filename=\\"\\(paramSrc)\\"\\r\\n"\n`; | ||
bodySnippet += `${indent.repeat(2)} + "Content-Type: \\"content-type header\\"\\r\\n\\r\\n`; | ||
bodySnippet += '\\(fileContent)\\r\\n"\n'; | ||
bodySnippet += `${indent}}\n}\nbody += "--\\(boundary)--\\r\\n";\n`; | ||
bodySnippet += 'let postData = body.data(using: .utf8)'; | ||
bodySnippet += `${indent.repeat(2)}let fileURL = URL(fileURLWithPath: paramSrc)\n`; | ||
bodySnippet += `${indent.repeat(2)}if let fileContent = try? Data(contentsOf: fileURL) {\n`; | ||
bodySnippet += `${indent.repeat(3)}body += Data("; filename=\\"\\(paramSrc)\\"\\r\\n".utf8)\n`; | ||
bodySnippet += `${indent.repeat(3)}body += Data("Content-Type: \\"content-type header\\"\\r\\n".utf8)\n`; | ||
bodySnippet += `${indent.repeat(3)}body += Data("\\r\\n".utf8)\n`; | ||
bodySnippet += `${indent.repeat(3)}body += fileContent\n`; | ||
bodySnippet += `${indent.repeat(3)}body += Data("\\r\\n".utf8)\n`; | ||
bodySnippet += `${indent.repeat(2)}}\n`; | ||
bodySnippet += `${indent}}\n`; | ||
bodySnippet += '}\n'; | ||
bodySnippet += 'body += Data("--\\(boundary)--\\r\\n".utf8);\n'; | ||
bodySnippet += 'let postData = body\n'; | ||
return bodySnippet; | ||
@@ -140,0 +145,0 @@ } |
{ | ||
"name": "postman-code-generators", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "Generates code snippets for a postman collection", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
1715393
489
44870