Skip to content

Commit a5ca31a

Browse files
authored
Improve nested fields path and type resolution (#490)
This commit improves the `getAttributeFromPath` function by introducing a better field path and type resolution mechanism. Now, it considers aadditional fallback naming conventions, particularly for cases involving lists. This is needed to generate type references for `Distribution` resource in ACK CloudFront controller. More specifically, the CF API Schema for the `Distribution` resource is naming the `FunctionAssociations` shape `FunctionAssociationsList`. Tested with cloudfront-controller using the following config: ```yaml resources: Distribution: fields: DistributionConfig.DefaultCacheBehavior.FunctionAssociations.Items.FunctionARN: references: resource: Function path: Status.ACKResourceMetadata.ARN ``` Signed-off-by: Amine Hilaly <[email protected]> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2511e45 commit a5ca31a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/model/model.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,20 @@ func getAttributeFromPath(crd *CRD, fieldPath string, tdefs []*TypeDef) (parentT
581581

582582
var parentFieldTypeDef *TypeDef
583583
for _, td := range tdefs {
584-
if strings.EqualFold(td.Names.Original, parentFieldTypeDefName) {
584+
585+
fallbackName := ""
586+
switch parentFieldShapeRef.Shape.Type {
587+
case "list":
588+
// e.g FunctionAssociationsList in CloudFront DistributionConfig.DefaultCacheBehavior.FunctionAssociations
589+
fallbackName = parentFieldShapeRef.Shape.MemberRef.ShapeName
590+
fallbackName = strings.TrimSuffix(fallbackName, "List")
591+
default:
592+
// NOTE(a-hilaly): Very likely that we will need to add more cases here
593+
// as we encounter more special APIs in the future.
594+
}
595+
596+
if strings.EqualFold(td.Names.Original, parentFieldTypeDefName) ||
597+
(fallbackName != "" && strings.EqualFold(td.Names.Original, fallbackName)) {
585598
parentFieldTypeDef = td
586599
break
587600
}

0 commit comments

Comments
 (0)