Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
typescript-axios: aligned to fetch API for custom instance
  • Loading branch information
Sebastian Rühl committed Oct 22, 2018
commit c7e4f7dabb89e85d843b8f248bbb450cad1f61d8
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface RequestArgs {
export class BaseAPI {
protected configuration: Configuration | undefined;

constructor(configuration?: Configuration, protected basePath: string = BASE_PATH) {
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath || this.basePath;
Expand Down Expand Up @@ -252,13 +252,12 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
{{#allParams}}
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
{{/allParams}}
* @param {*} [options] Override http request option.
* @param {AxiosInstance} [axios] Custom axios instance.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any, axios: AxiosInstance = globalAxios): (basePath?: string) => AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response{{/returnType}}> {
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response{{/returnType}}> {
const localVarAxiosArgs = {{classname}}AxiosParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
return (basePath: string = BASE_PATH) => {
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = Object.assign(localVarAxiosArgs.options, {url: basePath + localVarAxiosArgs.url})
return axios.request(axiosRequestArgs);
};
Expand All @@ -272,7 +271,7 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
* {{&description}}{{/description}}
* @export
*/
export const {{classname}}Factory = function (configuration?: Configuration, basePath?: string) {
export const {{classname}}Factory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
return {
{{#operation}}
/**
Expand All @@ -284,11 +283,10 @@ export const {{classname}}Factory = function (configuration?: Configuration, bas
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
{{/allParams}}
* @param {*} [options] Override http request option.
* @param {AxiosInstance} [axios] Custom axios instance.
* @throws {RequiredError}
*/
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any, axios: AxiosInstance = globalAxios) {
return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options, axios)(basePath);
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(axios, basePath);
},
{{/operation}}
};
Expand All @@ -312,11 +310,10 @@ export interface {{classname}}Interface {
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
{{/allParams}}
* @param {*} [options] Override http request option.
* @param {AxiosInstance} [axios] Custom axios instance.
* @throws {RequiredError}
* @memberof {{classname}}Interface
*/
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any, axios: AxiosInstance = globalAxios): AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}>;
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}>;

{{/operation}}
}
Expand Down Expand Up @@ -345,12 +342,11 @@ export class {{classname}} extends BaseAPI {
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
{{/allParams}}
* @param {*} [options] Override http request option.
* @param {AxiosInstance} [axios] Custom axios instance.
* @throws {RequiredError}
* @memberof {{classname}}
*/
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any, axios: AxiosInstance = globalAxios) {
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options, axios)(this.basePath);
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(this.axios, this.basePath);
}

{{/operation}}
Expand Down
Loading