diff --git a/src/gen/model/accounting/models.ts b/src/gen/model/accounting/models.ts index 5268439a1..c80284f15 100644 --- a/src/gen/model/accounting/models.ts +++ b/src/gen/model/accounting/models.ts @@ -487,6 +487,24 @@ let typeMap: {[index: string]: any} = { } export class ObjectSerializer { + private static getDeserializedValue(data: any, baseName: string) { + if (data == null) { + return undefined; + } + + if (data[baseName] !== undefined) { + return data[baseName]; + } + + const idSuffixVariant = baseName.replace(/ID\b/g, "Id"); + + if (idSuffixVariant !== baseName && data[idSuffixVariant] !== undefined) { + return data[idSuffixVariant]; + } + + return undefined; + } + public static findCorrectType(data: any, expectedType: string) { if (data == undefined) { return expectedType; @@ -608,7 +626,10 @@ export class ObjectSerializer { let instance = new typeMap[type](); let attributeTypes = typeMap[type].getAttributeTypeMap(); for (let [index, attributeType] of Object.entries(attributeTypes)) { - instance[attributeType['name']] = ObjectSerializer.deserialize(data[attributeType['baseName']], attributeType['type']); + instance[attributeType['name']] = ObjectSerializer.deserialize( + ObjectSerializer.getDeserializedValue(data, attributeType['baseName']), + attributeType['type'], + ); } return instance; } diff --git a/src/test/objectSerializer.spec.ts b/src/test/objectSerializer.spec.ts new file mode 100644 index 000000000..b5b6ef2ca --- /dev/null +++ b/src/test/objectSerializer.spec.ts @@ -0,0 +1,32 @@ +import { ObjectSerializer } from "../gen/model/accounting/models"; + +describe("accounting ObjectSerializer", () => { + it("deserializes Id-suffixed tracking option keys from invoice line items", () => { + const invoices = ObjectSerializer.deserialize( + { + Invoices: [ + { + InvoiceID: "invoice-1", + LineItems: [ + { + Tracking: [ + { + TrackingCategoryID: "category-1", + TrackingOptionId: "option-1", + Name: "Region", + Option: "North", + }, + ], + }, + ], + }, + ], + }, + "Invoices", + ); + + expect(invoices.invoices?.[0].lineItems?.[0].tracking?.[0].trackingOptionID).toBe( + "option-1", + ); + }); +});