Skip to content

Commit e559791

Browse files
authored
fix: correct union type code generation for list members (#629)
Fix code generation for union types with list members (e.g []*string) that was incorrectly trying to dereference the constructed slice and assign directly to non-existent interface fields. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent eaabefb commit e559791

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/generate/code/set_sdk.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ func setSDKForSlice(
12721272
out := ""
12731273
indent := strings.Repeat("\t", indentLevel)
12741274
targetShape := targetShapeRef.Shape
1275+
if targetShape.MemberRef.Shape.Type == "string" && !targetShape.MemberRef.Shape.IsEnum() && !r.IsSecretField(sourceFieldPath) {
1276+
out += fmt.Sprintf("%s%s = aws.ToStringSlice(%s)\n", indent, targetVarName, sourceVarName)
1277+
return out
1278+
}
12751279

12761280
iterVarName := fmt.Sprintf("%siter", targetVarName)
12771281
elemVarName := fmt.Sprintf("%selem", targetVarName)
@@ -1776,11 +1780,11 @@ func setSDKForUnion(
17761780

17771781
switch memberShape.Type {
17781782
case "list", "structure", "map", "union":
1779-
adaption := setSDKAdaptiveResourceCollection(memberShape, targetVarName, memberName, sourceAdaptedVarName, indent, r.IsSecretField(memberFieldPath))
1783+
/* adaption := setSDKAdaptiveResourceCollection(memberShape, targetVarName, memberName, sourceAdaptedVarName, indent, r.IsSecretField(memberFieldPath))
17801784
out += adaption
17811785
if adaption != "" {
17821786
break
1783-
}
1787+
} */
17841788
{
17851789
out += varEmptyConstructorSDKType(
17861790
cfg, r,
@@ -1799,7 +1803,11 @@ func setSDKForUnion(
17991803
op,
18001804
indentLevel+1,
18011805
)
1802-
out += fmt.Sprintf("%s\t%s.Value = *%s\n", indent, elemVarName, indexedVarName)
1806+
if memberShape.Type == "list" {
1807+
out += fmt.Sprintf("%s\t%s.Value = %s\n", indent, elemVarName, indexedVarName)
1808+
} else {
1809+
out += fmt.Sprintf("%s\t%s.Value = *%s\n", indent, elemVarName, indexedVarName)
1810+
}
18031811
out += fmt.Sprintf("%s\t%s = %s\n", indent, targetVarName, elemVarName)
18041812
out += fmt.Sprintf("%s\tisInterfaceSet = true\n", indent)
18051813
}

0 commit comments

Comments
 (0)