Skip to content

Commit 0bf7808

Browse files
authored
feat(fieldpath): Handle case differences in structure member names (#522)
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 <[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 ca5ff20 commit 0bf7808

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/fieldpath/path.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,17 @@ func memberShapeRef(
242242
}
243243
switch shapeRef.Shape.Type {
244244
case "structure":
245-
return shapeRef.Shape.MemberRefs[memberName]
245+
// We are looking for a member of a structure. Since the ACK fields and
246+
// the AWS SDK fields may have different casing (e.g AWSVPCConfiguration
247+
// and AwsVpcConfiguration) we need to perform a case insensitive
248+
// comparison to find the correct member reference.
249+
for memberRefName, memberRefShape := range shapeRef.Shape.MemberRefs {
250+
if strings.EqualFold(memberRefName, memberName) {
251+
return memberRefShape
252+
}
253+
}
254+
// If no matching member is found, return nil.
255+
return nil
246256
case "list":
247257
return memberShapeRef(&shapeRef.Shape.MemberRef, memberName)
248258
case "map":

pkg/fieldpath/path_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ func TestShapeRef(t *testing.T) {
148148
},
149149
},
150150
},
151+
"WeirdlycasEdType": &awssdkmodel.ShapeRef{
152+
ShapeName: "WeirdlycasEdType",
153+
Shape: &awssdkmodel.Shape{
154+
Type: "string",
155+
},
156+
},
151157
},
152158
},
153159
}
@@ -220,4 +226,11 @@ func TestShapeRef(t *testing.T) {
220226

221227
// Calling ShapeRef should not modify the original Path
222228
require.Equal("Author.Books.ChapterPageCounts.PageCount", p.String())
229+
230+
// Case-insensitive comparisons...
231+
p = fieldpath.FromString("Author.WeirdlyCasedType")
232+
ref = p.ShapeRef(authShapeRef)
233+
require.NotNil(ref)
234+
require.Equal("WeirdlycasEdType", ref.ShapeName)
235+
require.Equal("string", ref.Shape.Type)
223236
}

0 commit comments

Comments
 (0)