@@ -23,6 +23,7 @@ import (
23
23
"github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset"
24
24
"github.com/aws-controllers-k8s/code-generator/pkg/names"
25
25
"github.com/aws-controllers-k8s/code-generator/pkg/util"
26
+ awssdkmodel "github.com/aws/aws-sdk-go/private/model/api"
26
27
)
27
28
28
29
var (
@@ -316,44 +317,7 @@ func (m *Model) GetTypeDefs() ([]*TypeDef, error) {
316
317
if ! m .IsShapeUsedInCRDs (memberShape .ShapeName ) {
317
318
continue
318
319
}
319
- // There are shapes that are called things like DBProxyStatus that are
320
- // fields in a DBProxy CRD... we need to ensure the type names don't
321
- // conflict. Also, the name of the Go type in the generated code is
322
- // Camel-cased and normalized, so we use that as the Go type
323
- gt := memberShape .GoType ()
324
- if memberShape .Type == "structure" {
325
- typeNames := names .New (memberShape .ShapeName )
326
- if m .SDKAPI .HasConflictingTypeName (memberShape .ShapeName , m .cfg ) {
327
- typeNames .Camel += ConflictingNameSuffix
328
- }
329
- gt = "*" + typeNames .Camel
330
- } else if memberShape .Type == "list" {
331
- // If it's a list type, where the element is a structure, we need to
332
- // set the GoType to the cleaned-up Camel-cased name
333
- if memberShape .MemberRef .Shape .Type == "structure" {
334
- elemType := memberShape .MemberRef .Shape .GoTypeElem ()
335
- typeNames := names .New (elemType )
336
- if m .SDKAPI .HasConflictingTypeName (elemType , m .cfg ) {
337
- typeNames .Camel += ConflictingNameSuffix
338
- }
339
- gt = "[]*" + typeNames .Camel
340
- }
341
- } else if memberShape .Type == "map" {
342
- // If it's a map type, where the value element is a structure,
343
- // we need to set the GoType to the cleaned-up Camel-cased name
344
- if memberShape .ValueRef .Shape .Type == "structure" {
345
- valType := memberShape .ValueRef .Shape .GoTypeElem ()
346
- typeNames := names .New (valType )
347
- if m .SDKAPI .HasConflictingTypeName (valType , m .cfg ) {
348
- typeNames .Camel += ConflictingNameSuffix
349
- }
350
- gt = "[]map[string]*" + typeNames .Camel
351
- }
352
- } else if memberShape .Type == "timestamp" {
353
- // time.Time needs to be converted to apimachinery/metav1.Time
354
- // otherwise there is no DeepCopy support
355
- gt = "*metav1.Time"
356
- }
320
+ gt := m .getShapeCleanGoType (memberShape )
357
321
attrs [memberName ] = NewAttr (memberNames , gt , memberShape )
358
322
}
359
323
if len (attrs ) == 0 {
@@ -375,6 +339,37 @@ func (m *Model) GetTypeDefs() ([]*TypeDef, error) {
375
339
return tdefs , nil
376
340
}
377
341
342
+ // getShapeCleanGoType returns a cleaned-up and Camel-cased GoType name for a given shape.
343
+ func (m * Model ) getShapeCleanGoType (shape * awssdkmodel.Shape ) string {
344
+ switch shape .Type {
345
+ case "map" :
346
+ // If it's a map type we need to set the GoType to the cleaned-up
347
+ // Camel-cased name
348
+ return "map[string]" + m .getShapeCleanGoType (shape .ValueRef .Shape )
349
+ case "list" , "array" , "blob" :
350
+ // If it's a list type, we need to set the GoType to the cleaned-up
351
+ // Camel-cased name
352
+ return "[]" + m .getShapeCleanGoType (shape .MemberRef .Shape )
353
+ case "timestamp" :
354
+ // time.Time needs to be converted to apimachinery/metav1.Time
355
+ // otherwise there is no DeepCopy support
356
+ return "*metav1.Time"
357
+ case "structure" :
358
+ // There are shapes that are called things like DBProxyStatus that are
359
+ // fields in a DBProxy CRD... we need to ensure the type names don't
360
+ // conflict. Also, the name of the Go type in the generated code is
361
+ // Camel-cased and normalized, so we use that as the Go type
362
+ goType := shape .GoType ()
363
+ typeNames := names .New (goType )
364
+ if m .SDKAPI .HasConflictingTypeName (goType , m .cfg ) {
365
+ typeNames .Camel += ConflictingNameSuffix
366
+ }
367
+ return "*" + typeNames .Camel
368
+ default :
369
+ return shape .GoType ()
370
+ }
371
+ }
372
+
378
373
// processNestedFieldTypeDefs updates the supplied TypeDef structs' if a nested
379
374
// field has been configured with a type overriding FieldConfig -- such as
380
375
// FieldConfig.IsSecret.
0 commit comments