Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix de/serialization of Array types #721

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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> => Type
const subType: string = type.substring(ARRAY_PREFIX.length, type.length - 1);
const transformedData: any[] = [];
Expand Down Expand Up @@ -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> => Type
const subType: string = type.substring(ARRAY_PREFIX.length, type.length - 1);
const transformedData: any[] = [];
Expand Down
7 changes: 7 additions & 0 deletions packages/datadog-api-client-v1/models/ObjectSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> => Type
const subType: string = type.substring(
ARRAY_PREFIX.length,
Expand Down Expand Up @@ -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> => Type
const subType: string = type.substring(
ARRAY_PREFIX.length,
Expand Down
7 changes: 7 additions & 0 deletions packages/datadog-api-client-v2/models/ObjectSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> => Type
const subType: string = type.substring(
ARRAY_PREFIX.length,
Expand Down Expand Up @@ -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> => Type
const subType: string = type.substring(
ARRAY_PREFIX.length,
Expand Down