File tree Expand file tree Collapse file tree 2 files changed +49
-13
lines changed
packages/openapi-ts/src/plugins/@hey-api Expand file tree Collapse file tree 2 files changed +49
-13
lines changed Original file line number Diff line number Diff line change @@ -106,23 +106,41 @@ export const createClient = (config: Config = {}): Client => {
106
106
} ;
107
107
108
108
if ( response . ok ) {
109
+ const parseAs =
110
+ ( opts . parseAs === 'auto'
111
+ ? getParseAs ( response . headers . get ( 'Content-Type' ) )
112
+ : opts . parseAs ) ?? 'json' ;
113
+
109
114
if (
110
115
response . status === 204 ||
111
116
response . headers . get ( 'Content-Length' ) === '0'
112
117
) {
118
+ let emptyData : any ;
119
+ switch ( parseAs ) {
120
+ case 'arrayBuffer' :
121
+ case 'blob' :
122
+ case 'text' :
123
+ emptyData = await response [ parseAs ] ( ) ;
124
+ break ;
125
+ case 'formData' :
126
+ emptyData = new FormData ( ) ;
127
+ break ;
128
+ case 'stream' :
129
+ emptyData = response . body ;
130
+ break ;
131
+ case 'json' :
132
+ default :
133
+ emptyData = { } ;
134
+ break ;
135
+ }
113
136
return opts . responseStyle === 'data'
114
- ? { }
137
+ ? emptyData
115
138
: {
116
- data : { } ,
139
+ data : emptyData ,
117
140
...result ,
118
141
} ;
119
142
}
120
143
121
- const parseAs =
122
- ( opts . parseAs === 'auto'
123
- ? getParseAs ( response . headers . get ( 'Content-Type' ) )
124
- : opts . parseAs ) ?? 'json' ;
125
-
126
144
let data : any ;
127
145
switch ( parseAs ) {
128
146
case 'arrayBuffer' :
Original file line number Diff line number Diff line change @@ -101,21 +101,39 @@ export const createClient = (config: Config = {}): Client => {
101
101
} ;
102
102
103
103
if ( response . ok ) {
104
+ const parseAs =
105
+ ( opts . parseAs === 'auto'
106
+ ? getParseAs ( response . headers . get ( 'Content-Type' ) )
107
+ : opts . parseAs ) ?? 'json' ;
108
+
104
109
if (
105
110
response . status === 204 ||
106
111
response . headers . get ( 'Content-Length' ) === '0'
107
112
) {
113
+ let emptyData : any ;
114
+ switch ( parseAs ) {
115
+ case 'arrayBuffer' :
116
+ case 'blob' :
117
+ case 'text' :
118
+ emptyData = await response [ parseAs ] ( ) ;
119
+ break ;
120
+ case 'formData' :
121
+ emptyData = new FormData ( ) ;
122
+ break ;
123
+ case 'stream' :
124
+ emptyData = response . body ;
125
+ break ;
126
+ case 'json' :
127
+ default :
128
+ emptyData = { } ;
129
+ break ;
130
+ }
108
131
return {
109
- data : { } ,
132
+ data : emptyData ,
110
133
...result ,
111
134
} ;
112
135
}
113
136
114
- const parseAs =
115
- ( opts . parseAs === 'auto'
116
- ? getParseAs ( response . headers . get ( 'Content-Type' ) )
117
- : opts . parseAs ) ?? 'json' ;
118
-
119
137
let data : any ;
120
138
switch ( parseAs ) {
121
139
case 'arrayBuffer' :
You can’t perform that action at this time.
0 commit comments