Skip to content

Commit b7d79a2

Browse files
authored
Merge pull request #2219 from hey-api/fix/output-types
fix: make output pass stricter tsconfig configurations
2 parents a6eacf0 + 4df6fa0 commit b7d79a2

File tree

595 files changed

+3606
-1348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

595 files changed

+3606
-1348
lines changed

.changeset/old-feet-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix: make output pass stricter tsconfig configurations"

packages/custom-client/src/client.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,21 @@ export const createClient = (config: Config = {}): Client => {
102102
? getParseAs(response.headers.get('Content-Type'))
103103
: opts.parseAs) ?? 'json';
104104

105-
if (parseAs === 'stream') {
106-
return {
107-
data: response.body,
108-
...result,
109-
};
105+
let data: any;
106+
switch (parseAs) {
107+
case 'arrayBuffer':
108+
case 'blob':
109+
case 'formData':
110+
case 'json':
111+
case 'text':
112+
data = await response[parseAs]();
113+
break;
114+
case 'stream':
115+
return {
116+
data: response.body,
117+
...result,
118+
};
110119
}
111-
112-
let data = await response[parseAs]();
113120
if (parseAs === 'json') {
114121
if (opts.responseValidator) {
115122
await opts.responseValidator(data);

packages/custom-client/src/core/bodySerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const formDataBodySerializer = {
5757

5858
export const jsonBodySerializer = {
5959
bodySerializer: <T>(body: T) =>
60-
JSON.stringify(body, (key, value) =>
60+
JSON.stringify(body, (_key, value) =>
6161
typeof value === 'bigint' ? value.toString() : value,
6262
),
6363
};

packages/custom-client/src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ export interface Config<T extends ClientOptions = ClientOptions>
2424
*
2525
* @default 'auto'
2626
*/
27-
parseAs?: Exclude<keyof Body, 'body' | 'bodyUsed'> | 'auto' | 'stream';
27+
parseAs?:
28+
| 'arrayBuffer'
29+
| 'auto'
30+
| 'blob'
31+
| 'formData'
32+
| 'json'
33+
| 'stream'
34+
| 'text';
2835
/**
2936
* Throw an error instead of returning it in the response?
3037
*

packages/custom-client/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ export const getParseAs = (
182182
if (cleanContent.startsWith('text/')) {
183183
return 'text';
184184
}
185+
186+
return;
185187
};
186188

187189
export const setAuthParams = async ({

packages/openapi-ts-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"test:coverage": "vitest run --config vitest.config.unit.ts --coverage",
88
"test:e2e:disabled": "vitest run --config vitest.config.e2e.ts",
9+
"test:types": "tsc -p tsconfig.test.json --noEmit",
910
"test:update": "vitest watch --config vitest.config.unit.ts --update",
1011
"test:watch": "vitest watch --config vitest.config.unit.ts",
1112
"test": "vitest run --config vitest.config.unit.ts",

packages/openapi-ts-tests/test/__snapshots__/2.0.x/body-response-text-plain/client/client.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,24 @@ export const createClient = (config: Config = {}): Client => {
103103
? getParseAs(response.headers.get('Content-Type'))
104104
: opts.parseAs) ?? 'json';
105105

106-
if (parseAs === 'stream') {
107-
return opts.responseStyle === 'data'
108-
? response.body
109-
: {
110-
data: response.body,
111-
...result,
112-
};
106+
let data: any;
107+
switch (parseAs) {
108+
case 'arrayBuffer':
109+
case 'blob':
110+
case 'formData':
111+
case 'json':
112+
case 'text':
113+
data = await response[parseAs]();
114+
break;
115+
case 'stream':
116+
return opts.responseStyle === 'data'
117+
? response.body
118+
: {
119+
data: response.body,
120+
...result,
121+
};
113122
}
114123

115-
let data = await response[parseAs]();
116124
if (parseAs === 'json') {
117125
if (opts.responseValidator) {
118126
await opts.responseValidator(data);

packages/openapi-ts-tests/test/__snapshots__/2.0.x/body-response-text-plain/client/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ export interface Config<T extends ClientOptions = ClientOptions>
3636
*
3737
* @default 'auto'
3838
*/
39-
parseAs?: Exclude<keyof Body, 'body' | 'bodyUsed'> | 'auto' | 'stream';
39+
parseAs?:
40+
| 'arrayBuffer'
41+
| 'auto'
42+
| 'blob'
43+
| 'formData'
44+
| 'json'
45+
| 'stream'
46+
| 'text';
4047
/**
4148
* Should we return only data or multiple fields (data, error, response, etc.)?
4249
*

packages/openapi-ts-tests/test/__snapshots__/2.0.x/body-response-text-plain/client/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ export const getParseAs = (
182182
if (cleanContent.startsWith('text/')) {
183183
return 'text';
184184
}
185+
186+
return;
185187
};
186188

187189
export const setAuthParams = async ({

packages/openapi-ts-tests/test/__snapshots__/2.0.x/body-response-text-plain/core/bodySerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const formDataBodySerializer = {
5757

5858
export const jsonBodySerializer = {
5959
bodySerializer: <T>(body: T) =>
60-
JSON.stringify(body, (key, value) =>
60+
JSON.stringify(body, (_key, value) =>
6161
typeof value === 'bigint' ? value.toString() : value,
6262
),
6363
};

0 commit comments

Comments
 (0)