Fixed parse of header for contentType

This commit is contained in:
Ferdi Koomen 2020-10-15 16:25:06 +02:00
parent 6c35b190e5
commit 45d4c2e9fc
5 changed files with 26 additions and 33 deletions

View File

@ -1,6 +1,6 @@
{
"name": "openapi-typescript-codegen",
"version": "0.5.2",
"version": "0.5.3",
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",
"author": "Ferdi Koomen",
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",

View File

@ -2,12 +2,11 @@ async function getResponseBody(response: Response): Promise<any> {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
return await response.json();
default:
return await response.text();
const isJSON = contentType.toLowerCase().startsWith('application/json');
if (isJSON) {
return await response.json();
} else {
return await response.text();
}
}
} catch (error) {

View File

@ -2,13 +2,11 @@ async function getResponseBody(response: Response): Promise<any> {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
return await response.json();
default:
return await response.text();
const isJSON = contentType.toLowerCase().startsWith('application/json');
if (isJSON) {
return await response.json();
} else {
return await response.text();
}
}
} catch (error) {

View File

@ -2,13 +2,11 @@ function getResponseBody(xhr: XMLHttpRequest): any {
try {
const contentType = xhr.getResponseHeader('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
return JSON.parse(xhr.responseText);
default:
return xhr.responseText;
const isJSON = contentType.toLowerCase().startsWith('application/json');
if (isJSON) {
return JSON.parse(xhr.responseText);
} else {
return xhr.responseText;
}
}
} catch (error) {

View File

@ -201,12 +201,11 @@ async function getResponseBody(response: Response): Promise<any> {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
return await response.json();
default:
return await response.text();
const isJSON = contentType.toLowerCase().startsWith('application/json');
if (isJSON) {
return await response.json();
} else {
return await response.text();
}
}
} catch (error) {
@ -2300,12 +2299,11 @@ async function getResponseBody(response: Response): Promise<any> {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
return await response.json();
default:
return await response.text();
const isJSON = contentType.toLowerCase().startsWith('application/json');
if (isJSON) {
return await response.json();
} else {
return await response.text();
}
}
} catch (error) {