File tree Expand file tree Collapse file tree 5 files changed +26
-33
lines changed Expand file tree Collapse file tree 5 files changed +26
-33
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " openapi-typescript-codegen" ,
3
- "version" : " 0.5.2 " ,
3
+ "version" : " 0.5.3 " ,
4
4
"description" : " NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification." ,
5
5
"author" : " Ferdi Koomen" ,
6
6
"homepage" : " https://github.com/ferdikoomen/openapi-typescript-codegen" ,
Original file line number Diff line number Diff line change @@ -2,12 +2,11 @@ async function getResponseBody(response: Response): Promise<any> {
2
2
try {
3
3
const contentType = response.headers.get('Content-Type');
4
4
if (contentType) {
5
- switch (contentType.toLowerCase()) {
6
- case 'application/json':
7
- case 'application/json; charset=utf-8':
8
- return await response.json();
9
- default:
10
- return await response.text();
5
+ const isJSON = contentType.toLowerCase().startsWith('application/json');
6
+ if (isJSON) {
7
+ return await response.json();
8
+ } else {
9
+ return await response.text();
11
10
}
12
11
}
13
12
} catch (error) {
Original file line number Diff line number Diff line change @@ -2,13 +2,11 @@ async function getResponseBody(response: Response): Promise<any> {
2
2
try {
3
3
const contentType = response.headers.get('Content-Type');
4
4
if (contentType) {
5
- switch (contentType.toLowerCase()) {
6
- case 'application/json':
7
- case 'application/json; charset=utf-8':
8
- return await response.json();
9
-
10
- default:
11
- return await response.text();
5
+ const isJSON = contentType.toLowerCase().startsWith('application/json');
6
+ if (isJSON) {
7
+ return await response.json();
8
+ } else {
9
+ return await response.text();
12
10
}
13
11
}
14
12
} catch (error) {
Original file line number Diff line number Diff line change @@ -2,13 +2,11 @@ function getResponseBody(xhr: XMLHttpRequest): any {
2
2
try {
3
3
const contentType = xhr.getResponseHeader('Content-Type');
4
4
if (contentType) {
5
- switch (contentType.toLowerCase()) {
6
- case 'application/json':
7
- case 'application/json; charset=utf-8':
8
- return JSON.parse(xhr.responseText);
9
-
10
- default:
11
- return xhr.responseText;
5
+ const isJSON = contentType.toLowerCase().startsWith('application/json');
6
+ if (isJSON) {
7
+ return JSON.parse(xhr.responseText);
8
+ } else {
9
+ return xhr.responseText;
12
10
}
13
11
}
14
12
} catch (error) {
Original file line number Diff line number Diff line change @@ -201,12 +201,11 @@ async function getResponseBody(response: Response): Promise<any> {
201
201
try {
202
202
const contentType = response.headers.get('Content-Type');
203
203
if (contentType) {
204
- switch (contentType.toLowerCase()) {
205
- case 'application/json':
206
- case 'application/json; charset=utf-8':
207
- return await response.json();
208
- default:
209
- return await response.text();
204
+ const isJSON = contentType.toLowerCase().startsWith('application/json');
205
+ if (isJSON) {
206
+ return await response.json();
207
+ } else {
208
+ return await response.text();
210
209
}
211
210
}
212
211
} catch (error) {
@@ -2300,12 +2299,11 @@ async function getResponseBody(response: Response): Promise<any> {
2300
2299
try {
2301
2300
const contentType = response.headers.get('Content-Type');
2302
2301
if (contentType) {
2303
- switch (contentType.toLowerCase()) {
2304
- case 'application/json':
2305
- case 'application/json; charset=utf-8':
2306
- return await response.json();
2307
- default:
2308
- return await response.text();
2302
+ const isJSON = contentType.toLowerCase().startsWith('application/json');
2303
+ if (isJSON) {
2304
+ return await response.json();
2305
+ } else {
2306
+ return await response.text();
2309
2307
}
2310
2308
}
2311
2309
} catch (error) {
You can’t perform that action at this time.
0 commit comments