File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -500,6 +500,24 @@ let typeMap: {[index: string]: any} = {
500500}
501501
502502export 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 ( / I D \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 }
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments