Skip to content

Commit e3c7ceb

Browse files
committed
rm legacy handling
1 parent cb5ced4 commit e3c7ceb

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

rules/models/generator/main.go

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,8 @@ func main() {
7474

7575
// Detect format and extract shapes accordingly
7676
var shapes map[string]interface{}
77-
if smithyVersion, ok := api["smithy"]; ok && smithyVersion != nil {
78-
// Smithy format (api-models-aws)
79-
shapes = api["shapes"].(map[string]interface{})
80-
} else {
81-
// Legacy Ruby SDK format
82-
shapes = api["shapes"].(map[string]interface{})
83-
}
77+
// Extract shapes from Smithy format
78+
shapes = api["shapes"].(map[string]interface{})
8479

8580
for _, mapping := range mappingFile.Mappings {
8681
for attribute, value := range mapping.Attrs {
@@ -142,33 +137,26 @@ func fetchSchema(resource, attribute string, model map[string]interface{}, provi
142137
return attrSchema
143138
}
144139

145-
// findShape locates a shape in either Ruby SDK or Smithy format
140+
// findShape locates a shape in Smithy format
146141
func findShape(shapes map[string]interface{}, shapeName, importPath string) map[string]interface{} {
147-
// First try direct lookup (Ruby SDK format)
148-
if shape, ok := shapes[shapeName]; ok {
149-
return shape.(map[string]interface{})
142+
// Try with service namespace qualification
143+
serviceNamespace := extractServiceNamespace(shapes)
144+
if serviceNamespace != "" {
145+
qualifiedName := fmt.Sprintf("%s#%s", serviceNamespace, shapeName)
146+
if shape, ok := shapes[qualifiedName]; ok {
147+
// Convert Smithy shape to standard format for compatibility
148+
return convertSmithyShape(shape.(map[string]interface{}))
149+
}
150150
}
151151

152-
// If not found and this looks like a Smithy file, try with service namespace
153-
if isSmithyFile(importPath) {
154-
serviceNamespace := extractServiceNamespace(shapes)
155-
if serviceNamespace != "" {
156-
qualifiedName := fmt.Sprintf("%s#%s", serviceNamespace, shapeName)
157-
if shape, ok := shapes[qualifiedName]; ok {
158-
// Convert Smithy shape to Ruby SDK-like format for compatibility
159-
return convertSmithyShape(shape.(map[string]interface{}))
160-
}
161-
}
152+
// Fallback to direct lookup
153+
if shape, ok := shapes[shapeName]; ok {
154+
return shape.(map[string]interface{})
162155
}
163156

164157
return nil
165158
}
166159

167-
// isSmithyFile checks if the import path is for a Smithy file
168-
func isSmithyFile(importPath string) bool {
169-
return strings.Contains(importPath, "api-models-aws") &&
170-
!strings.Contains(importPath, "aws-sdk-ruby")
171-
}
172160

173161
// extractServiceNamespace gets the service namespace from the Smithy shapes
174162
func extractServiceNamespace(shapes map[string]interface{}) string {
@@ -186,7 +174,7 @@ func extractServiceNamespace(shapes map[string]interface{}) string {
186174
return ""
187175
}
188176

189-
// convertSmithyShape converts a Smithy shape format to Ruby SDK-like format
177+
// convertSmithyShape converts a Smithy shape format to standard format
190178
func convertSmithyShape(smithyShape map[string]interface{}) map[string]interface{} {
191179
result := make(map[string]interface{})
192180

@@ -195,7 +183,7 @@ func convertSmithyShape(smithyShape map[string]interface{}) map[string]interface
195183
result["type"] = shapeType
196184
}
197185

198-
// Convert traits to Ruby SDK format
186+
// Convert traits to standard format
199187
if traits, ok := smithyShape["traits"].(map[string]interface{}); ok {
200188
// Handle length constraints
201189
if lengthTrait, ok := traits["smithy.api#length"].(map[string]interface{}); ok {

rules/models/generator/rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func fetchNumber(model map[string]interface{}, key string) int {
8888

8989
func fetchStrings(model map[string]interface{}, key string) []string {
9090
if raw, ok := model[key]; ok {
91-
// Handle both []interface{} (Ruby SDK format) and []string (converted Smithy format)
91+
// Handle both []interface{} (legacy format) and []string (converted Smithy format)
9292
switch v := raw.(type) {
9393
case []interface{}:
9494
ret := make([]string, len(v))
@@ -131,7 +131,7 @@ func replacePattern(pattern string) string {
131131
if !strings.HasPrefix(replaced, "^") && !strings.HasSuffix(replaced, "$") {
132132
// Handle single character classes that should match one or more characters
133133
if replaced == "\\S" {
134-
// Use Ruby SDK compatible format for minimal diff
134+
// Use AWS Service Model Definition compatible format for minimal diff
135135
return "^.*\\S.*$"
136136
}
137137
return fmt.Sprintf("^%s$", replaced)

0 commit comments

Comments
 (0)