Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript][Fetch] Prefix local vars to prevent conflict with params #6717

Merged
merged 2 commits into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,49 +98,49 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
}
{{/required}}
{{/allParams}}
const path = `{{{path}}}`{{#pathParams}}
const localVarPath = `{{{path}}}`{{#pathParams}}
.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}};
const urlObj = url.parse(path, true);
const requestOptions = Object.assign({ method: '{{httpMethod}}' }, options);
const headerParameter = {} as any;
const queryParameter = {} as any;
const localVarUrlObj = url.parse(localVarPath, true);
const localVarRequestOptions = Object.assign({ method: '{{httpMethod}}' }, options);
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
{{#hasFormParams}}
const formParams = new url.URLSearchParams();
const localVarFormParams = new url.URLSearchParams();
{{/hasFormParams}}

{{#authMethods}}
// authentication {{name}} required
{{#isApiKey}}
{{#isKeyInHeader}}
if (configuration && configuration.apiKey) {
const apiKeyValue = typeof configuration.apiKey === 'function'
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
? configuration.apiKey("{{keyParamName}}")
: configuration.apiKey;
headerParameter["{{keyParamName}}"] = apiKeyValue;
localVarHeaderParameter["{{keyParamName}}"] = localVarApiKeyValue;
}
{{/isKeyInHeader}}
{{#isKeyInQuery}}
if (configuration && configuration.apiKey) {
const apiKeyValue = typeof configuration.apiKey === 'function'
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
? configuration.apiKey("{{keyParamName}}")
: configuration.apiKey;
queryParameter["{{keyParamName}}"] = apiKeyValue;
localVarQueryParameter["{{keyParamName}}"] = localVarApiKeyValue;
}
{{/isKeyInQuery}}
{{/isApiKey}}
{{#isBasic}}
// http basic authentication required
if (configuration && (configuration.username || configuration.password)) {
headerParameter["Authorization"] = "Basic " + btoa(configuration.username + ":" + configuration.password);
localVarHeaderParameter["Authorization"] = "Basic " + btoa(configuration.username + ":" + configuration.password);
}
{{/isBasic}}
{{#isOAuth}}
// oauth required
if (configuration && configuration.accessToken) {
const accessTokenValue = typeof configuration.accessToken === 'function'
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
? configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}])
: configuration.accessToken;
headerParameter["Authorization"] = "Bearer " + accessTokenValue;
localVarHeaderParameter["Authorization"] = "Bearer " + localVarAccessTokenValue;
}
{{/isOAuth}}

Expand All @@ -149,24 +149,24 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{#isListContainer}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
queryParameter['{{baseName}}'] = {{paramName}};
localVarQueryParameter['{{baseName}}'] = {{paramName}};
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
queryParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
localVarQueryParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
{{#isDateTime}}
queryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
localVarQueryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
{{/isDateTime}}
{{^isDateTime}}
{{#isDate}}
queryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
localVarQueryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
{{/isDate}}
{{^isDate}}
queryParameter['{{baseName}}'] = {{paramName}};
localVarQueryParameter['{{baseName}}'] = {{paramName}};
{{/isDate}}
{{/isDateTime}}
}
Expand All @@ -176,12 +176,12 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{#headerParams}}
{{#isListContainer}}
if ({{paramName}}) {
headerParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
localVarHeaderParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined && {{paramName}} !== null) {
headerParameter['{{baseName}}'] = String({{paramName}});
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
}
{{/isListContainer}}

Expand All @@ -191,43 +191,43 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
formParams.append('{{baseName}}', element as any);
localVarFormParams.append('{{baseName}}', element as any);
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
formParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
localVarFormParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
formParams.set('{{baseName}}', {{paramName}} as any);
localVarFormParams.set('{{baseName}}', {{paramName}} as any);
}
{{/isListContainer}}

{{/formParams}}
{{#hasFormParams}}
headerParameter['Content-Type'] = 'application/x-www-form-urlencoded';
localVarHeaderParameter['Content-Type'] = 'application/x-www-form-urlencoded';

{{/hasFormParams}}
{{#bodyParam}}
headerParameter['Content-Type'] = 'application/json';
localVarHeaderParameter['Content-Type'] = 'application/json';

{{/bodyParam}}
urlObj.query = Object.assign({}, urlObj.query, queryParameter, options.query);
localVarUrlObj.query = Object.assign({}, localVarUrlObj.query, localVarQueryParameter, options.query);
// fix override query string Detail: https://stackoverflow.com/a/7517673/1077943
delete urlObj.search;
requestOptions.headers = Object.assign({}, headerParameter, options.headers);
delete localVarUrlObj.search;
localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers);
{{#hasFormParams}}
requestOptions.body = formParams.toString();
localVarRequestOptions.body = localVarFormParams.toString();
{{/hasFormParams}}
{{#bodyParam}}
requestOptions.body = JSON.stringify({{paramName}} || {});
localVarRequestOptions.body = JSON.stringify({{paramName}} || {});
{{/bodyParam}}

return {
url: url.format(urlObj),
options: requestOptions,
url: url.format(localVarUrlObj),
options: localVarRequestOptions,
};
},
{{/operation}}
Expand All @@ -254,9 +254,9 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
* @throws {RequiredError}
*/
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}any{{/returnType}}> {
const fetchArgs = {{classname}}FetchParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
const localVarFetchArgs = {{classname}}FetchParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => {
return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response{{#returnType}}.json(){{/returnType}};
} else {
Expand Down
Loading