Skip to content

Commit da78b7b

Browse files
committed
fix: pass original fetch response to consumer
1 parent 1f73694 commit da78b7b

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/openapi-typescript/fetch-factory.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ function fetchFactory<Paths>(options?: InitParameters) {
5050

5151
const fetchInit = buildInit(defaultInit, options, headers);
5252
const response = await fetchMethod(url, fetchInit);
53-
return new Response(
54-
[101, 204, 205, 304].includes(response.status) ? null : response.body,
55-
{
56-
status: response.status,
57-
headers: response.headers,
58-
statusText: response.statusText,
59-
}
60-
) as Omit<Response, "json"> & ResponseByStatus<Paths[Path][Method]>;
53+
return response as Omit<Response, "json"> &
54+
ResponseByStatus<Paths[Path][Method]>;
6155
}
6256

6357
return fetcher;

test/openapi-typescript/fetch-factory.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import createFetch from "../../src/openapi-typescript";
22
import { paths, components } from "./test-data/petstore-openapi3";
33
import { IsEqual } from "../test-tools";
4-
import { Readable } from "stream";
5-
6-
const mockedJson = jest.fn(() => ({} as any));
7-
const mockedFetch = jest.fn(
8-
() =>
9-
({
10-
ok: true,
11-
body: Readable.from([`{"hello": "world"}`]),
12-
} as any)
13-
);
14-
global.fetch = jest.fn(() => ({ ok: true, json: mockedJson } as any));
4+
5+
const mockedFetch = jest.fn<any, any>(() => ({
6+
status: 200,
7+
ok: true,
8+
json: () => ({ hello: "world" }),
9+
})) as any;
10+
11+
global.fetch = jest.fn<any, any>(() => ({
12+
status: 200,
13+
ok: true,
14+
json: () => ({ hello: "world" }),
15+
}));
1516

1617
const defaultFetch = createFetch<paths>();
1718

0 commit comments

Comments
 (0)