@@ -182,19 +182,19 @@ func (expander autoExpander) convert(ctx context.Context, sourcePath path.Path,
182182
183183 // Aggregate types.
184184 case basetypes.ObjectValuable :
185- diags .Append (expander .object (ctx , sourcePath , vFrom , targetPath , vTo )... )
185+ diags .Append (expander .object (ctx , sourcePath , vFrom , targetPath , vTo , fieldOpts )... )
186186 return diags
187187
188188 case basetypes.ListValuable :
189- diags .Append (expander .list (ctx , sourcePath , vFrom , targetPath , vTo )... )
189+ diags .Append (expander .list (ctx , sourcePath , vFrom , targetPath , vTo , fieldOpts )... )
190190 return diags
191191
192192 case basetypes.MapValuable :
193- diags .Append (expander .map_ (ctx , vFrom , vTo )... )
193+ diags .Append (expander .map_ (ctx , vFrom , vTo , fieldOpts )... )
194194 return diags
195195
196196 case basetypes.SetValuable :
197- diags .Append (expander .set (ctx , sourcePath , vFrom , targetPath , vTo )... )
197+ diags .Append (expander .set (ctx , sourcePath , vFrom , targetPath , vTo , fieldOpts )... )
198198 return diags
199199 }
200200
@@ -538,7 +538,7 @@ func (expander autoExpander) string(ctx context.Context, vFrom basetypes.StringV
538538}
539539
540540// string copies a Plugin Framework Object(ish) value to a compatible AWS API value.
541- func (expander autoExpander ) object (ctx context.Context , sourcePath path.Path , vFrom basetypes.ObjectValuable , targetPath path.Path , vTo reflect.Value ) diag.Diagnostics {
541+ func (expander autoExpander ) object (ctx context.Context , sourcePath path.Path , vFrom basetypes.ObjectValuable , targetPath path.Path , vTo reflect.Value , _ fieldOpts ) diag.Diagnostics {
542542 var diags diag.Diagnostics
543543
544544 _ , d := vFrom .ToObjectValue (ctx )
@@ -588,7 +588,7 @@ func (expander autoExpander) object(ctx context.Context, sourcePath path.Path, v
588588}
589589
590590// list copies a Plugin Framework List(ish) value to a compatible AWS API value.
591- func (expander autoExpander ) list (ctx context.Context , sourcePath path.Path , vFrom basetypes.ListValuable , targetPath path.Path , vTo reflect.Value ) diag.Diagnostics {
591+ func (expander autoExpander ) list (ctx context.Context , sourcePath path.Path , vFrom basetypes.ListValuable , targetPath path.Path , vTo reflect.Value , fieldOpts fieldOpts ) diag.Diagnostics {
592592 var diags diag.Diagnostics
593593
594594 v , d := vFrom .ToListValue (ctx )
@@ -599,16 +599,16 @@ func (expander autoExpander) list(ctx context.Context, sourcePath path.Path, vFr
599599
600600 switch v .ElementType (ctx ).(type ) {
601601 case basetypes.Int64Typable :
602- diags .Append (expander .listOrSetOfInt64 (ctx , v , vTo )... )
602+ diags .Append (expander .listOrSetOfInt64 (ctx , v , vTo , fieldOpts )... )
603603 return diags
604604
605605 case basetypes.StringTypable :
606- diags .Append (expander .listOrSetOfString (ctx , v , vTo )... )
606+ diags .Append (expander .listOrSetOfString (ctx , v , vTo , fieldOpts )... )
607607 return diags
608608
609609 case basetypes.ObjectTypable :
610610 if vFrom , ok := vFrom .(fwtypes.NestedObjectCollectionValue ); ok {
611- diags .Append (expander .nestedObjectCollection (ctx , sourcePath , vFrom , targetPath , vTo )... )
611+ diags .Append (expander .nestedObjectCollection (ctx , sourcePath , vFrom , targetPath , vTo , fieldOpts )... )
612612 return diags
613613 }
614614 }
@@ -622,13 +622,13 @@ func (expander autoExpander) list(ctx context.Context, sourcePath path.Path, vFr
622622}
623623
624624// listOrSetOfInt64 copies a Plugin Framework ListOfInt64(ish) or SetOfInt64(ish) value to a compatible AWS API value.
625- func (expander autoExpander ) listOrSetOfInt64 (ctx context.Context , vFrom valueWithElementsAs , vTo reflect.Value ) diag.Diagnostics {
625+ func (expander autoExpander ) listOrSetOfInt64 (ctx context.Context , vFrom valueWithElementsAs , vTo reflect.Value , fieldOpts fieldOpts ) diag.Diagnostics {
626626 var diags diag.Diagnostics
627627
628628 switch vTo .Kind () {
629629 case reflect .Struct :
630630 // Check if target is an XML wrapper struct
631- if isXMLWrapperStruct (vTo .Type ()) {
631+ if fieldOpts . xmlWrapper && isXMLWrapperStruct (vTo .Type ()) {
632632 diags .Append (expander .xmlWrapper (ctx , vFrom , vTo , "Items" )... )
633633 return diags
634634 }
@@ -701,13 +701,13 @@ func (expander autoExpander) listOrSetOfInt64(ctx context.Context, vFrom valueWi
701701}
702702
703703// listOrSetOfString copies a Plugin Framework ListOfString(ish) or SetOfString(ish) value to a compatible AWS API value.
704- func (expander autoExpander ) listOrSetOfString (ctx context.Context , vFrom valueWithElementsAs , vTo reflect.Value ) diag.Diagnostics {
704+ func (expander autoExpander ) listOrSetOfString (ctx context.Context , vFrom valueWithElementsAs , vTo reflect.Value , fieldOpts fieldOpts ) diag.Diagnostics {
705705 var diags diag.Diagnostics
706706
707707 switch vTo .Kind () {
708708 case reflect .Struct :
709709 // Check if target is an XML wrapper struct
710- if isXMLWrapperStruct (vTo .Type ()) {
710+ if fieldOpts . xmlWrapper && isXMLWrapperStruct (vTo .Type ()) {
711711 diags .Append (expander .xmlWrapper (ctx , vFrom , vTo , "Items" )... )
712712 return diags
713713 }
@@ -766,7 +766,7 @@ func (expander autoExpander) listOrSetOfString(ctx context.Context, vFrom valueW
766766}
767767
768768// map_ copies a Plugin Framework Map(ish) value to a compatible AWS API value.
769- func (expander autoExpander ) map_ (ctx context.Context , vFrom basetypes.MapValuable , vTo reflect.Value ) diag.Diagnostics {
769+ func (expander autoExpander ) map_ (ctx context.Context , vFrom basetypes.MapValuable , vTo reflect.Value , _ fieldOpts ) diag.Diagnostics {
770770 var diags diag.Diagnostics
771771
772772 v , d := vFrom .ToMapValue (ctx )
@@ -893,7 +893,7 @@ func (expander autoExpander) mapOfString(ctx context.Context, vFrom basetypes.Ma
893893}
894894
895895// set copies a Plugin Framework Set(ish) value to a compatible AWS API value.
896- func (expander autoExpander ) set (ctx context.Context , sourcePath path.Path , vFrom basetypes.SetValuable , targetPath path.Path , vTo reflect.Value ) diag.Diagnostics {
896+ func (expander autoExpander ) set (ctx context.Context , sourcePath path.Path , vFrom basetypes.SetValuable , targetPath path.Path , vTo reflect.Value , fieldOpts fieldOpts ) diag.Diagnostics {
897897 var diags diag.Diagnostics
898898
899899 v , d := vFrom .ToSetValue (ctx )
@@ -904,16 +904,16 @@ func (expander autoExpander) set(ctx context.Context, sourcePath path.Path, vFro
904904
905905 switch v .ElementType (ctx ).(type ) {
906906 case basetypes.Int64Typable :
907- diags .Append (expander .listOrSetOfInt64 (ctx , v , vTo )... )
907+ diags .Append (expander .listOrSetOfInt64 (ctx , v , vTo , fieldOpts )... )
908908 return diags
909909
910910 case basetypes.StringTypable :
911- diags .Append (expander .listOrSetOfString (ctx , v , vTo )... )
911+ diags .Append (expander .listOrSetOfString (ctx , v , vTo , fieldOpts )... )
912912 return diags
913913
914914 case basetypes.ObjectTypable :
915915 if vFrom , ok := vFrom .(fwtypes.NestedObjectCollectionValue ); ok {
916- diags .Append (expander .nestedObjectCollection (ctx , sourcePath , vFrom , targetPath , vTo )... )
916+ diags .Append (expander .nestedObjectCollection (ctx , sourcePath , vFrom , targetPath , vTo , fieldOpts )... )
917917 return diags
918918 }
919919 }
@@ -927,13 +927,13 @@ func (expander autoExpander) set(ctx context.Context, sourcePath path.Path, vFro
927927}
928928
929929// nestedObjectCollection copies a Plugin Framework NestedObjectCollectionValue value to a compatible AWS API value.
930- func (expander autoExpander ) nestedObjectCollection (ctx context.Context , sourcePath path.Path , vFrom fwtypes.NestedObjectCollectionValue , targetPath path.Path , vTo reflect.Value ) diag.Diagnostics {
930+ func (expander autoExpander ) nestedObjectCollection (ctx context.Context , sourcePath path.Path , vFrom fwtypes.NestedObjectCollectionValue , targetPath path.Path , vTo reflect.Value , fieldOpts fieldOpts ) diag.Diagnostics {
931931 var diags diag.Diagnostics
932932
933933 switch tTo := vTo .Type (); vTo .Kind () {
934934 case reflect .Struct :
935935 // Check if target is an XML wrapper struct before handling as generic struct
936- if isXMLWrapperStruct (tTo ) {
936+ if fieldOpts . xmlWrapper && isXMLWrapperStruct (tTo ) {
937937 diags .Append (expander .nestedObjectCollectionToXMLWrapper (ctx , sourcePath , vFrom , targetPath , vTo )... )
938938 return diags
939939 }
@@ -947,7 +947,7 @@ func (expander autoExpander) nestedObjectCollection(ctx context.Context, sourceP
947947 switch tElem := tTo .Elem (); tElem .Kind () {
948948 case reflect .Struct :
949949 // Check if target is a pointer to XML wrapper struct
950- if isXMLWrapperStruct (tElem ) {
950+ if fieldOpts . xmlWrapper && isXMLWrapperStruct (tElem ) {
951951 // Create new instance of the XML wrapper struct
952952 newWrapper := reflect .New (tElem )
953953 diags .Append (expander .nestedObjectCollectionToXMLWrapper (ctx , sourcePath , vFrom , targetPath , newWrapper .Elem ())... )
@@ -1221,7 +1221,8 @@ func expandStruct(ctx context.Context, sourcePath path.Path, from any, targetPat
12211221 })
12221222
12231223 opts := fieldOpts {
1224- legacy : fromFieldOpts .Legacy (),
1224+ legacy : fromFieldOpts .Legacy (),
1225+ xmlWrapper : fromFieldOpts .XMLWrapperField () != "" ,
12251226 }
12261227
12271228 diags .Append (flexer .convert (ctx , sourcePath .AtName (fromFieldName ), valFrom .FieldByIndex (fromField .Index ), targetPath .AtName (toFieldName ), toFieldVal , opts )... )
@@ -1587,7 +1588,15 @@ func isXMLWrapperStruct(t reflect.Type) bool {
15871588 return false
15881589 }
15891590
1590- return true
1591+ // Items and Quantity should be the only non-anonymous fields
1592+ nNonAnonymousFields := 0
1593+ for i := 0 ; i < t .NumField (); i ++ {
1594+ if ! t .Field (i ).Anonymous {
1595+ nNonAnonymousFields ++
1596+ }
1597+ }
1598+
1599+ return nNonAnonymousFields == 2
15911600}
15921601
15931602// nestedObjectCollectionToXMLWrapper converts a NestedObjectCollectionValue to an XML wrapper struct
0 commit comments