Skip to content

Commit fdce041

Browse files
committed
fix: deserialize Id-suffixed tracking option keys
1 parent 16f7391 commit fdce041

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/gen/model/accounting/models.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,24 @@ let typeMap: {[index: string]: any} = {
500500
}
501501

502502
export class ObjectSerializer {
503+
private static getDeserializedValue(data: any, baseName: string) {
504+
if (data == null) {
505+
return undefined;
506+
}
507+
508+
if (data[baseName] !== undefined) {
509+
return data[baseName];
510+
}
511+
512+
const idSuffixVariant = baseName.replace(/ID\b/g, "Id");
513+
514+
if (idSuffixVariant !== baseName && data[idSuffixVariant] !== undefined) {
515+
return data[idSuffixVariant];
516+
}
517+
518+
return undefined;
519+
}
520+
503521
public static findCorrectType(data: any, expectedType: string) {
504522
if (data == undefined) {
505523
return expectedType;
@@ -621,7 +639,10 @@ export class ObjectSerializer {
621639
let instance = new typeMap[type]();
622640
let attributeTypes = typeMap[type].getAttributeTypeMap();
623641
for (let [index, attributeType] of Object.entries(attributeTypes)) {
624-
instance[attributeType['name']] = ObjectSerializer.deserialize(data[attributeType['baseName']], attributeType['type']);
642+
instance[attributeType['name']] = ObjectSerializer.deserialize(
643+
ObjectSerializer.getDeserializedValue(data, attributeType['baseName']),
644+
attributeType['type'],
645+
);
625646
}
626647
return instance;
627648
}

src/test/objectSerializer.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ObjectSerializer } from "../gen/model/accounting/models";
2+
3+
describe("accounting ObjectSerializer", () => {
4+
it("deserializes Id-suffixed tracking option keys from invoice line items", () => {
5+
const invoices = ObjectSerializer.deserialize(
6+
{
7+
Invoices: [
8+
{
9+
InvoiceID: "invoice-1",
10+
LineItems: [
11+
{
12+
Tracking: [
13+
{
14+
TrackingCategoryID: "category-1",
15+
TrackingOptionId: "option-1",
16+
Name: "Region",
17+
Option: "North",
18+
},
19+
],
20+
},
21+
],
22+
},
23+
],
24+
},
25+
"Invoices",
26+
);
27+
28+
expect(invoices.invoices?.[0].lineItems?.[0].tracking?.[0].trackingOptionID).toBe(
29+
"option-1",
30+
);
31+
});
32+
});

0 commit comments

Comments
 (0)