Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generator change for member of type list #452

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/generate/code/set_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions pkg/model/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, but note that this will not handle nested fields, since the path isn't being built up and only contains the member name. We can cross that bridge when we get to it, though... :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nnbu can you add a comment to IsMemberList stating what is can currently do and it's limitations? maybe a //TODO stating what needs to be added.

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.
Expand Down