Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/empty-rooms-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": patch
---

Fix Request parameter being ignored by client methods
4 changes: 2 additions & 2 deletions packages/openapi-fetch/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default function createClient(clientOptions) {

let id;
let options;
let request = new CustomRequest(
let request = new Request(
createFinalURL(schemaPath, { baseUrl: finalBaseUrl, params, querySerializer }),
requestInit,
);
Expand Down Expand Up @@ -143,7 +143,7 @@ export default function createClient(clientOptions) {
id,
});
if (result) {
if (result instanceof CustomRequest) {
if (result instanceof Request) {
request = result;
} else if (result instanceof Response) {
response = result;
Expand Down
22 changes: 21 additions & 1 deletion packages/openapi-fetch/test/common/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe("request", () => {
});

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

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

test("Can use custom Request class", async () => {
// sanity check to make sure the provided fetch function is actually called
expect.assertions(1);

class SpecialRequestImplementation extends Request {}

const customFetch = async (input: Request) => {
// make sure that the request is actually an instance of the custom request we provided
expect(input).instanceOf(SpecialRequestImplementation);
return Promise.resolve(Response.json({ hello: "world" }));
};

const client = createClient<paths>({
baseUrl: "https://fakeurl.example",
fetch: customFetch,
});

await client.GET("/resources", { Request: SpecialRequestImplementation });
});

test("can attach custom properties to request", async () => {
function createCustomFetch(data: any) {
const response = {
Expand Down
Loading