Skip to content

Commit 75c335a

Browse files
committed
- Added support for node-fetch 3.0.0 (breaking change)
1 parent 17d3c74 commit 75c335a

File tree

7 files changed

+29
-33
lines changed

7 files changed

+29
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.9.3",
3+
"version": "0.10.0",
44
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",

src/templates/core/node/getHeaders.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
2929
if (options.body) {
3030
if (options.mediaType) {
3131
headers.append('Content-Type', options.mediaType);
32-
} else if (isBinary(options.body)) {
32+
} else if (isBlob(options.body)) {
3333
headers.append('Content-Type', 'application/octet-stream');
3434
} else if (isString(options.body)) {
3535
headers.append('Content-Type', 'text/plain');

src/templates/core/node/getRequestBody.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
55
if (options.body) {
66
if (options.mediaType?.includes('/json')) {
77
return JSON.stringify(options.body)
8-
} else if (isString(options.body) || isBinary(options.body)) {
8+
} else if (isString(options.body) || isBlob(options.body)) {
99
return options.body;
1010
} else {
1111
return JSON.stringify(options.body);

src/templates/core/node/request.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { OpenAPI } from './OpenAPI';
1818
{{>functions/isStringWithValue}}
1919

2020

21-
{{>functions/isBinary}}
21+
{{>functions/isBlob}}
2222

2323

2424
{{>functions/getQueryString}}

src/templates/partials/base.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{~#equals base 'File'~}}
22
{{~#equals @root.httpClient 'fetch'}}Blob{{/equals~}}
33
{{~#equals @root.httpClient 'xhr'}}Blob{{/equals~}}
4-
{{~#equals @root.httpClient 'node'}}Buffer | ArrayBuffer | ArrayBufferView{{/equals~}}
4+
{{~#equals @root.httpClient 'node'}}Blob{{/equals~}}
55
{{~else~}}
66
{{{base}}}
77
{{~/equals~}}

test/__snapshots__/index.spec.js.snap

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
163163
const token = await resolve(options, OpenAPI.TOKEN);
164164
const username = await resolve(options, OpenAPI.USERNAME);
165165
const password = await resolve(options, OpenAPI.PASSWORD);
166-
const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
166+
const additionalHeaders = await resolve(options, OpenAPI.HEADERS);
167167

168-
const filteredHeaders = Object.entries({
168+
const defaultHeaders = Object.entries({
169169
Accept: 'application/json',
170-
...defaultHeaders,
170+
...additionalHeaders,
171171
...options.headers,
172-
}).reduce((acc, [headerKey, headerValue]) => {
173-
if (typeof headerValue !== 'undefined') {
174-
return {
175-
...acc,
176-
[headerKey]: headerValue,
177-
};
178-
}
179-
return acc;
180-
}, {});
181-
const headers = new Headers(filteredHeaders);
172+
})
173+
.filter(([key, value]) => isDefined(value))
174+
.reduce((headers, [key, value]) => ({
175+
...headers,
176+
[key]: value,
177+
}), {});
178+
179+
const headers = new Headers(defaultHeaders);
182180

183181
if (isStringWithValue(token)) {
184182
headers.append('Authorization', \`Bearer \${token}\`);
@@ -2527,22 +2525,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
25272525
const token = await resolve(options, OpenAPI.TOKEN);
25282526
const username = await resolve(options, OpenAPI.USERNAME);
25292527
const password = await resolve(options, OpenAPI.PASSWORD);
2530-
const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
2528+
const additionalHeaders = await resolve(options, OpenAPI.HEADERS);
25312529

2532-
const filteredHeaders = Object.entries({
2530+
const defaultHeaders = Object.entries({
25332531
Accept: 'application/json',
2534-
...defaultHeaders,
2532+
...additionalHeaders,
25352533
...options.headers,
2536-
}).reduce((acc, [headerKey, headerValue]) => {
2537-
if (typeof headerValue !== 'undefined') {
2538-
return {
2539-
...acc,
2540-
[headerKey]: headerValue,
2541-
};
2542-
}
2543-
return acc;
2544-
}, {});
2545-
const headers = new Headers(filteredHeaders);
2534+
})
2535+
.filter(([key, value]) => isDefined(value))
2536+
.reduce((headers, [key, value]) => ({
2537+
...headers,
2538+
[key]: value,
2539+
}), {});
2540+
2541+
const headers = new Headers(defaultHeaders);
25462542

25472543
if (isStringWithValue(token)) {
25482544
headers.append('Authorization', \`Bearer \${token}\`);

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function generateV2() {
1313
exportSchemas: true,
1414
exportModels: true,
1515
exportServices: true,
16-
request: './test/custom/request.ts',
16+
// request: './test/custom/request.ts',
1717
});
1818
}
1919

@@ -28,7 +28,7 @@ async function generateV3() {
2828
exportSchemas: true,
2929
exportModels: true,
3030
exportServices: true,
31-
request: './test/custom/request.ts',
31+
// request: './test/custom/request.ts',
3232
});
3333
}
3434

0 commit comments

Comments
 (0)