Skip to content

Commit 0363d83

Browse files
committed
changed to url.toString() for url parsing
1 parent 33a8622 commit 0363d83

File tree

6 files changed

+64
-69
lines changed

6 files changed

+64
-69
lines changed

codegens/golang/lib/index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var _ = require('./lodash'),
1313
* @param {Object} body Raw body data
1414
* @param {boolean} trim trim body option
1515
*/
16-
function parseRawBody (body, trim) {
16+
function parseRawBody(body, trim) {
1717
var bodySnippet;
1818
bodySnippet = `payload := strings.NewReader(\`${sanitizeMultiline(body.toString(), trim)}\`)`;
1919
return bodySnippet;
@@ -25,7 +25,7 @@ function parseRawBody (body, trim) {
2525
* @param {Object} body Raw body data
2626
* @param {boolean} trim trim body option
2727
*/
28-
function parseGraphQL (body, trim) {
28+
function parseGraphQL(body, trim) {
2929
let query = body.query,
3030
graphqlVariables,
3131
bodySnippet;
@@ -48,7 +48,7 @@ function parseGraphQL (body, trim) {
4848
* @param {Object} body URLEncoded Body
4949
* @param {boolean} trim trim body option
5050
*/
51-
function parseURLEncodedBody (body, trim) {
51+
function parseURLEncodedBody(body, trim) {
5252
var payload, bodySnippet;
5353
payload = _.reduce(body, function (accumulator, data) {
5454
if (!data.disabled) {
@@ -68,7 +68,7 @@ function parseURLEncodedBody (body, trim) {
6868
* @param {boolean} trim trim body option
6969
* @param {string} indent indent string
7070
*/
71-
function parseFormData (body, trim, indent) {
71+
function parseFormData(body, trim, indent) {
7272
var bodySnippet = `payload := &bytes.Buffer{}\n${indent}writer := multipart.NewWriter(payload)\n`;
7373
_.forEach(body, function (data, index) {
7474
if (!data.disabled) {
@@ -101,16 +101,16 @@ function parseFormData (body, trim, indent) {
101101
}
102102
});
103103
bodySnippet += `${indent}err := writer.Close()\n${indent}if err != nil ` +
104-
`{\n${indent.repeat(2)}fmt.Println(err)\n` +
105-
`${indent.repeat(2)}return\n${indent}}\n`;
104+
`{\n${indent.repeat(2)}fmt.Println(err)\n` +
105+
`${indent.repeat(2)}return\n${indent}}\n`;
106106
return bodySnippet;
107107
}
108108

109109
/**
110110
* Parses file body from the Request
111111
*
112112
*/
113-
function parseFile () {
113+
function parseFile() {
114114
// var bodySnippet = `payload := &bytes.Buffer{}\n${indent}writer := multipart.NewWriter(payload)\n`;
115115
// isFile = true;
116116
// bodySnippet += `${indent}// add your file name in the next statement in place of path\n`;
@@ -130,7 +130,7 @@ function parseFile () {
130130
* @param {boolean} trim trim body option
131131
* @param {string} indent indent string
132132
*/
133-
function parseBody (body, trim, indent) {
133+
function parseBody(body, trim, indent) {
134134
if (!_.isEmpty(body)) {
135135
switch (body.mode) {
136136
case 'urlencoded':
@@ -156,7 +156,7 @@ function parseBody (body, trim, indent) {
156156
* @param {Object} headers headers from the request.
157157
* @param {string} indent indent string
158158
*/
159-
function parseHeaders (headers, indent) {
159+
function parseHeaders(headers, indent) {
160160
var headerSnippet = '';
161161
if (!_.isEmpty(headers)) {
162162
headers = _.reject(headers, 'disabled');
@@ -245,8 +245,7 @@ self = module.exports = {
245245
codeSnippet += `${indent}"net/http"\n${indent}"io/ioutil"\n)\n\n`;
246246

247247
finalUrl = new sdk.Url(request.url.toString());
248-
// URL encoding each part of Url individually
249-
finalUrl = `${finalUrl.protocol}://${finalUrl.getRemote()}${finalUrl.getPathWithQuery(true)}`;
248+
finalUrl = finalUrl.toString();
250249

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

codegens/golang/test/unit/convert.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Golang convert function', function () {
2727
expect.fail(null, null, error);
2828
}
2929
expect(snippet).to.be.a('string');
30-
expect(snippet).to.include('url := "https://google.com/"');
30+
expect(snippet).to.include('url := "https://google.com"');
3131
expect(snippet).to.include('method := "GET"');
3232
});
3333
});

codegens/js-xhr/lib/index.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var _ = require('./lodash'),
1010
*
1111
* @param {*} body URLEncoded Body
1212
*/
13-
function parseURLEncodedBody (body) {
13+
function parseURLEncodedBody(body) {
1414
var payload = [],
1515
bodySnippet;
1616
_.forEach(body, function (data) {
@@ -29,7 +29,7 @@ function parseURLEncodedBody (body) {
2929
* @param {*} trim trim body option
3030
* @param {String} contentType Content type of the body being sent
3131
*/
32-
function parseRawBody (body, trim, contentType) {
32+
function parseRawBody(body, trim, contentType) {
3333
var bodySnippet = 'var data = ';
3434
// Match any application type whose underlying structure is json
3535
// For example application/vnd.api+json
@@ -56,7 +56,7 @@ function parseRawBody (body, trim, contentType) {
5656
* @param {boolean} trim trim body option
5757
* @param {String} indentString indentation to be added to the snippet
5858
*/
59-
function parseGraphQL (body, trim, indentString) {
59+
function parseGraphQL(body, trim, indentString) {
6060
let query = body.query,
6161
graphqlVariables,
6262
bodySnippet;
@@ -79,7 +79,7 @@ function parseGraphQL (body, trim, indentString) {
7979
* @param {*} body formData Body
8080
* @param {*} trim trim body option
8181
*/
82-
function parseFormData (body, trim) {
82+
function parseFormData(body, trim) {
8383
var bodySnippet = 'var data = new FormData();\n';
8484
_.forEach(body, (data) => {
8585
if (!(data.disabled)) {
@@ -104,7 +104,7 @@ function parseFormData (body, trim) {
104104
* Parses file body from the Request
105105
*
106106
*/
107-
function parseFile () {
107+
function parseFile() {
108108
// var bodySnippet = 'var data = new FormData();\n';
109109
// bodySnippet += `data.append("${sanitize(body.key, trim)}", "${sanitize(body.src, trim)}", `;
110110
// bodySnippet += `"${sanitize(body.key, trim)}");\n`;
@@ -120,7 +120,7 @@ function parseFile () {
120120
* @param {String} indentString indentation to be added to the snippet
121121
* @param {String} contentType Content type of the body being sent
122122
*/
123-
function parseBody (body, trim, indentString, contentType) {
123+
function parseBody(body, trim, indentString, contentType) {
124124
if (!_.isEmpty(body)) {
125125
switch (body.mode) {
126126
case 'urlencoded':
@@ -145,7 +145,7 @@ function parseBody (body, trim, indentString, contentType) {
145145
*
146146
* @param {Object} headers headers from the request.
147147
*/
148-
function parseHeaders (headers) {
148+
function parseHeaders(headers) {
149149
var headerSnippet = '';
150150
if (!_.isEmpty(headers)) {
151151
headers = _.reject(headers, 'disabled');
@@ -161,7 +161,7 @@ function parseHeaders (headers) {
161161
*
162162
* @returns {Array} - Returns an array of option objects
163163
*/
164-
function getOptions () {
164+
function getOptions() {
165165
return [
166166
{
167167
name: 'Set indentation count',
@@ -184,7 +184,7 @@ function getOptions () {
184184
type: 'positiveInteger',
185185
default: 0,
186186
description: 'Set number of milliseconds the request should wait for a response' +
187-
' before timing out (use 0 for infinity)'
187+
' before timing out (use 0 for infinity)'
188188
},
189189
{
190190
name: 'Trim request body fields',
@@ -206,7 +206,7 @@ function getOptions () {
206206
* @param {Number} options.requestTimeout : time in milli-seconds after which request will bail out
207207
* @param {Function} callback - callback function with parameters (error, snippet)
208208
*/
209-
function convert (request, options, callback) {
209+
function convert(request, options, callback) {
210210

211211
if (!_.isFunction(callback)) {
212212
throw new Error('JS-XHR-Converter: callback is not valid function');
@@ -273,8 +273,7 @@ function convert (request, options, callback) {
273273
codeSnippet += `${indent}}\n});\n\n`;
274274

275275
finalUrl = new sdk.Url(request.url.toString());
276-
// URL encoding each part of Url individually
277-
finalUrl = `${finalUrl.protocol}://${finalUrl.getRemote()}${finalUrl.getPathWithQuery(true)}`;
276+
finalUrl = finalUrl.toString();
278277

279278
codeSnippet += `xhr.open("${request.method}", "${finalUrl}");\n`;
280279
if (options.requestTimeout) {

codegens/objective-c/lib/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ var _ = require('./lodash'),
1212
* @param {String} indent indentation required for code snippet
1313
* @param {Boolean} trim indicates whether to trim string or not
1414
*/
15-
function parseRawBody (body, indent, trim) {
15+
function parseRawBody(body, indent, trim) {
1616
var bodySnippet = '';
1717
bodySnippet += 'NSData *postData = [[NSData alloc] initWithData:[@"' + sanitize(body.toString(), trim) + '" ' +
18-
'dataUsingEncoding:NSUTF8StringEncoding]];\n';
18+
'dataUsingEncoding:NSUTF8StringEncoding]];\n';
1919
bodySnippet += '[request setHTTPBody:postData];\n';
2020
return bodySnippet;
2121
}
@@ -27,11 +27,11 @@ function parseRawBody (body, indent, trim) {
2727
* @param {String} indent indentation required for code snippet
2828
* @param {Boolean} trim indicates whether to trim string or not
2929
*/
30-
function parseGraphQLBody (body, indent, trim) {
30+
function parseGraphQLBody(body, indent, trim) {
3131
var bodySnippet = '',
3232
rawBody = JSON.stringify(body);
3333
bodySnippet += 'NSData *postData = [[NSData alloc] initWithData:[@"' + sanitize(rawBody, trim) + '" ' +
34-
'dataUsingEncoding:NSUTF8StringEncoding]];\n';
34+
'dataUsingEncoding:NSUTF8StringEncoding]];\n';
3535
bodySnippet += '[request setHTTPBody:postData];\n';
3636
return bodySnippet;
3737
}
@@ -43,7 +43,7 @@ function parseGraphQLBody (body, indent, trim) {
4343
* @param {String} indent indentation required for code snippet
4444
* @param {Boolean} trim indicates whether to trim string or not
4545
*/
46-
function parseURLEncodedBody (body, indent, trim) {
46+
function parseURLEncodedBody(body, indent, trim) {
4747
let bodySnippet = '',
4848
key,
4949
value,
@@ -54,11 +54,11 @@ function parseURLEncodedBody (body, indent, trim) {
5454
value = trim ? data.value.trim() : data.value;
5555
if (first) {
5656
bodySnippet += 'NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"' +
57-
sanitize(key, true) + '=' + sanitize(value, trim) + '" dataUsingEncoding:NSUTF8StringEncoding]];\n';
57+
sanitize(key, true) + '=' + sanitize(value, trim) + '" dataUsingEncoding:NSUTF8StringEncoding]];\n';
5858
}
5959
else {
6060
bodySnippet += '[postData appendData:[@"&' + sanitize(key, true) + '=' + sanitize(value, trim) +
61-
'" dataUsingEncoding:NSUTF8StringEncoding]];\n';
61+
'" dataUsingEncoding:NSUTF8StringEncoding]];\n';
6262
}
6363
first = false;
6464
}
@@ -74,7 +74,7 @@ function parseURLEncodedBody (body, indent, trim) {
7474
* @param {String} indent indentation required for code snippet
7575
* @param {Boolean} trim indicates whether to trim string or not
7676
*/
77-
function parseFormData (body, indent, trim) {
77+
function parseFormData(body, indent, trim) {
7878
let bodySnippet = '',
7979
formDataArray = [],
8080
key,
@@ -143,7 +143,7 @@ function parseFormData (body, indent, trim) {
143143
* @param {String} indent indentation required for code snippet
144144
* @param {trim} trim indicates whether to trim string or not
145145
*/
146-
function parseBody (body, indent, trim) {
146+
function parseBody(body, indent, trim) {
147147
if (!_.isEmpty(body)) {
148148
switch (body.mode) {
149149
case 'urlencoded':
@@ -170,7 +170,7 @@ function parseBody (body, indent, trim) {
170170
* @param {String} indent indentation required for code snippet
171171
* @param {Boolean} trim indicates whether to trim string or not
172172
*/
173-
function parseHeaders (headersArray, indent, trim) {
173+
function parseHeaders(headersArray, indent, trim) {
174174
var headerString = '',
175175
headerDictionary = [];
176176
if (_.isEmpty(headersArray)) {
@@ -265,8 +265,7 @@ self = module.exports = {
265265
codeSnippet += 'dispatch_semaphore_t sema = dispatch_semaphore_create(0);\n\n';
266266

267267
finalUrl = new sdk.Url(request.url.toString());
268-
// URL encoding each part of Url individually
269-
finalUrl = `${finalUrl.protocol}://${finalUrl.getRemote()}${finalUrl.getPathWithQuery(true)}`;
268+
finalUrl = finalUrl.toString();
270269

271270
codeSnippet += 'NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"' +
272271
finalUrl + '"]\n';
@@ -299,7 +298,7 @@ self = module.exports = {
299298

300299
// if boilerplate is included then two more indent needs to be added in snippet
301300
(options.includeBoilerplate) &&
302-
(codeSnippet = indent + codeSnippet.split('\n').join('\n' + indent) + '\n');
301+
(codeSnippet = indent + codeSnippet.split('\n').join('\n' + indent) + '\n');
303302

304303
callback(null, headerSnippet + codeSnippet + footerSnippet);
305304
},
@@ -328,7 +327,7 @@ self = module.exports = {
328327
// TODO: Find out a way to set infinite timeout.
329328
default: 10000,
330329
description: 'Set number of milliseconds the request should wait for a response' +
331-
' before timing out (use 0 for infinity)'
330+
' before timing out (use 0 for infinity)'
332331
},
333332
{
334333
name: 'Trim request body fields',

0 commit comments

Comments
 (0)