Skip to content

Commit 1782758

Browse files
committed
Fix: Allow overriding http api with options
1 parent 29804b0 commit 1782758

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

modules/openapi-generator/src/main/resources/typescript/types/ObservableAPI.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Observable{{classname}} {
7272
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx)));
7373
}
7474

75-
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))).
75+
return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => _config.httpApi.send(ctx))).
7676
pipe(mergeMap((response: ResponseContext) => {
7777
let middlewarePostObservable = of(response);
7878
for (const middleware of _config.middleware.reverse()) {

samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as petstore from 'ts-petstore-client'
2-
import { Middleware, RequestContext, ResponseContext } from 'ts-petstore-client'
2+
import { Middleware, RequestContext, ResponseContext, wrapHttpLibrary } from 'ts-petstore-client'
33

44
import { expect } from "chai";
55
import * as fs from 'fs';
@@ -158,6 +158,31 @@ describe("PetApi", () => {
158158
expect(callTimeAppendedRightPet).to.deep.equal(pet);
159159
})
160160

161+
it("should override http api from option", async () => {
162+
const configuration = petstore.createConfiguration();
163+
const petApi = new petstore.PetApi(configuration);
164+
165+
let overriddenCalls = 0;
166+
const mockHttpLibrary = {
167+
async send(): Promise<ResponseContext> {
168+
overriddenCalls++;
169+
return new ResponseContext(200, {
170+
"content-type": "application/json",
171+
}, {
172+
async text() {
173+
return "{}";
174+
},
175+
async binary() {
176+
throw new Error("Unexpected usage of mock body as binary.");
177+
}
178+
});
179+
}
180+
};
181+
182+
await petApi.getPetById(pet.id, { httpApi: wrapHttpLibrary(mockHttpLibrary) });
183+
expect(overriddenCalls).to.equal(1);
184+
})
185+
161186
it("deletePet", async () => {
162187
await petApi.deletePet(pet.id);
163188
let deletedPet;

0 commit comments

Comments
 (0)