From 7556e85392e73002f18bb740d0d11c720dd59970 Mon Sep 17 00:00:00 2001 From: Sherzod K Date: Thu, 16 Jun 2022 14:57:44 +0200 Subject: [PATCH 1/2] Fix de/serialization of Array types --- .../src/generator/templates/model/ObjectSerializer.j2 | 7 +++++++ 1 file changed, 7 insertions(+) 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[] = []; From 1bde741dcbe18234f863bbeb4fe49b89bdaad055 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Thu, 16 Jun 2022 13:01:38 +0000 Subject: [PATCH 2/2] pre-commit fixes --- packages/datadog-api-client-v1/models/ObjectSerializer.ts | 7 +++++++ packages/datadog-api-client-v2/models/ObjectSerializer.ts | 7 +++++++ 2 files changed, 14 insertions(+) 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,