Skip to content

Commit

Permalink
Improve nested fields path and type resolution (#490)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
a-hilaly authored Jan 19, 2024
1 parent 2511e45 commit a5ca31a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,20 @@ func getAttributeFromPath(crd *CRD, fieldPath string, tdefs []*TypeDef) (parentT

var parentFieldTypeDef *TypeDef
for _, td := range tdefs {
if strings.EqualFold(td.Names.Original, parentFieldTypeDefName) {

fallbackName := ""
switch parentFieldShapeRef.Shape.Type {
case "list":
// e.g FunctionAssociationsList in CloudFront DistributionConfig.DefaultCacheBehavior.FunctionAssociations
fallbackName = parentFieldShapeRef.Shape.MemberRef.ShapeName
fallbackName = strings.TrimSuffix(fallbackName, "List")
default:
// NOTE(a-hilaly): Very likely that we will need to add more cases here
// as we encounter more special APIs in the future.
}

if strings.EqualFold(td.Names.Original, parentFieldTypeDefName) ||
(fallbackName != "" && strings.EqualFold(td.Names.Original, fallbackName)) {
parentFieldTypeDef = td
break
}
Expand Down

0 comments on commit a5ca31a

Please sign in to comment.