-
Notifications
You must be signed in to change notification settings - Fork 240
fix: resolve Go field names correctly in late_initialize code generation #708
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,16 @@ import ( | |
| "github.com/aws-controllers-k8s/code-generator/pkg/model" | ||
| ) | ||
|
|
||
| func fieldGoName(r *model.CRD, configName string) string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: It seems like this should be a problem we've already solved for the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't a standalone shared utility for this today.. sdk.go does it inline since it already has the field from iterating operation shapes. late_initialize is the only codepath starting from bare config keys. |
||
| if f, ok := r.SpecFields[configName]; ok { | ||
| return f.Names.Camel | ||
| } | ||
| if f, ok := r.Fields[configName]; ok { | ||
| return f.Names.Camel | ||
| } | ||
| return configName | ||
| } | ||
|
|
||
| // FindLateInitializedFieldNames outputs the code to create a sorted slice of fieldNames to | ||
| // late initialize. This slice helps with short circuiting the AWSResourceManager.LateInitialize() | ||
| // method if there are no fields to late initialize. | ||
|
|
@@ -49,7 +59,7 @@ func FindLateInitializedFieldNames( | |
| sort.Strings(lateInitFieldNames) | ||
| out += fmt.Sprintf("%svar %s = []string{", indent, resVarName) | ||
| for _, fName := range lateInitFieldNames { | ||
| out += fmt.Sprintf("%q,", fName) | ||
| out += fmt.Sprintf("%q,", fieldGoName(r, fName)) | ||
| } | ||
| out += "}\n" | ||
| return out | ||
|
|
@@ -163,7 +173,8 @@ func LateInitializeFromReadOne( | |
| continue | ||
| } | ||
| indent := strings.Repeat("\t", fNameIndentLevel) | ||
| fNamePartAccesor := fmt.Sprintf("Spec%s.%s", fParentPath, fNamePart) | ||
| goName := fieldGoName(r, fNamePart) | ||
| fNamePartAccesor := fmt.Sprintf("Spec%s.%s", fParentPath, goName) | ||
| if mapShapedParent { | ||
| fNamePartAccesor = fmt.Sprintf("Spec%s[%q]", fParentPath, fNamePart) | ||
| } | ||
|
|
@@ -175,7 +186,7 @@ func LateInitializeFromReadOne( | |
| fParentPath = fmt.Sprintf("%s[%q]", fParentPath, fNamePart) | ||
| mapShapedParent = false | ||
| } else { | ||
| fParentPath = fmt.Sprintf("%s.%s", fParentPath, fNamePart) | ||
| fParentPath = fmt.Sprintf("%s.%s", fParentPath, goName) | ||
| } | ||
| fNameIndentLevel = fNameIndentLevel + 1 | ||
| } else { | ||
|
|
@@ -303,7 +314,8 @@ func IncompleteLateInitialization( | |
| continue | ||
| } | ||
| indent := strings.Repeat("\t", fNameIndentLevel) | ||
| fNamePartAccesor := fmt.Sprintf("Spec%s.%s", fParentPath, fNamePart) | ||
| goName := fieldGoName(r, fNamePart) | ||
| fNamePartAccesor := fmt.Sprintf("Spec%s.%s", fParentPath, goName) | ||
| if mapShapedParent { | ||
| fNamePartAccesor = fmt.Sprintf("Spec%s[%q]", fParentPath, fNamePart) | ||
| } | ||
|
|
@@ -315,7 +327,7 @@ func IncompleteLateInitialization( | |
| fParentPath = fmt.Sprintf("%s[%q]", fParentPath, fNamePart) | ||
| mapShapedParent = false | ||
| } else { | ||
| fParentPath = fmt.Sprintf("%s.%s", fParentPath, fNamePart) | ||
| fParentPath = fmt.Sprintf("%s.%s", fParentPath, goName) | ||
| } | ||
| fNameIndentLevel = fNameIndentLevel + 1 | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| resources: | ||
| Queue: | ||
| unpack_attributes_map: | ||
| get_attributes_input: | ||
| overrides: | ||
| AttributeNames: | ||
| values: | ||
| - All | ||
| fields: | ||
| DelaySeconds: | ||
| is_attribute: true | ||
| MaximumMessageSize: | ||
| is_attribute: true | ||
| MessageRetentionPeriod: | ||
| is_attribute: true | ||
| KmsMasterKeyId: | ||
| is_attribute: true | ||
| KmsDataKeyReusePeriodSeconds: | ||
| is_attribute: true | ||
| Policy: | ||
| is_attribute: true | ||
| ReceiveMessageWaitTimeSeconds: | ||
| is_attribute: true | ||
| VisibilityTimeout: | ||
| is_attribute: true | ||
| FifoQueue: | ||
| is_attribute: true | ||
| ContentBasedDeduplication: | ||
| is_attribute: true | ||
| RedrivePolicy: | ||
| is_attribute: true | ||
| CreatedTimestamp: | ||
| is_attribute: true | ||
| QueueArn: | ||
| is_attribute: true | ||
| is_read_only: true | ||
| QueueUrl: | ||
| is_read_only: true | ||
| is_primary_key: true | ||
| SqsManagedSseEnabled: | ||
| is_attribute: true | ||
| late_initialize: {} |
Uh oh!
There was an error while loading. Please reload this page.