@hey-api/openapi-ts 0.74.0 → 0.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,7 +57,7 @@ export const formDataBodySerializer = {
57
57
 
58
58
  export const jsonBodySerializer = {
59
59
  bodySerializer: <T>(body: T) =>
60
- JSON.stringify(body, (key, value) =>
60
+ JSON.stringify(body, (_key, value) =>
61
61
  typeof value === 'bigint' ? value.toString() : value,
62
62
  ),
63
63
  };
@@ -103,16 +103,24 @@ export const createClient = (config: Config = {}): Client => {
103
103
  ? getParseAs(response.headers.get('Content-Type'))
104
104
  : opts.parseAs) ?? 'json';
105
105
 
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
+ };
113
122
  }
114
123
 
115
- let data = await response[parseAs]();
116
124
  if (parseAs === 'json') {
117
125
  if (opts.responseValidator) {
118
126
  await opts.responseValidator(data);
@@ -36,7 +36,14 @@ export interface Config<T extends ClientOptions = ClientOptions>
36
36
  *
37
37
  * @default 'auto'
38
38
  */
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';
40
47
  /**
41
48
  * Should we return only data or multiple fields (data, error, response, etc.)?
42
49
  *
@@ -182,6 +182,8 @@ export const getParseAs = (
182
182
  if (cleanContent.startsWith('text/')) {
183
183
  return 'text';
184
184
  }
185
+
186
+ return;
185
187
  };
186
188
 
187
189
  export const setAuthParams = async ({
@@ -92,14 +92,22 @@ export const createClient = (config: Config = {}): Client => {
92
92
  ? getParseAs(response.headers.get('Content-Type'))
93
93
  : opts.parseAs) ?? 'json';
94
94
 
95
- if (parseAs === 'stream') {
96
- return {
97
- data: response.body,
98
- ...result,
99
- };
95
+ let data: any;
96
+ switch (parseAs) {
97
+ case 'arrayBuffer':
98
+ case 'blob':
99
+ case 'formData':
100
+ case 'json':
101
+ case 'text':
102
+ data = await response[parseAs]();
103
+ break;
104
+ case 'stream':
105
+ return {
106
+ data: response.body,
107
+ ...result,
108
+ };
100
109
  }
101
110
 
102
- let data = await response[parseAs]();
103
111
  if (parseAs === 'json') {
104
112
  if (opts.responseValidator) {
105
113
  await opts.responseValidator(data);
@@ -27,7 +27,14 @@ export interface Config<T extends ClientOptions = ClientOptions>
27
27
  *
28
28
  * @default 'auto'
29
29
  */
30
- parseAs?: Exclude<keyof Body, 'body' | 'bodyUsed'> | 'auto' | 'stream';
30
+ parseAs?:
31
+ | 'arrayBuffer'
32
+ | 'auto'
33
+ | 'blob'
34
+ | 'formData'
35
+ | 'json'
36
+ | 'stream'
37
+ | 'text';
31
38
  /**
32
39
  * Throw an error instead of returning it in the response?
33
40
  *
@@ -182,6 +182,8 @@ export const getParseAs = (
182
182
  if (cleanContent.startsWith('text/')) {
183
183
  return 'text';
184
184
  }
185
+
186
+ return;
185
187
  };
186
188
 
187
189
  export const setAuthParams = async ({