Skip to content

Commit d9d3390

Browse files
authored
allow ignore nested fieldpaths (#260)
When implementing the update code paths for OpenSearchService, I found out I needed to ignore the AutoTuneOptions.RollbackOnDisable nested field within the UpdateDomainConfigInput shape. When I went to put the following in the `generator.yaml` file: ```yaml ignore: field_paths: - UpdateDomainConfigInput.AutoTuneOptions.RollbackOnDisable ``` What ended up happening is that the *entire* AutoTuneOptions field was ignored instead of just the RollbackOnDisable field. This patch fixes this situation by modifying the `pkg/model.Model:ApplyIgnoreShapeRules()` method to account for nested field paths and not just a two-level field path that has the Input or Output shape name as the first part of the field path and the top-level member field name as the second part of the field path. Signed-off-by: Jay Pipes <[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 8287f67 commit d9d3390

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

pkg/model/model.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"sort"
2020
"strings"
2121

22+
ackfp "github.com/aws-controllers-k8s/code-generator/pkg/fieldpath"
2223
ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config"
2324
"github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset"
2425
"github.com/aws-controllers-k8s/code-generator/pkg/names"
@@ -718,14 +719,6 @@ func (m *Model) ApplyShapeIgnoreRules() {
718719
return
719720
}
720721
for sdkShapeID, shape := range m.SDKAPI.API.Shapes {
721-
for _, fieldpath := range m.cfg.Ignore.FieldPaths {
722-
sn := strings.Split(fieldpath, ".")[0]
723-
fn := strings.Split(fieldpath, ".")[1]
724-
if shape.ShapeName != sn {
725-
continue
726-
}
727-
delete(shape.MemberRefs, fn)
728-
}
729722
for _, sn := range m.cfg.Ignore.ShapeNames {
730723
if shape.ShapeName == sn {
731724
delete(m.SDKAPI.API.Shapes, sdkShapeID)
@@ -739,6 +732,31 @@ func (m *Model) ApplyShapeIgnoreRules() {
739732
}
740733
}
741734
}
735+
for _, fieldpath := range m.cfg.Ignore.FieldPaths {
736+
fp := ackfp.FromString(fieldpath)
737+
sn := fp.At(0)
738+
if shape, found := m.SDKAPI.API.Shapes[sn]; !found {
739+
msg := fmt.Sprintf(
740+
"referred to unknown shape %s in config's Ignore.FieldPaths", sn,
741+
)
742+
panic(msg)
743+
} else {
744+
// This is just some tomfoolery to make the Input and Output shapes
745+
// into ShapeRefs because the SDKAPI.Shapes is a map of Shape
746+
// pointers not a map of ShapeRefs...
747+
wrapper := &awssdkmodel.ShapeRef{
748+
ShapeName: sn,
749+
Shape: shape,
750+
}
751+
// The last element of the fieldpath is the field/shape we want to
752+
// ignore...
753+
ignoreShape := fp.Pop()
754+
parentShapeRef := fp.ShapeRef(wrapper)
755+
// OK, now we delete the ignored shape by removing the shape from
756+
// the parent's member references...
757+
delete(parentShapeRef.Shape.MemberRefs, ignoreShape)
758+
}
759+
}
742760
}
743761

744762
// GetConfig returns the configuration option used to define the current

0 commit comments

Comments
 (0)