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
Next Next commit
typescript-axios: Added possibility to add custom axios instance.
This comes in handy if you want to use mocks in tests.
  • Loading branch information
Sebastian Rühl committed Oct 19, 2018
commit a0a94709f167df51903a830b4aa343ef2fdcd392
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import * as url from "url";
import { Configuration } from "./configuration";
import axios, { AxiosPromise } from 'axios';
import globalAxios, { AxiosPromise, AxiosInstance } from 'axios';

const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");

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

{{/operation}}
}
Expand Down Expand Up @@ -342,11 +345,12 @@ 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) {
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(this.basePath);
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);
}

{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3-SNAPSHOT
3.3.2-SNAPSHOT
Loading