From 6df26e3cf5b991e95e81bf4f2b837991bdfbabaf Mon Sep 17 00:00:00 2001 From: Nishant Burte Date: Tue, 6 Jun 2023 16:02:25 -0700 Subject: [PATCH] Code generator change for member of type list Currently code generator assumes the type of 'member' as scalar. But if the member is a list, the generated code needs to be as per that type. --- pkg/generate/code/set_sdk.go | 12 +++++++++--- pkg/model/crd.go | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pkg/generate/code/set_sdk.go b/pkg/generate/code/set_sdk.go index bac62aa7..c8d7f4ff 100644 --- a/pkg/generate/code/set_sdk.go +++ b/pkg/generate/code/set_sdk.go @@ -874,9 +874,15 @@ func setSDKReadMany( indentLevel+1, ) - // f0 = append(f0, sourceVarName) - out += fmt.Sprintf("%s\t%s = append(%s, %s)\n", indent, - memberVarName, memberVarName, resVarPath) + if r.IsMemberAList(memberName, op) { + // f0 = append(f0, sourceVarName...) + out += fmt.Sprintf("%s\t%s = append(%s, %s...)\n", indent, + memberVarName, memberVarName, resVarPath) + } else { + // f0 = append(f0, sourceVarName) + out += fmt.Sprintf("%s\t%s = append(%s, %s)\n", indent, + memberVarName, memberVarName, resVarPath) + } // res.SetIds(f0) out += setSDKForScalar( diff --git a/pkg/model/crd.go b/pkg/model/crd.go index 16734d37..95980761 100644 --- a/pkg/model/crd.go +++ b/pkg/model/crd.go @@ -686,6 +686,28 @@ func (r *CRD) GetIdentifiers() []string { return identifiers } +func (r *CRD) IsMemberAList( + memberName string, + op *awssdkmodel.Operation) bool { + cfg := r.Config() + + // Handles field renames, if applicable + fieldName := cfg.GetResourceFieldName( + r.Names.Original, + op.ExportedName, + memberName, + ) + cleanFieldNames := names.New(fieldName) + pathFieldName := cleanFieldNames.Camel + + if _, ok := r.Fields[pathFieldName]; ok { + if strings.Contains(r.Fields[pathFieldName].GoType, "[]") { + return true + } + } + return false +} + // GetSanitizedMemberPath takes a shape member field, checks for renames, checks // for existence in Spec and Status, then constructs and returns the var path. // Returns error if memberName is not present in either Spec or Status.