diff --git a/pkg/config/config.go b/pkg/config/config.go index 447d8fca..f6e521fe 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -25,6 +25,8 @@ type Config struct { // Resources contains generator instructions for individual CRDs within an // API Resources map[string]ResourceConfig `json:"resources"` + // EmptyShapes contains fields associated with empty struct types + EmptyShapes []string `json:"empty_shapes,omitempty"` // CRDs to ignore. ACK generator would skip these resources. Ignore IgnoreSpec `json:"ignore"` // Contains generator instructions for individual API operations. @@ -151,6 +153,17 @@ func (c *Config) GetCustomMapFieldMembers() []string { return members } +// HasEmptyShape returns true if the given shape is setup as empty_shape in config, +// otherwise returns false +func (c *Config) HasEmptyShape(shapeName string) bool { + for _, emptyShape := range c.EmptyShapes { + if emptyShape == shapeName { + return true + } + } + return false +} + // New returns a new Config object given a supplied // path to a config file func New( diff --git a/pkg/generate/code/set_sdk.go b/pkg/generate/code/set_sdk.go index 75c914a1..22450af9 100644 --- a/pkg/generate/code/set_sdk.go +++ b/pkg/generate/code/set_sdk.go @@ -1388,8 +1388,13 @@ func varEmptyConstructorK8sType( switch shape.Type { case "structure": - // f0 := &svcapitypes.BookData{} - out += fmt.Sprintf("%s%s := &%s{}\n", indent, varName, goType) + if r.Config().HasEmptyShape(shape.ShapeName) { + // f0 := map[string]*string{} + out += fmt.Sprintf("%s%s := map[string]*string{}\n", indent, varName) + } else { + // f0 := &svcapitypes.BookData{} + out += fmt.Sprintf("%s%s := &%s{}\n", indent, varName, goType) + } case "list", "map": // f0 := []*string{} out += fmt.Sprintf("%s%s := %s{}\n", indent, varName, goType) diff --git a/pkg/model/model.go b/pkg/model/model.go index 10071835..63069145 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -471,6 +471,12 @@ func (m *Model) getShapeCleanGoType(shape *awssdkmodel.Shape) string { // otherwise there is no DeepCopy support return "*metav1.Time" case "structure": + if len(shape.MemberRefs) == 0 { + if m.cfg.HasEmptyShape(shape.ShapeName) { + return "map[string]*string" + } + panic(fmt.Sprintf("structure %s has no fields, either configure it as a `empty_shape` or manually set the field type", shape.ShapeName)) + } // There are shapes that are called things like DBProxyStatus that are // fields in a DBProxy CRD... we need to ensure the type names don't // conflict. Also, the name of the Go type in the generated code is