@@ -308,6 +308,8 @@ func SetResource(
308308 setCfg ,
309309 sourceAdaptedVarName ,
310310 sourceMemberShapeRef ,
311+ f .Names .Camel ,
312+ opType ,
311313 indentLevel + 1 ,
312314 )
313315 out += setResourceForScalar (
@@ -578,6 +580,8 @@ func setResourceReadMany(
578580 setCfg ,
579581 sourceAdaptedVarName ,
580582 sourceMemberShapeRef ,
583+ f .Names .Camel ,
584+ model .OpTypeList ,
581585 indentLevel + 2 ,
582586 )
583587 out += setResourceForScalar (
@@ -1156,6 +1160,9 @@ func setResourceForContainer(
11561160 sourceVarName string ,
11571161 // ShapeRef of the source struct field
11581162 sourceShapeRef * awssdkmodel.ShapeRef ,
1163+ // targetFieldPath is the field path for the target containing field
1164+ targetFieldPath string ,
1165+ op model.OpType ,
11591166 indentLevel int ,
11601167) string {
11611168 switch sourceShapeRef .Shape .Type {
@@ -1168,6 +1175,8 @@ func setResourceForContainer(
11681175 targetSetCfg ,
11691176 sourceVarName ,
11701177 sourceShapeRef ,
1178+ targetFieldPath ,
1179+ op ,
11711180 indentLevel ,
11721181 )
11731182 case "list" :
@@ -1179,6 +1188,8 @@ func setResourceForContainer(
11791188 targetSetCfg ,
11801189 sourceVarName ,
11811190 sourceShapeRef ,
1191+ targetFieldPath ,
1192+ op ,
11821193 indentLevel ,
11831194 )
11841195 case "map" :
@@ -1190,6 +1201,8 @@ func setResourceForContainer(
11901201 targetSetCfg ,
11911202 sourceVarName ,
11921203 sourceShapeRef ,
1204+ targetFieldPath ,
1205+ op ,
11931206 indentLevel ,
11941207 )
11951208 default :
@@ -1219,15 +1232,21 @@ func SetResourceForStruct(
12191232 sourceVarName string ,
12201233 // ShapeRef of the source struct field
12211234 sourceShapeRef * awssdkmodel.ShapeRef ,
1235+ // targetFieldPath is the field path to targetFieldName
1236+ targetFieldPath string ,
1237+ op model.OpType ,
12221238 indentLevel int ,
12231239) string {
12241240 out := ""
12251241 indent := strings .Repeat ("\t " , indentLevel )
12261242 sourceShape := sourceShapeRef .Shape
12271243 targetShape := targetShapeRef .Shape
12281244
1245+ var sourceMemberShapeRef * awssdkmodel.ShapeRef
1246+ var sourceAdaptedVarName , qualifiedTargetVar string
1247+
12291248 for _ , targetMemberName := range targetShape .MemberNames () {
1230- sourceMemberShapeRef : = sourceShape .MemberRefs [targetMemberName ]
1249+ sourceMemberShapeRef = sourceShape .MemberRefs [targetMemberName ]
12311250 if sourceMemberShapeRef == nil {
12321251 continue
12331252 }
@@ -1244,13 +1263,14 @@ func SetResourceForStruct(
12441263 indexedVarName := fmt .Sprintf ("%sf%d" , targetVarName , sourceMemberIndex )
12451264 sourceMemberShape := sourceMemberShapeRef .Shape
12461265 targetMemberCleanNames := names .New (targetMemberName )
1247- sourceAdaptedVarName : = sourceVarName + "." + targetMemberName
1266+ sourceAdaptedVarName = sourceVarName + "." + targetMemberName
12481267 out += fmt .Sprintf (
12491268 "%sif %s != nil {\n " , indent , sourceAdaptedVarName ,
12501269 )
1251- qualifiedTargetVar : = fmt .Sprintf (
1270+ qualifiedTargetVar = fmt .Sprintf (
12521271 "%s.%s" , targetVarName , targetMemberCleanNames .Camel ,
12531272 )
1273+ updatedTargetFieldPath := targetFieldPath + "." + targetMemberCleanNames .Camel
12541274
12551275 switch sourceMemberShape .Type {
12561276 case "list" , "structure" , "map" :
@@ -1269,6 +1289,8 @@ func SetResourceForStruct(
12691289 nil ,
12701290 sourceAdaptedVarName ,
12711291 sourceMemberShapeRef ,
1292+ updatedTargetFieldPath ,
1293+ op ,
12721294 indentLevel + 1 ,
12731295 )
12741296 out += setResourceForScalar (
@@ -1290,6 +1312,52 @@ func SetResourceForStruct(
12901312 "%s}\n " , indent ,
12911313 )
12921314 }
1315+ if len (targetShape .MemberNames ()) == 0 {
1316+ // This scenario can occur when the targetShape is a primitive, but
1317+ // the sourceShape is a struct. For example, EC2 resource DHCPOptions
1318+ // has a field NewDhcpConfiguration.Values(targetShape = string) whose name
1319+ // aligns with DhcpConfiguration.Values(sourceShape = AttributeValue).
1320+ // Although the names correspond, the shapes/types are different and the intent
1321+ // is to set NewDhcpConfiguration.Values using DhcpConfiguration.Values.Value
1322+ // (AttributeValue.Value) shape instead. This behavior can be configured using
1323+ // SetConfig.
1324+
1325+ // Check if target field has a SetConfig, validate SetConfig.From points
1326+ // to a shape within sourceShape, and generate Go code using
1327+ // said shape. Using the example above, SetConfig is set
1328+ // for NewDhcpConfiguration.Values and Setconfig.From points
1329+ // to AttributeValue.Value (string), which leads to generating Go
1330+ // code referencing DhcpConfiguration.Values.Value instead of 'Values'.
1331+
1332+ if targetField , ok := r .Fields [targetFieldPath ]; ok {
1333+ setCfg := targetField .GetSetterConfig (op )
1334+ if setCfg != nil && setCfg .From != nil {
1335+ fp := fieldpath .FromString (* setCfg .From )
1336+ sourceMemberShapeRef = fp .ShapeRef (sourceShapeRef )
1337+ if sourceMemberShapeRef != nil && sourceMemberShapeRef .Shape != nil {
1338+ names := names .New (sourceMemberShapeRef .LocationName )
1339+ sourceAdaptedVarName = sourceVarName + "." + names .Camel
1340+ out += fmt .Sprintf (
1341+ "%sif %s != nil {\n " , indent , sourceAdaptedVarName ,
1342+ )
1343+ qualifiedTargetVar = targetVarName
1344+
1345+ // Use setResourceForScalar and dereference sourceAdaptedVarName
1346+ // because primitives are being set.
1347+ sourceAdaptedVarName = "*" + sourceAdaptedVarName
1348+ out += setResourceForScalar (
1349+ qualifiedTargetVar ,
1350+ sourceAdaptedVarName ,
1351+ sourceMemberShapeRef ,
1352+ indentLevel + 1 ,
1353+ )
1354+ out += fmt .Sprintf (
1355+ "%s}\n " , indent ,
1356+ )
1357+ }
1358+ }
1359+ }
1360+ }
12931361 return out
12941362}
12951363
@@ -1310,6 +1378,9 @@ func setResourceForSlice(
13101378 sourceVarName string ,
13111379 // ShapeRef of the source slice field
13121380 sourceShapeRef * awssdkmodel.ShapeRef ,
1381+ // targetFieldPath is the field path to targetFieldName
1382+ targetFieldPath string ,
1383+ op model.OpType ,
13131384 indentLevel int ,
13141385) string {
13151386 out := ""
@@ -1388,6 +1459,8 @@ func setResourceForSlice(
13881459 targetSetCfg ,
13891460 iterVarName ,
13901461 & sourceShape .MemberRef ,
1462+ targetFieldPath ,
1463+ op ,
13911464 indentLevel + 1 ,
13921465 )
13931466 }
@@ -1421,6 +1494,9 @@ func setResourceForMap(
14211494 sourceVarName string ,
14221495 // ShapeRef of the source map field
14231496 sourceShapeRef * awssdkmodel.ShapeRef ,
1497+ // targetFieldPath is the field path to targetFieldName
1498+ targetFieldPath string ,
1499+ op model.OpType ,
14241500 indentLevel int ,
14251501) string {
14261502 out := ""
@@ -1453,6 +1529,8 @@ func setResourceForMap(
14531529 nil ,
14541530 valIterVarName ,
14551531 & sourceShape .ValueRef ,
1532+ targetFieldPath ,
1533+ op ,
14561534 indentLevel + 1 ,
14571535 )
14581536 addressOfVar := ""
0 commit comments