Skip to content

Commit ec4cbc2

Browse files
committed
add support for empty shapes, used as markers
1 parent 587b90d commit ec4cbc2

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

pkg/config/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type Config struct {
2525
// Resources contains generator instructions for individual CRDs within an
2626
// API
2727
Resources map[string]ResourceConfig `json:"resources"`
28+
// MarkerShapes contains fields associated with empty structs used as markers
29+
MarkerShapes []string `json:"marker_shapes,omitempty"`
2830
// CRDs to ignore. ACK generator would skip these resources.
2931
Ignore IgnoreSpec `json:"ignore"`
3032
// Contains generator instructions for individual API operations.
@@ -151,6 +153,17 @@ func (c *Config) GetCustomMapFieldMembers() []string {
151153
return members
152154
}
153155

156+
// IsMarkerShape returns true if a given shape name is a marker shape,
157+
// otherwise returns false
158+
func (c *Config) IsMarkerShape(shapeName string) bool {
159+
for _, markerShape := range c.MarkerShapes {
160+
if markerShape == shapeName {
161+
return true
162+
}
163+
}
164+
return false
165+
}
166+
154167
// New returns a new Config object given a supplied
155168
// path to a config file
156169
func New(

pkg/generate/code/set_sdk.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,13 @@ func varEmptyConstructorK8sType(
13881388

13891389
switch shape.Type {
13901390
case "structure":
1391-
// f0 := &svcapitypes.BookData{}
1392-
out += fmt.Sprintf("%s%s := &%s{}\n", indent, varName, goType)
1391+
if r.Config().IsMarkerShape(shape.ShapeName) {
1392+
// f0 := []byte{}
1393+
out += fmt.Sprintf("%s%s := []byte{}\n", indent, varName)
1394+
} else {
1395+
// f0 := &svcapitypes.BookData{}
1396+
out += fmt.Sprintf("%s%s := &%s{}\n", indent, varName, goType)
1397+
}
13931398
case "list", "map":
13941399
// f0 := []*string{}
13951400
out += fmt.Sprintf("%s%s := %s{}\n", indent, varName, goType)

pkg/model/model.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package model
1616
import (
1717
"errors"
1818
"fmt"
19+
"slices"
1920
"sort"
2021
"strings"
2122

@@ -395,6 +396,11 @@ func (m *Model) IsShapeUsedInCRDs(shapeName string) bool {
395396
return false
396397
}
397398

399+
// IsMarkerShape return true if the supplied shape name is a marker shape
400+
func (m *Model) IsMarkerShape(shapeName string) bool {
401+
return slices.Contains(m.cfg.MarkerShapes, shapeName)
402+
}
403+
398404
// GetTypeDefs returns a slice of `TypeDef` pointers
399405
func (m *Model) GetTypeDefs() ([]*TypeDef, error) {
400406
if m.typeDefs != nil {
@@ -471,6 +477,12 @@ func (m *Model) getShapeCleanGoType(shape *awssdkmodel.Shape) string {
471477
// otherwise there is no DeepCopy support
472478
return "*metav1.Time"
473479
case "structure":
480+
if len(shape.MemberRefs) == 0 {
481+
if m.cfg.IsMarkerShape(shape.ShapeName) {
482+
return "[]byte"
483+
}
484+
panic(fmt.Sprintf("structure %s has no fields, either configure it as a `marker_shape` or manually set the field type", shape.ShapeName))
485+
}
474486
// There are shapes that are called things like DBProxyStatus that are
475487
// fields in a DBProxy CRD... we need to ensure the type names don't
476488
// conflict. Also, the name of the Go type in the generated code is

0 commit comments

Comments
 (0)