Skip to content

Commit e278e1a

Browse files
Add base CRD documentation (#89)
Description of changes: Replaces the comment block for CRDs with the documentation of the resource shape from the AWS SDK. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 99e7023 commit e278e1a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/model/crd.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package model
1515

1616
import (
17+
"fmt"
1718
"sort"
1819
"strings"
1920

@@ -106,6 +107,18 @@ func (r *CRD) TypeRenames() map[string]string {
106107
return r.sdkAPI.GetTypeRenames(r.cfg)
107108
}
108109

110+
// Documentation returns the base documentation string for the API formatted as
111+
// a Go code comment block
112+
func (r *CRD) Documentation() string {
113+
docString := fmt.Sprintf("// %sSpec defines the desired state of %s.", r.Names.Original, r.Names.Original)
114+
shape, ok := r.sdkAPI.API.Shapes[r.Names.Original]
115+
if ok {
116+
// Separate with a double newline to force a newline in the CRD base
117+
docString += "\n//\n" + shape.Documentation
118+
}
119+
return docString
120+
}
121+
109122
// HasShapeAsMember returns true if the supplied Shape name appears in *any*
110123
// payload shape of *any* Operation for the resource. It recurses down through
111124
// the resource's Operation Input and Output shapes and their member shapes

templates/apis/crd.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
)
1515

16-
// {{ .CRD.Kind }}Spec defines the desired state of {{ .CRD.Kind }}
16+
{{ .CRD.Documentation }}
1717
type {{ .CRD.Kind }}Spec struct {
1818
{{- range $fieldName, $field := .CRD.SpecFields }}
1919
{{- if $field.ShapeRef }}

0 commit comments

Comments
 (0)