Skip to content

Commit

Permalink
Enable generating Bearer auth for typescript-axios
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Vanston committed Mar 3, 2019
1 parent 24df02a commit e7666b8
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const COLLECTION_FORMATS = {
};

/**
*
*
* @export
* @interface RequestArgs
*/
Expand All @@ -30,7 +30,7 @@ export interface RequestArgs {
}

/**
*
*
* @export
* @class BaseAPI
*/
Expand All @@ -46,7 +46,7 @@ export class BaseAPI {
};

/**
*
*
* @export
* @class RequiredError
* @extends {Error}
Expand Down Expand Up @@ -123,10 +123,19 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{/isKeyInQuery}}
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
// http basic authentication required
if (configuration && (configuration.username || configuration.password)) {
localVarHeaderParameter["Authorization"] = "Basic " + btoa(configuration.username + ":" + configuration.password);
}
{{/isBasicBasic}}
{{#isBasicBearer}}
// http bearer auth required
if (configuration && (configuration.accessToken || configuration.apiKey)) {
let token = configuration.accessToken || configuration.apiKey;
localVarHeaderParameter["Authorization"] = `Bearer ${token}`;
}
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}
// oauth required
Expand Down Expand Up @@ -224,7 +233,7 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{#bodyParam}}
const needsSerialization = (<any>"{{dataType}}" !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
localVarRequestOptions.data = needsSerialization ? JSON.stringify({{paramName}} || {}) : ({{paramName}} || "");
{{/bodyParam}}
{{/bodyParam}}
return {
url: url.format(localVarUrlObj),
Expand Down Expand Up @@ -258,7 +267,7 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
const localVarAxiosArgs = {{classname}}AxiosParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
return axios.request(axiosRequestArgs);
};
},
{{/operation}}
Expand Down

0 comments on commit e7666b8

Please sign in to comment.