Skip to content
Open
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
50 changes: 32 additions & 18 deletions packages/datadog-api-client-v1/models/ObjectSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3339,31 +3339,45 @@ export class ObjectSerializer {

const instance = new typeMap[type]();
const attributesMap = typeMap[type].getAttributeTypeMap();
const attributesBaseNames = Object.keys(attributesMap).reduce(
(o, key) => Object.assign(o, { [attributesMap[key].baseName]: "" }),
{}
);
const keepAllInAdditional = (typeMap[type] as any)._keepTypedInAdditionalProperties === true;
// Single pass: build attributesBaseNames (for extra-key detection) and, when needed,
// baseNameToAttr (for per-field typed deserialization preserving int64 precision).
const attributesBaseNames: { [key: string]: string } = {};
const baseNameToAttr: { [key: string]: any } = {};
for (const attrName in attributesMap) {
const baseName = attributesMap[attrName].baseName;
attributesBaseNames[baseName] = "";
if (keepAllInAdditional && attrName !== "additionalProperties") {
baseNameToAttr[baseName] = attributesMap[attrName];
}
}
const extraAttributes = Object.keys(data).filter(
(key) => !Object.prototype.hasOwnProperty.call(attributesBaseNames, key)
(key) => keepAllInAdditional || !Object.prototype.hasOwnProperty.call(attributesBaseNames, key)
);

if (extraAttributes.length > 0) {
if ("additionalProperties" in attributesMap) {
if (!instance.additionalProperties) {
instance.additionalProperties = {};
}

const additionalProperties: { [key: string]: any } = {};
for (const key of extraAttributes) {
additionalProperties[key] = data[key];
if (keepAllInAdditional) {
for (const key of extraAttributes) {
const attrInfo = baseNameToAttr[key];
// Use per-field type/format for typed attrs to preserve int64 precision.
additionalProperties[key] = attrInfo
? ObjectSerializer.deserialize(data[key], attrInfo.type, attrInfo.format)
: data[key];
}
instance.additionalProperties = additionalProperties;
} else {
for (const key of extraAttributes) {
additionalProperties[key] = data[key];
}
const attributeObj = attributesMap["additionalProperties"];
instance.additionalProperties = ObjectSerializer.deserialize(
additionalProperties,
attributeObj.type,
attributeObj.format
);
}

const attributeObj = attributesMap["additionalProperties"];
instance.additionalProperties = ObjectSerializer.deserialize(
additionalProperties,
attributeObj.type,
attributeObj.format
);
} else {
throw new Error(
`found extra attributes '${extraAttributes}' in ${type}`
Expand Down
5 changes: 5 additions & 0 deletions packages/datadog-api-client-v1/models/UsageSummaryDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,11 @@ export class UsageSummaryDate {
*/
"_unparsed"?: boolean;

/**
* @ignore
*/
static readonly _keepTypedInAdditionalProperties = true;

/**
* @ignore
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,11 @@ export class UsageSummaryDateOrg {
*/
"_unparsed"?: boolean;

/**
* @ignore
*/
static readonly _keepTypedInAdditionalProperties = true;

/**
* @ignore
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,11 @@ export class UsageSummaryResponse {
*/
"_unparsed"?: boolean;

/**
* @ignore
*/
static readonly _keepTypedInAdditionalProperties = true;

/**
* @ignore
*/
Expand Down
50 changes: 32 additions & 18 deletions packages/datadog-api-client-v2/models/ObjectSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14355,31 +14355,45 @@ export class ObjectSerializer {

const instance = new typeMap[type]();
const attributesMap = typeMap[type].getAttributeTypeMap();
const attributesBaseNames = Object.keys(attributesMap).reduce(
(o, key) => Object.assign(o, { [attributesMap[key].baseName]: "" }),
{}
);
const keepAllInAdditional = (typeMap[type] as any)._keepTypedInAdditionalProperties === true;
// Single pass: build attributesBaseNames (for extra-key detection) and, when needed,
// baseNameToAttr (for per-field typed deserialization preserving int64 precision).
const attributesBaseNames: { [key: string]: string } = {};
const baseNameToAttr: { [key: string]: any } = {};
for (const attrName in attributesMap) {
const baseName = attributesMap[attrName].baseName;
attributesBaseNames[baseName] = "";
if (keepAllInAdditional && attrName !== "additionalProperties") {
baseNameToAttr[baseName] = attributesMap[attrName];
}
}
const extraAttributes = Object.keys(data).filter(
(key) => !Object.prototype.hasOwnProperty.call(attributesBaseNames, key)
(key) => keepAllInAdditional || !Object.prototype.hasOwnProperty.call(attributesBaseNames, key)
);

if (extraAttributes.length > 0) {
if ("additionalProperties" in attributesMap) {
if (!instance.additionalProperties) {
instance.additionalProperties = {};
}

const additionalProperties: { [key: string]: any } = {};
for (const key of extraAttributes) {
additionalProperties[key] = data[key];
if (keepAllInAdditional) {
for (const key of extraAttributes) {
const attrInfo = baseNameToAttr[key];
// Use per-field type/format for typed attrs to preserve int64 precision.
additionalProperties[key] = attrInfo
? ObjectSerializer.deserialize(data[key], attrInfo.type, attrInfo.format)
: data[key];
}
instance.additionalProperties = additionalProperties;
} else {
for (const key of extraAttributes) {
additionalProperties[key] = data[key];
}
const attributeObj = attributesMap["additionalProperties"];
instance.additionalProperties = ObjectSerializer.deserialize(
additionalProperties,
attributeObj.type,
attributeObj.format
);
}

const attributeObj = attributesMap["additionalProperties"];
instance.additionalProperties = ObjectSerializer.deserialize(
additionalProperties,
attributeObj.type,
attributeObj.format
);
} else {
throw new Error(
`found extra attributes '${extraAttributes}' in ${type}`
Expand Down
Loading