diff --git a/pkg/model/attr.go b/pkg/model/attr.go index 701322f7..2de98275 100644 --- a/pkg/model/attr.go +++ b/pkg/model/attr.go @@ -24,6 +24,7 @@ type Attr struct { Names names.Names GoType string Shape *awssdkmodel.Shape + ShapeRef *awssdkmodel.ShapeRef GoTag string IsImmutable bool } @@ -32,14 +33,30 @@ func NewAttr( names names.Names, goType string, shape *awssdkmodel.Shape, + shapeRef *awssdkmodel.ShapeRef, ) *Attr { return &Attr{ - Names: names, - GoType: goType, - Shape: shape, + Names: names, + GoType: goType, + Shape: shape, + ShapeRef: shapeRef, } } +// Documentation returns the godoc-formatted documentation for this attribute. +// It checks the Shape documentation first (type-level docs), then falls back +// to the ShapeRef documentation (member-specific docs for fields like +// primitives where the Shape is shared). +func (a *Attr) Documentation() string { + if a.Shape != nil && a.Shape.Documentation != "" { + return a.Shape.Documentation + } + if a.ShapeRef != nil && a.ShapeRef.Documentation != "" { + return a.ShapeRef.Documentation + } + return "" +} + // GetGoTag returns the Go Tag to inject for this attribute. If the GoTag // field is not empty, it will be used. Otherwise, one will be generated // from the attribute's name. diff --git a/pkg/model/model.go b/pkg/model/model.go index d703655c..30c007d0 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -638,7 +638,7 @@ func (m *Model) GetTypeDefs() ([]*TypeDef, error) { if err != nil { return nil, err } - attrs[memberName] = NewAttr(memberNames, gt, memberShape) + attrs[memberName] = NewAttr(memberNames, gt, memberShape, memberRef) } if len(attrs) == 0 { // Just ignore these... @@ -951,7 +951,7 @@ func addReferenceAttribute(td *TypeDef, attr *Attr) error { if attr.Shape.Type == "list" { refAttrGoType = fmt.Sprintf("[]%s", refAttrGoType) } - refAttr := NewAttr(refAttrName, refAttrGoType, refAttrShape) + refAttr := NewAttr(refAttrName, refAttrGoType, refAttrShape, nil) // Add reference attribute to the parent field typedef td.Attrs[refAttrName.Original] = refAttr return nil diff --git a/templates/apis/type_def.go.tpl b/templates/apis/type_def.go.tpl index 84032aeb..b54b1223 100644 --- a/templates/apis/type_def.go.tpl +++ b/templates/apis/type_def.go.tpl @@ -5,8 +5,8 @@ type {{ .Names.Camel }} struct { {{- range $attrName := .SortedAttrNames }} {{- $attr := (index $.Attrs $attrName) }} - {{- if $attr.Shape.Documentation }} - {{ $attr.Shape.Documentation }} + {{- if $attr.Documentation }} + {{ $attr.Documentation }} {{- end }} {{- if $attr.IsImmutable }} // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable once set" diff --git a/templates/crossplane/apis/type_def.go.tpl b/templates/crossplane/apis/type_def.go.tpl index aa00c82c..17b7e32b 100644 --- a/templates/crossplane/apis/type_def.go.tpl +++ b/templates/crossplane/apis/type_def.go.tpl @@ -3,8 +3,8 @@ type {{ .Names.Camel }} struct { {{- range $attrName := .SortedAttrNames }} {{- $attr := (index $.Attrs $attrName) }} - {{- if $attr.Shape }} - {{ $attr.Shape.Documentation }} + {{- if $attr.Documentation }} + {{ $attr.Documentation }} {{- end }} {{ $attr.Names.Camel }} {{ $attr.GoType }} `json:"{{ $attr.Names.CamelLower }},omitempty"` {{- end }}