Skip to content

Commit 42429aa

Browse files
author
Nicholas Thomson
committed
Add custom key shape for maps
1 parent feb7d2e commit 42429aa

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/sdk/custom_shapes.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
const (
2828
ShapeNameTemplateList = "%sList"
2929
ShapeNameTemplateMap = "%sMap"
30+
ShapeNameTemplateKey = "%sKey"
3031
)
3132

3233
type CustomShape struct {
@@ -113,6 +114,16 @@ func (i *customShapeInjector) createShapeRefForMember(shape *awssdkmodel.Shape)
113114
}
114115
}
115116

117+
// createKeyShape creates a Shape that acts as the string key shape for a
118+
// custom map.
119+
func (i *customShapeInjector) createKeyShape(shapeName string) *awssdkmodel.Shape {
120+
return &awssdkmodel.Shape{
121+
API: i.sdkAPI.API,
122+
ShapeName: fmt.Sprintf(ShapeNameTemplateKey, shapeName),
123+
Type: "string",
124+
}
125+
}
126+
116127
// newList loads a shape given its name and creates a custom shape that is a
117128
// map with strings as keys and that shape as the value.
118129
func (i *customShapeInjector) newMap(valueShapeName string) (*CustomShape, error) {
@@ -125,11 +136,15 @@ func (i *customShapeInjector) newMap(valueShapeName string) (*CustomShape, error
125136
shapeName := fmt.Sprintf(ShapeNameTemplateMap, valueShape.ShapeName)
126137
documentation := ""
127138

139+
keyShape := i.createKeyShape(shapeName)
140+
keyShapeRef := i.createShapeRefForMember(keyShape)
141+
128142
shape := &awssdkmodel.Shape{
129143
API: i.sdkAPI.API,
130144
ShapeName: shapeName,
131145
// TODO (RedbackThomson): Support documentation for custom shapes
132146
Documentation: documentation,
147+
KeyRef: *keyShapeRef,
133148
ValueRef: *valueShapeRef,
134149
Type: "map",
135150
}

0 commit comments

Comments
 (0)