Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions pkg/model/attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Attr struct {
Names names.Names
GoType string
Shape *awssdkmodel.Shape
ShapeRef *awssdkmodel.ShapeRef
GoTag string
IsImmutable bool
}
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions templates/apis/type_def.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions templates/crossplane/apis/type_def.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down