File tree Expand file tree Collapse file tree 4 files changed +129
-2
lines changed
data/TestClient/src/models Expand file tree Collapse file tree 4 files changed +129
-2
lines changed Original file line number Diff line number Diff line change 11# Release History
22
33## 1.1.4 (Unreleased)
4-
4+ - Fix issue with flattened model serialization, where constant properties are being dropped [ PR # 8658 ] ( https://github.com/Azure/azure-sdk-for-js/pull/8658 )
55
66## 1.1.3 (2020-06-03)
77
Original file line number Diff line number Diff line change @@ -573,7 +573,10 @@ function serializeCompositeType(
573573
574574 for ( const pathName of paths ) {
575575 const childObject = parentObject [ pathName ] ;
576- if ( childObject == undefined && object [ key ] != undefined ) {
576+ if (
577+ childObject == undefined &&
578+ ( object [ key ] != undefined || propertyMapper . defaultValue !== undefined )
579+ ) {
577580 parentObject [ pathName ] = { } ;
578581 }
579582 parentObject = parentObject [ pathName ] ;
Original file line number Diff line number Diff line change 55 */
66const internalMappers : any = { } ;
77
8+ internalMappers . SimpleProduct = {
9+ type : {
10+ name : "Composite" ,
11+ className : "SimpleProduct" ,
12+ modelProperties : {
13+ id : {
14+ serializedName : "id" ,
15+ constraints : { } ,
16+ required : true ,
17+ type : {
18+ name : "Number"
19+ }
20+ } ,
21+ name : {
22+ serializedName : "name" ,
23+ required : true ,
24+ type : {
25+ name : "String"
26+ }
27+ } ,
28+ maxProductDisplayName : {
29+ serializedName : "details.max_product_display_name" ,
30+ type : {
31+ name : "String"
32+ }
33+ } ,
34+ capacity : {
35+ defaultValue : "Large" ,
36+ isConstant : true ,
37+ serializedName : "details.max_product_capacity" ,
38+ type : {
39+ name : "String"
40+ }
41+ }
42+ }
43+ }
44+ } ;
45+
46+ internalMappers . SimpleProductConstFirst = {
47+ type : {
48+ name : "Composite" ,
49+ className : "SimpleProduct" ,
50+ modelProperties : {
51+ id : {
52+ serializedName : "id" ,
53+ constraints : { } ,
54+ required : true ,
55+ type : {
56+ name : "Number"
57+ }
58+ } ,
59+ name : {
60+ serializedName : "name" ,
61+ required : true ,
62+ type : {
63+ name : "String"
64+ }
65+ } ,
66+ capacity : {
67+ defaultValue : "Large" ,
68+ isConstant : true ,
69+ serializedName : "details.max_product_capacity" ,
70+ type : {
71+ name : "String"
72+ }
73+ } ,
74+ maxProductDisplayName : {
75+ serializedName : "details.max_product_display_name" ,
76+ type : {
77+ name : "String"
78+ }
79+ }
80+ }
81+ }
82+ } ;
83+
884internalMappers . Cat = {
985 required : false ,
1086 serializedName : "cat" ,
Original file line number Diff line number Diff line change @@ -21,6 +21,54 @@ function stringToByteArray(str: string): Uint8Array {
2121
2222describe ( "msrest" , function ( ) {
2323 describe ( "serializeObject" , function ( ) {
24+ it ( "should correctly serialize flattened properties" , ( done ) => {
25+ const expected = {
26+ id : 1 ,
27+ name : "testProduct" ,
28+ details : {
29+ max_product_capacity : "Large" ,
30+ max_product_display_name : "MaxDisplayName"
31+ }
32+ } ;
33+
34+ const serialized = Serializer . serialize (
35+ Mappers . SimpleProduct ,
36+ {
37+ id : 1 ,
38+ name : "testProduct" ,
39+ maxProductDisplayName : "MaxDisplayName"
40+ } ,
41+ "SimpleProduct"
42+ ) ;
43+
44+ assert . deepEqual ( serialized , expected ) ;
45+ done ( ) ;
46+ } ) ;
47+
48+ it ( "should correctly serialize flattened properties when flattened constant is defined first" , ( done ) => {
49+ const expected = {
50+ id : 1 ,
51+ name : "testProduct" ,
52+ details : {
53+ max_product_capacity : "Large" ,
54+ max_product_display_name : "MaxDisplayName"
55+ }
56+ } ;
57+
58+ const serialized = Serializer . serialize (
59+ Mappers . SimpleProductConstFirst ,
60+ {
61+ id : 1 ,
62+ name : "testProduct" ,
63+ maxProductDisplayName : "MaxDisplayName"
64+ } ,
65+ "SimpleProduct"
66+ ) ;
67+
68+ assert . deepEqual ( serialized , expected ) ;
69+ done ( ) ;
70+ } ) ;
71+
2472 it ( "should correctly serialize a Date Object" , function ( done ) {
2573 const dateObj = new Date ( "2015-01-01" ) ;
2674 const dateISO = "2015-01-01T00:00:00.000Z" ;
You can’t perform that action at this time.
0 commit comments