Skip to content

Commit 9cebd89

Browse files
authored
Support nested paths in field config specifically list type members (#183)
Issue #, if available: aws-controllers-k8s/community#932 Description of changes: `getMemberByPath` checks the shape type as it loops through members to ensure lists are handled correctly. Currently I have simply ignored the empty element created by the splitting of the string on the single dot instead of handling the double dot notation explicitly. Open to comments. Also added a Unit Test for the same. Testing 1. Generated code for ApplicationAutoscaling and ensured CreationTime field now works as expected. Linked changes [in this PR](aws-controllers-k8s/applicationautoscaling-controller#39). 2. Ensured that the SageMaker Controller can be generated using new changes with no diff as expected. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0916df1 commit 9cebd89

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pkg/model/sdk_helper.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,19 @@ func (a *SDKAPI) GetOutputShapeRef(
246246
}
247247

248248
// getMemberByPath returns a ShapeRef given a root Shape and a dot-notation
249-
// object search path
249+
// object search path. Given the explicit type check for list type members
250+
// both ".." and "." notations work currently.
251+
// TODO: Add support for other types such as map.
250252
func getMemberByPath(
251253
shape *awssdkmodel.Shape,
252254
path string,
253255
) (*awssdkmodel.ShapeRef, bool) {
254256
elements := strings.Split(path, ".")
255257
last := len(elements) - 1
256258
for x, elem := range elements {
259+
if elem == "" {
260+
continue
261+
}
257262
if shape == nil {
258263
return nil, false
259264
}
@@ -264,7 +269,13 @@ func getMemberByPath(
264269
if x == last {
265270
return shapeRef, true
266271
}
267-
shape = shapeRef.Shape
272+
elemType := shapeRef.Shape.Type
273+
switch elemType {
274+
case "list":
275+
shape = shapeRef.Shape.MemberRef.Shape
276+
default:
277+
shape = shapeRef.Shape
278+
}
268279
}
269280
return nil, false
270281
}

pkg/model/sdk_helper_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ func TestGetOutputShapeRef(t *testing.T) {
133133
&stringshape,
134134
true,
135135
},
136+
{
137+
// list type nested path search
138+
"ListAliases",
139+
"Aliases..RevisionId",
140+
&stringshape,
141+
true,
142+
},
136143
{
137144
// no such op
138145
"GetNonexisting",

0 commit comments

Comments
 (0)