Skip to content
6 changes: 5 additions & 1 deletion codegens/golang/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('./lodash'),
sdk = require('postman-collection'),
sanitize = require('./util').sanitize,
sanitizeMultiline = require('./util').sanitizeMultiline,
sanitizeOptions = require('./util').sanitizeOptions,
Expand Down Expand Up @@ -243,7 +244,10 @@ self = module.exports = {
}
codeSnippet += `${indent}"net/http"\n${indent}"io/ioutil"\n)\n\n`;

codeSnippet += `func main() {\n\n${indent}url := "${encodeURI(request.url.toString())}"\n`;
finalUrl = new sdk.Url(request.url.toString());
finalUrl = `${finalUrl.protocol ? `${finalUrl.protocol}://` : ''}${finalUrl.getRemote()}${finalUrl.getPathWithQuery(true)}`;

codeSnippet += `func main() {\n\n${indent}url := "${finalUrl}"\n`;
codeSnippet += `${indent}method := "${request.method}"\n\n`;

if (bodySnippet !== '') {
Expand Down
4 changes: 3 additions & 1 deletion codegens/golang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/golang",
"dependencies": {},
"dependencies": {
"postman-collection": "3.6.8"
},
"devDependencies": {},
"engines": {
"node": ">=8"
Expand Down
4 changes: 2 additions & 2 deletions codegens/golang/test/unit/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Golang convert function', function () {
'method': 'GET',
'header': [],
'url': {
'raw': 'https://google.com',
'raw': 'https://google.com/',
'protocol': 'https',
'host': [
'google',
Expand All @@ -27,7 +27,7 @@ describe('Golang convert function', function () {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet).to.include('url := "https://google.com"');
expect(snippet).to.include('url := "https://google.com/"');
expect(snippet).to.include('method := "GET"');
});
});
Expand Down
6 changes: 5 additions & 1 deletion codegens/js-xhr/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('./lodash'),
sdk = require('postman-collection'),
sanitize = require('./util').sanitize,
sanitizeOptions = require('./util').sanitizeOptions,
addFormParam = require('./util').addFormParam,
Expand Down Expand Up @@ -271,7 +272,10 @@ function convert (request, options, callback) {
codeSnippet += `${indent.repeat(2)}console.log(this.responseText);\n`;
codeSnippet += `${indent}}\n});\n\n`;

codeSnippet += `xhr.open("${request.method}", "${encodeURI(request.url.toString())}");\n`;
finalUrl = new sdk.Url(request.url.toString());
finalUrl = `${finalUrl.protocol ? `${finalUrl.protocol}://` : ''}${finalUrl.getRemote()}${finalUrl.getPathWithQuery(true)}`;

codeSnippet += `xhr.open("${request.method}", "${finalUrl}");\n`;
if (options.requestTimeout) {
codeSnippet += `xhr.timeout = ${options.requestTimeout};\n`;
codeSnippet += 'xhr.addEventListener("ontimeout", function(e) {\n';
Expand Down
4 changes: 3 additions & 1 deletion codegens/js-xhr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/js-xhr",
"dependencies": {},
"dependencies": {
"postman-collection": "3.6.8"
},
"engines": {
"node": ">=8"
},
Expand Down
7 changes: 3 additions & 4 deletions codegens/nodejs-native/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function makeSnippet (request, indentString, options) {
snippet,
optionsArray = [],
postData = '',
url, host, path, query;
url, host, query;

if (options.ES6_enabled) {
snippet = 'const ';
Expand Down Expand Up @@ -132,9 +132,8 @@ function makeSnippet (request, indentString, options) {
}


url = sdk.Url.parse(request.url.toString());
url = new sdk.Url(request.url.toString());
host = url.host ? url.host.join('.') : '';
path = url.path ? '/' + url.path.join('/') : '/';
query = url.query ? _.reduce(url.query, (accum, q) => {
accum.push(`${q.key}=${q.value}`);
return accum;
Expand All @@ -152,7 +151,7 @@ function makeSnippet (request, indentString, options) {
if (url.port) {
optionsArray.push(`${indentString}'port': ${url.port}`);
}
optionsArray.push(`${indentString}'path': '${sanitize(path)}${sanitize(encodeURI(query))}'`);
optionsArray.push(`${indentString}'path': '${sanitize(url.getPathWithQuery(true))}'`);
optionsArray.push(parseRequest.parseHeader(request, indentString));
if (options.followRedirect) {
optionsArray.push(indentString + '\'maxRedirects\': 20');
Expand Down
2 changes: 1 addition & 1 deletion codegens/nodejs-native/test/unit/snippet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ describe('nodejs-native convert function', function () {
}
expect(snippet).to.be.a('string');
// eslint-disable-next-line quotes
expect(snippet).to.include("'path': '/get?query1=b\\'b&query2=c%22c'");
expect(snippet).to.include("'path': '/get?query1=b%27b&query2=c%22c'");
});
});

Expand Down
7 changes: 6 additions & 1 deletion codegens/objective-c/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('./lodash'),
sdk = require('postman-collection'),
sanitizeOptions = require('./util').sanitizeOptions,
sanitize = require('./util').sanitize,
addFormParam = require('./util').addFormParam,
Expand Down Expand Up @@ -262,8 +263,12 @@ self = module.exports = {
footerSnippet += '}';
}
codeSnippet += 'dispatch_semaphore_t sema = dispatch_semaphore_create(0);\n\n';

finalUrl = new sdk.Url(request.url.toString());
finalUrl = `${finalUrl.protocol ? `${finalUrl.protocol}://` : ''}${finalUrl.getRemote()}${finalUrl.getPathWithQuery(true)}`;

codeSnippet += 'NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"' +
encodeURI(request.url.toString()) + '"]\n';
sanitize(request.url.toString()) + '"]\n';
codeSnippet += `${indent}cachePolicy:NSURLRequestUseProtocolCachePolicy\n`;
codeSnippet += `${indent}timeoutInterval:${requestTimeout}.0];\n`;

Expand Down
4 changes: 3 additions & 1 deletion codegens/objective-c/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/objective-c",
"dependencies": {},
"dependencies": {
"postman-collection": "3.6.8"
},
"devDependencies": {},
"engines": {
"node": ">=8"
Expand Down
Loading