Skip to content

Commit 7527d1e

Browse files
authored
Fix Request parameter being ignored by client methods (#2407)
* Fix typos * Add a test to verify Request parameter is used * Fix Request parameter being ignored by client methods
1 parent 1bf4a95 commit 7527d1e

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.changeset/empty-rooms-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-fetch": patch
3+
---
4+
5+
Fix Request parameter being ignored by client methods

packages/openapi-fetch/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default function createClient(clientOptions) {
109109

110110
let id;
111111
let options;
112-
let request = new CustomRequest(
112+
let request = new Request(
113113
createFinalURL(schemaPath, { baseUrl: finalBaseUrl, params, querySerializer }),
114114
requestInit,
115115
);
@@ -143,7 +143,7 @@ export default function createClient(clientOptions) {
143143
id,
144144
});
145145
if (result) {
146-
if (result instanceof CustomRequest) {
146+
if (result instanceof Request) {
147147
request = result;
148148
} else if (result instanceof Response) {
149149
response = result;

packages/openapi-fetch/test/common/request.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe("request", () => {
296296
});
297297

298298
test("uses provided Request class", async () => {
299-
// santity check to make sure the profided fetch function is actually called
299+
// sanity check to make sure the provided fetch function is actually called
300300
expect.assertions(1);
301301

302302
class SpecialRequestImplementation extends Request {}
@@ -316,6 +316,26 @@ describe("request", () => {
316316
await client.GET("/resources");
317317
});
318318

319+
test("Can use custom Request class", async () => {
320+
// sanity check to make sure the provided fetch function is actually called
321+
expect.assertions(1);
322+
323+
class SpecialRequestImplementation extends Request {}
324+
325+
const customFetch = async (input: Request) => {
326+
// make sure that the request is actually an instance of the custom request we provided
327+
expect(input).instanceOf(SpecialRequestImplementation);
328+
return Promise.resolve(Response.json({ hello: "world" }));
329+
};
330+
331+
const client = createClient<paths>({
332+
baseUrl: "https://fakeurl.example",
333+
fetch: customFetch,
334+
});
335+
336+
await client.GET("/resources", { Request: SpecialRequestImplementation });
337+
});
338+
319339
test("can attach custom properties to request", async () => {
320340
function createCustomFetch(data: any) {
321341
const response = {

0 commit comments

Comments
 (0)