Skip to content
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 @@ -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 @@ -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 @@ -255,9 +255,9 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @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, 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 @@ -271,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 @@ -286,7 +286,7 @@ export const {{classname}}Factory = function (configuration?: Configuration, bas
* @throws {RequiredError}
*/
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(basePath);
return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(axios, basePath);
},
{{/operation}}
};
Expand Down Expand Up @@ -346,7 +346,7 @@ export class {{classname}} extends BaseAPI {
* @memberof {{classname}}
*/
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(this.basePath);
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(this.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
170 changes: 85 additions & 85 deletions samples/client/petstore/typescript-axios/builds/default/api.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3-SNAPSHOT
3.3.2-SNAPSHOT
170 changes: 85 additions & 85 deletions samples/client/petstore/typescript-axios/builds/es6-target/api.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3-SNAPSHOT
3.3.2-SNAPSHOT
170 changes: 85 additions & 85 deletions samples/client/petstore/typescript-axios/builds/with-interfaces/api.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3-SNAPSHOT
3.3.2-SNAPSHOT

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var typescript_axios_petstore_1 = require("@swagger/typescript-axios-petstore");
var axios_1 = require("axios");
describe("PetApi", function () {
function runSuite(description, requestOptions) {
function runSuite(description, requestOptions, customAxiosInstance) {
describe(description, function () {
var api;
var fixture = createTestFixture();
beforeEach(function () {
api = new typescript_axios_petstore_1.PetApi();
api = new typescript_axios_petstore_1.PetApi(undefined, undefined, customAxiosInstance);
});
it("should add and delete Pet", function () {
return api.addPet(fixture, requestOptions).then(function () { });
Expand Down Expand Up @@ -52,6 +53,12 @@ describe("PetApi", function () {
credentials: "include",
mode: "cors"
});
runSuite("without custom axios instance");
runSuite("with custom axios instance", {}, axios_1.default);
runSuite("with custom request options and custom axios instance", {
credentials: "include",
mode: "cors"
}, axios_1.default);
});
function createTestFixture(ts) {
if (ts === void 0) { ts = Date.now(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var typescript_axios_petstore_1 = require("@swagger/typescript-axios-petstore");
var typescript_axios_petstore_2 = require("@swagger/typescript-axios-petstore");
var axios_1 = require("axios");
var config;
before(function () {
config = new typescript_axios_petstore_2.Configuration();
Expand All @@ -18,23 +19,23 @@ before(function () {
config.password = "bar";
});
describe("PetApiFactory", function () {
function runSuite(description, requestOptions) {
function runSuite(description, requestOptions, customAxiosInstance) {
describe(description, function () {
var fixture = createTestFixture();
it("should add and delete Pet", function () {
return typescript_axios_petstore_1.PetApiFactory(config)
return typescript_axios_petstore_1.PetApiFactory(config, undefined, customAxiosInstance)
.addPet(fixture, requestOptions)
.then(function () { });
});
it("should get Pet by ID", function () {
return typescript_axios_petstore_1.PetApiFactory(config)
return typescript_axios_petstore_1.PetApiFactory(config, undefined, customAxiosInstance)
.getPetById(fixture.id, requestOptions)
.then(function (result) {
return chai_1.expect(result.data).to.deep.equal(fixture);
});
});
it("should update Pet by ID", function () {
return typescript_axios_petstore_1.PetApiFactory(config)
return typescript_axios_petstore_1.PetApiFactory(config, undefined, customAxiosInstance)
.getPetById(fixture.id, requestOptions)
.then(function (result) {
result.data.name = "newname";
Expand All @@ -50,10 +51,10 @@ describe("PetApiFactory", function () {
});
});
it("should delete Pet", function () {
return typescript_axios_petstore_1.PetApiFactory(config).deletePet(fixture.id, requestOptions);
return typescript_axios_petstore_1.PetApiFactory(config, undefined, customAxiosInstance).deletePet(fixture.id, requestOptions);
});
it("should not contain deleted Pet", function () {
return typescript_axios_petstore_1.PetApiFactory(config)
return typescript_axios_petstore_1.PetApiFactory(config, undefined, customAxiosInstance)
.getPetById(fixture.id, requestOptions)
.then(function (result) {
return chai_1.expect(result.data).to.not.exist;
Expand All @@ -68,6 +69,12 @@ describe("PetApiFactory", function () {
credentials: "include",
mode: "cors"
});
runSuite("without custom axios instance");
runSuite("with custom axios instance", {}, axios_1.default);
runSuite("with custom request options and custom axios instance", {
credentials: "include",
mode: "cors"
}, axios_1.default);
});
function createTestFixture(ts) {
if (ts === void 0) { ts = Date.now(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var typescript_axios_petstore_1 = require("@swagger/typescript-axios-petstore");
var axios_1 = require("axios");
describe("StoreApi", function () {
function runSuite(description, requestOptions) {
function runSuite(description, requestOptions, customAxiosInstance) {
describe(description, function () {
var api;
beforeEach(function () {
api = new typescript_axios_petstore_1.StoreApi();
api = new typescript_axios_petstore_1.StoreApi(undefined, undefined, customAxiosInstance);
});
it("should get inventory", function () {
return api
Expand All @@ -23,4 +24,10 @@ describe("StoreApi", function () {
credentials: "include",
mode: "cors"
});
runSuite("without custom axios instance");
runSuite("with custom axios instance", {}, axios_1.default);
runSuite("with custom request options and custom axios instance", {
credentials: "include",
mode: "cors"
}, axios_1.default);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var typescript_axios_petstore_1 = require("@swagger/typescript-axios-petstore");
var typescript_axios_petstore_2 = require("@swagger/typescript-axios-petstore");
var axios_1 = require("axios");
var config;
before(function () {
config = new typescript_axios_petstore_2.Configuration();
Expand All @@ -18,10 +19,10 @@ before(function () {
config.password = "bar";
});
describe("StoreApiFactory", function () {
function runSuite(description, requestOptions) {
function runSuite(description, requestOptions, customAxiosInstance) {
describe(description, function () {
it("should get inventory", function () {
return typescript_axios_petstore_1.StoreApiFactory(config)
return typescript_axios_petstore_1.StoreApiFactory(config, undefined, customAxiosInstance)
.getInventory(requestOptions)
.then(function (result) {
chai_1.expect(Object.keys(result.data)).to.not.be.empty;
Expand All @@ -34,4 +35,10 @@ describe("StoreApiFactory", function () {
credentials: "include",
mode: "cors"
});
runSuite("without custom axios instance");
runSuite("with custom axios instance", {}, axios_1.default);
runSuite("with custom request options and custom axios instance", {
credentials: "include",
mode: "cors"
}, axios_1.default);
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect } from "chai";
import { PetApi, Pet, Category } from "@swagger/typescript-axios-petstore";
import { AxiosResponse } from "axios";
import axios, {AxiosInstance, AxiosResponse} from "axios";

describe("PetApi", () => {
function runSuite(description: string, requestOptions?: any): void {
function runSuite(description: string, requestOptions?: any, customAxiosInstance?: AxiosInstance): void {
describe(description, () => {
let api: PetApi;
const fixture: Pet = createTestFixture();

beforeEach(() => {
api = new PetApi();
api = new PetApi(undefined, undefined, customAxiosInstance);
});

it("should add and delete Pet", () => {
Expand Down Expand Up @@ -63,6 +63,15 @@ describe("PetApi", () => {
credentials: "include",
mode: "cors"
});

runSuite("without custom axios instance");

runSuite("with custom axios instance",{}, axios);

runSuite("with custom request options and custom axios instance",{
credentials: "include",
mode: "cors"
}, axios);
});

function createTestFixture(ts = Date.now()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Category
} from "@swagger/typescript-axios-petstore";
import { Configuration } from "@swagger/typescript-axios-petstore";
import { AxiosResponse } from "axios";
import axios, {AxiosInstance, AxiosResponse} from "axios";

let config: Configuration;

Expand All @@ -24,26 +24,26 @@ before(function() {
});

describe("PetApiFactory", () => {
function runSuite(description: string, requestOptions?: any): void {
function runSuite(description: string, requestOptions?: any, customAxiosInstance?: AxiosInstance): void {
describe(description, () => {
const fixture: Pet = createTestFixture();

it("should add and delete Pet", () => {
return PetApiFactory(config)
return PetApiFactory(config, undefined, customAxiosInstance)
.addPet(fixture, requestOptions)
.then(() => {});
});

it("should get Pet by ID", () => {
return PetApiFactory(config)
return PetApiFactory(config, undefined, customAxiosInstance)
.getPetById(fixture.id, requestOptions)
.then((result: AxiosResponse<Pet>) => {
return expect(result.data).to.deep.equal(fixture);
});
});

it("should update Pet by ID", () => {
return PetApiFactory(config)
return PetApiFactory(config, undefined, customAxiosInstance)
.getPetById(fixture.id, requestOptions)
.then((result: AxiosResponse<Pet>) => {
result.data.name = "newname";
Expand All @@ -60,11 +60,11 @@ describe("PetApiFactory", () => {
});

it("should delete Pet", () => {
return PetApiFactory(config).deletePet(fixture.id, requestOptions);
return PetApiFactory(config, undefined, customAxiosInstance).deletePet(fixture.id, requestOptions);
});

it("should not contain deleted Pet", () => {
return PetApiFactory(config)
return PetApiFactory(config, undefined, customAxiosInstance)
.getPetById(fixture.id, requestOptions)
.then(
(result: AxiosResponse<Pet>) => {
Expand All @@ -84,6 +84,15 @@ describe("PetApiFactory", () => {
credentials: "include",
mode: "cors"
});

runSuite("without custom axios instance");

runSuite("with custom axios instance",{}, axios);

runSuite("with custom request options and custom axios instance",{
credentials: "include",
mode: "cors"
}, axios);
});

function createTestFixture(ts = Date.now()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from "chai";
import { StoreApi } from "@swagger/typescript-axios-petstore";
import { AxiosResponse } from "axios";
import axios, {AxiosInstance, AxiosResponse} from "axios";

describe("StoreApi", function() {
function runSuite(description: string, requestOptions?: any): void {
function runSuite(description: string, requestOptions?: any, customAxiosInstance?: AxiosInstance): void {
describe(description, () => {
let api: StoreApi;

beforeEach(function() {
api = new StoreApi();
api = new StoreApi(undefined, undefined, customAxiosInstance);
});

it("should get inventory", function() {
Expand All @@ -27,4 +27,13 @@ describe("StoreApi", function() {
credentials: "include",
mode: "cors"
});

runSuite("without custom axios instance");

runSuite("with custom axios instance",{}, axios);

runSuite("with custom request options and custom axios instance",{
credentials: "include",
mode: "cors"
}, axios);
});
Loading