Skip to content

Commit bfac339

Browse files
committed
check confilcts
1 parent afd027d commit bfac339

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pkg/sdk/helper.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"errors"
1818
"fmt"
1919
"path/filepath"
20+
"strings"
2021

2122
"github.com/go-git/go-git/v5"
2223

@@ -111,7 +112,7 @@ func (h *Helper) API(serviceModelName string) (*model.SDKAPI, error) {
111112
sdkapi := model.NewSDKAPI(api, h.APIGroupSuffix)
112113

113114
h.InjectCustomShapes(sdkapi)
114-
115+
115116
return sdkapi, nil
116117
}
117118
return nil, ErrServiceNotFound
@@ -129,3 +130,25 @@ func (h *Helper) ModelAndDocsPath(serviceModelName string) string {
129130
)
130131
return modelPath
131132
}
133+
134+
// GetOriginalAPIShapeSet returns a map set (keys with empty struct values) of all original shape names
135+
// from the AWS service API model. This provides efficient lookups to check if a shape name exists.
136+
func (h *Helper) GetOriginalAPIShapeSet(serviceNameOrID string) (map[string]struct{}, error) {
137+
modelPath := h.ModelAndDocsPath(serviceNameOrID)
138+
apis, err := apiv2.LoadAPI(modelPath)
139+
if err != nil {
140+
return nil, err
141+
}
142+
143+
for _, api := range apis {
144+
_ = api.ServicePackageDoc()
145+
shapeSet := make(map[string]struct{}, len(api.Shapes))
146+
for shapeName := range api.Shapes {
147+
shapeSet[shapeName] = struct{}{}
148+
shapeSet[strings.ToLower(shapeName)] = struct{}{}
149+
}
150+
return shapeSet, nil
151+
}
152+
153+
return nil, ErrServiceNotFound
154+
}

pkg/sdk/simpleschema.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ func (h *Helper) InjectSimpleSchemaShapes(sdkapi *ackmodel.SDKAPI) error {
3030
return nil
3131
}
3232

33+
// Get a set of all original shape names for more efficient lookups
34+
originalShapeSet, err := h.GetOriginalAPIShapeSet(sdkapi.ServiceID())
35+
if err != nil {
36+
return err
37+
}
38+
for shapeName := range h.cfg.CustomShapes {
39+
if _, exists := originalShapeSet[shapeName]; exists {
40+
panic(fmt.Sprintf("custom shape %s conflicts with existing API shape", shapeName))
41+
}
42+
}
43+
3344
for shapeName, fieldsMap := range h.cfg.CustomShapes {
3445
schemaObj := convertMapKeys(fieldsMap)
3546

0 commit comments

Comments
 (0)