Skip to content

Commit

Permalink
feat(fieldpath): Handle case differences in structure member names
Browse files Browse the repository at this point in the history
This patch updates the `memberShapeRef` function in the `fieldpath`
package to handle case differences between struct member names in the
ACK model and the AWS SDK Model.

Previously, the function assumed that member names in the ACK model and
AWS SDK model were identical. However, this is not always the case, as
some field names may have different casing (e.g `AWSVPCConfiguration` in
the ACK model and `AwsVpcConfiguration` in the AWS SDK model).

To address this issue, the function now leverages `strings.EqualFold` to
compare the member names case isensitively.

Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
  • Loading branch information
a-hilaly committed Mar 24, 2024
1 parent ca5ff20 commit 8efc8b8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
25 changes: 25 additions & 0 deletions diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/pkg/fieldpath/path.go b/pkg/fieldpath/path.go
index d607318..d20b2b4 100644
--- a/pkg/fieldpath/path.go
+++ b/pkg/fieldpath/path.go
@@ -242,7 +242,19 @@ func memberShapeRef(
}
switch shapeRef.Shape.Type {
case "structure":
- return shapeRef.Shape.MemberRefs[memberName]
+ // We are looking for a member of a structure. We need to loop through
+ // the structure's members to find the member with the name we are
+ // looking for.
+ // Since the ACK fields and the AWS SDK fields are not exactly the same,
+ // we need to EqualFold the member names. e.g in ECS Service resource,
+ // AWSVPCConfiguration is the field name in the ACK model, but
+ // AwsVpcConfiguration is the field name in the AWS SDK model.
+ for memberRefName, memberRefShape := range shapeRef.Shape.MemberRefs {
+ if strings.EqualFold(memberRefName, memberName) {
+ return memberRefShape
+ }
+ }
+ return nil
case "list":
return memberShapeRef(&shapeRef.Shape.MemberRef, memberName)
case "map":
12 changes: 11 additions & 1 deletion pkg/fieldpath/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,17 @@ func memberShapeRef(
}
switch shapeRef.Shape.Type {
case "structure":
return shapeRef.Shape.MemberRefs[memberName]
// We are looking for a member of a structure. Since the ACK fields and
// the AWS SDK fields may have different casing (e.g AWSVPCConfiguration
// and AwsVpcConfiguration) we need to perform a case insensitive
// comparison to find the correct member reference.
for memberRefName, memberRefShape := range shapeRef.Shape.MemberRefs {
if strings.EqualFold(memberRefName, memberName) {
return memberRefShape
}
}
// If no matching member is found, return nil.
return nil
case "list":
return memberShapeRef(&shapeRef.Shape.MemberRef, memberName)
case "map":
Expand Down
13 changes: 13 additions & 0 deletions pkg/fieldpath/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ func TestShapeRef(t *testing.T) {
},
},
},
"WeirdlycasEdType": &awssdkmodel.ShapeRef{
ShapeName: "WeirdlycasEdType",
Shape: &awssdkmodel.Shape{
Type: "string",
},
},
},
},
}
Expand Down Expand Up @@ -220,4 +226,11 @@ func TestShapeRef(t *testing.T) {

// Calling ShapeRef should not modify the original Path
require.Equal("Author.Books.ChapterPageCounts.PageCount", p.String())

// Case-insensitive comparisons...
p = fieldpath.FromString("Author.WeirdlyCasedType")
ref = p.ShapeRef(authShapeRef)
require.NotNil(ref)
require.Equal("WeirdlycasEdType", ref.ShapeName)
require.Equal("string", ref.Shape.Type)
}

0 comments on commit 8efc8b8

Please sign in to comment.