[Bug] fix: use length to check for default return media type (#15833)

* fix: use length to check for default return media type

as `mediaTypes` is an array of strings and an required argument
it will never be undefined when we can rely on the typesystem.
However, it can be zero length(`[]`) and in this case we would
throw.

* Closes #15011

* chore: update examples
This commit is contained in:
Max Strübing
2023-06-16 07:23:58 +02:00
committed by GitHub
parent 03cef639e4
commit 730b946537
9 changed files with 9 additions and 9 deletions

View File

@@ -196,7 +196,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -168,7 +168,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -185,7 +185,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -190,7 +190,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -185,7 +185,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -185,7 +185,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -185,7 +185,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -185,7 +185,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}

View File

@@ -185,7 +185,7 @@ export class ObjectSerializer {
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}