Skip to content

Commit

Permalink
Bugfix/6750 name clash between npm request and parameter called reque…
Browse files Browse the repository at this point in the history
…st (#6753)

* rename request to $request

* update examples files

* rename $request to localVarRequest

* rename oder variables to localVar...
  • Loading branch information
pgrm authored and wing328 committed Oct 20, 2017
1 parent f0b7dae commit 8a5c361
Show file tree
Hide file tree
Showing 3 changed files with 595 additions and 595 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{>licenseInfo}}
import request = require('request');
import localVarRequest = require('request');
import http = require('http');
{{^supportsES6}}
import Promise = require('bluebird');
Expand Down Expand Up @@ -216,13 +216,13 @@ export interface Authentication {
/**
* Apply authentication settings to header and query params.
*/
applyToRequest(requestOptions: request.Options): void;
applyToRequest(requestOptions: localVarRequest.Options): void;
}

export class HttpBasicAuth implements Authentication {
public username: string;
public password: string;
applyToRequest(requestOptions: request.Options): void {
applyToRequest(requestOptions: localVarRequest.Options): void {
requestOptions.auth = {
username: this.username, password: this.password
}
Expand All @@ -235,7 +235,7 @@ export class ApiKeyAuth implements Authentication {
constructor(private location: string, private paramName: string) {
}

applyToRequest(requestOptions: request.Options): void {
applyToRequest(requestOptions: localVarRequest.Options): void {
if (this.location == "query") {
(<any>requestOptions.qs)[this.paramName] = this.apiKey;
} else if (this.location == "header" && requestOptions && requestOptions.headers) {
Expand All @@ -247,7 +247,7 @@ export class ApiKeyAuth implements Authentication {
export class OAuth implements Authentication {
public accessToken: string;
applyToRequest(requestOptions: request.Options): void {
applyToRequest(requestOptions: localVarRequest.Options): void {
if (requestOptions && requestOptions.headers) {
requestOptions.headers["Authorization"] = "Bearer " + this.accessToken;
}
Expand All @@ -257,7 +257,7 @@ export class OAuth implements Authentication {
export class VoidAuth implements Authentication {
public username: string;
public password: string;
applyToRequest(_: request.Options): void {
applyToRequest(_: localVarRequest.Options): void {
// Do nothing
}
}
Expand Down Expand Up @@ -371,9 +371,9 @@ export class {{classname}} {
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};
let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
let formParams: any = {};
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarFormParams: any = {};

{{#allParams}}
{{#required}}
Expand All @@ -386,34 +386,34 @@ export class {{classname}} {
{{/allParams}}
{{#queryParams}}
if ({{paramName}} !== undefined) {
queryParameters['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
localVarQueryParameters['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
}

{{/queryParams}}
{{#headerParams}}
headerParams['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
localVarHeaderParams['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
{{/headerParams}}

let useFormData = false;
let localVarUseFormData = false;

{{#formParams}}
if ({{paramName}} !== undefined) {
{{#isFile}}
formParams['{{baseName}}'] = {{paramName}};
localVarFormParams['{{baseName}}'] = {{paramName}};
{{/isFile}}
{{^isFile}}
formParams['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
localVarFormParams['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
{{/isFile}}
}
{{#isFile}}
useFormData = true;
localVarUseFormData = true;
{{/isFile}}

{{/formParams}}
let requestOptions: request.Options = {
let localVarRequestOptions: localVarRequest.Options = {
method: '{{httpMethod}}',
qs: queryParameters,
headers: headerParams,
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
{{^isResponseFile}}
Expand All @@ -428,20 +428,20 @@ export class {{classname}} {
};

{{#authMethods}}
this.authentications.{{name}}.applyToRequest(requestOptions);
this.authentications.{{name}}.applyToRequest(localVarRequestOptions);

{{/authMethods}}
this.authentications.default.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(localVarRequestOptions);

if (Object.keys(formParams).length) {
if (useFormData) {
(<any>requestOptions).formData = formParams;
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).formData = localVarFormParams;
} else {
requestOptions.form = formParams;
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise<{ response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>((resolve, reject) => {
request(requestOptions, (error, response, body) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
Expand Down
Loading

0 comments on commit 8a5c361

Please sign in to comment.