diff --git a/.generator/src/generator/templates/model/ObjectSerializer.j2 b/.generator/src/generator/templates/model/ObjectSerializer.j2 index b9115620b6e..f775b272638 100644 --- a/.generator/src/generator/templates/model/ObjectSerializer.j2 +++ b/.generator/src/generator/templates/model/ObjectSerializer.j2 @@ -57,6 +57,9 @@ export class ObjectSerializer { } else if (primitives.includes(type.toLowerCase()) && typeof data == type.toLowerCase()) { return data; } else if (type.startsWith(ARRAY_PREFIX)) { + if (!Array.isArray(data)) { + throw new TypeError(`mismatch types '${data}' and '${type}'`); + } // Array => Type const subType: string = type.substring(ARRAY_PREFIX.length, type.length - 1); const transformedData: any[] = []; @@ -160,6 +163,10 @@ export class ObjectSerializer { } else if (primitives.includes(type.toLowerCase()) && typeof data == type.toLowerCase()) { return data; } else if (type.startsWith(ARRAY_PREFIX)) { + // Assert the passed data is Array type + if (!Array.isArray(data)) { + throw new TypeError(`mismatch types '${data}' and '${type}'`); + } // Array => Type const subType: string = type.substring(ARRAY_PREFIX.length, type.length - 1); const transformedData: any[] = []; diff --git a/packages/datadog-api-client-v1/models/ObjectSerializer.ts b/packages/datadog-api-client-v1/models/ObjectSerializer.ts index b6b252749f7..20aa3cf76da 100644 --- a/packages/datadog-api-client-v1/models/ObjectSerializer.ts +++ b/packages/datadog-api-client-v1/models/ObjectSerializer.ts @@ -1859,6 +1859,9 @@ export class ObjectSerializer { ) { return data; } else if (type.startsWith(ARRAY_PREFIX)) { + if (!Array.isArray(data)) { + throw new TypeError(`mismatch types '${data}' and '${type}'`); + } // Array => Type const subType: string = type.substring( ARRAY_PREFIX.length, @@ -1998,6 +2001,10 @@ export class ObjectSerializer { ) { return data; } else if (type.startsWith(ARRAY_PREFIX)) { + // Assert the passed data is Array type + if (!Array.isArray(data)) { + throw new TypeError(`mismatch types '${data}' and '${type}'`); + } // Array => Type const subType: string = type.substring( ARRAY_PREFIX.length, diff --git a/packages/datadog-api-client-v2/models/ObjectSerializer.ts b/packages/datadog-api-client-v2/models/ObjectSerializer.ts index b9c93b02792..3e275d3e644 100644 --- a/packages/datadog-api-client-v2/models/ObjectSerializer.ts +++ b/packages/datadog-api-client-v2/models/ObjectSerializer.ts @@ -1018,6 +1018,9 @@ export class ObjectSerializer { ) { return data; } else if (type.startsWith(ARRAY_PREFIX)) { + if (!Array.isArray(data)) { + throw new TypeError(`mismatch types '${data}' and '${type}'`); + } // Array => Type const subType: string = type.substring( ARRAY_PREFIX.length, @@ -1157,6 +1160,10 @@ export class ObjectSerializer { ) { return data; } else if (type.startsWith(ARRAY_PREFIX)) { + // Assert the passed data is Array type + if (!Array.isArray(data)) { + throw new TypeError(`mismatch types '${data}' and '${type}'`); + } // Array => Type const subType: string = type.substring( ARRAY_PREFIX.length,