Skip to content

Commit 9995627

Browse files
committed
Add missing comments for internal validation generation
1 parent 4e6d726 commit 9995627

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cmd/internal/codegen/parse/validation.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
"text/template"
3333
)
3434

35+
// parseJSONSchemaProps populates the CRD field of each Group.Version.Resource,
36+
// creating validations using the annotations on type fields.
3537
func (b *APIs) parseJSONSchemaProps() {
3638
for _, group := range b.APIs.Groups {
3739
for _, version := range group.Versions {
@@ -94,6 +96,8 @@ func (b *APIs) getMeta() string {
9496
}`
9597
}
9698

99+
// typeToJSONSchemaProps returns a JSONSchemaProps object and its serialization
100+
// in Go that describe the JSONSchema validations for the given type.
97101
func (b *APIs) typeToJSONSchemaProps(t *types.Type, found sets.String, comments []string) (v1beta1.JSONSchemaProps, string) {
98102
// Special cases
99103
time := types.Name{Name: "Time", Package: "k8s.io/apimachinery/pkg/apis/meta/v1"}
@@ -165,6 +169,9 @@ var primitiveTemplate = template.Must(template.New("map-template").Parse(
165169
{{ end -}}
166170
}`))
167171

172+
// parsePrimitiveValidation returns a JSONSchemaProps object and its
173+
// serialization in Go that describe the validations for the given primitive
174+
// type.
168175
func (b *APIs) parsePrimitiveValidation(t *types.Type, found sets.String, comments []string) (v1beta1.JSONSchemaProps, string) {
169176
props := v1beta1.JSONSchemaProps{Type: string(t.Name.Name)}
170177

@@ -211,6 +218,8 @@ var mapTemplate = template.Must(template.New("map-template").Parse(
211218
},
212219
}`))
213220

221+
// parseMapValidation returns a JSONSchemaProps object and its serialization in
222+
// Go that describe the validations for the given map type.
214223
func (b *APIs) parseMapValidation(t *types.Type, found sets.String, comments []string) (v1beta1.JSONSchemaProps, string) {
215224
additionalProps, _ := b.typeToJSONSchemaProps(t.Elem, found, comments)
216225
props := v1beta1.JSONSchemaProps{
@@ -235,6 +244,8 @@ var arrayTemplate = template.Must(template.New("array-template").Parse(
235244
},
236245
}`))
237246

247+
// parseArrayValidation returns a JSONSchemaProps object and its serialization in
248+
// Go that describe the validations for the given array type.
238249
func (b *APIs) parseArrayValidation(t *types.Type, found sets.String, comments []string) (v1beta1.JSONSchemaProps, string) {
239250
items, result := b.typeToJSONSchemaProps(t.Elem, found, comments)
240251
props := v1beta1.JSONSchemaProps{
@@ -264,6 +275,8 @@ var objectTemplate = template.Must(template.New("object-template").Parse(
264275
},
265276
}`))
266277

278+
// parseObjectValidation returns a JSONSchemaProps object and its serialization in
279+
// Go that describe the validations for the given object type.
267280
func (b *APIs) parseObjectValidation(t *types.Type, found sets.String, comments []string) (v1beta1.JSONSchemaProps, string) {
268281
buff := &bytes.Buffer{}
269282
props := v1beta1.JSONSchemaProps{
@@ -290,6 +303,8 @@ func (b *APIs) parseObjectValidation(t *types.Type, found sets.String, comments
290303
return props, buff.String()
291304
}
292305

306+
// getValidation parses the validation tags from the comment and sets the
307+
// validation rules on the given JSONSchemaProps.
293308
func getValidation(comment string, props *v1beta1.JSONSchemaProps) {
294309
comment = strings.TrimLeft(comment, " ")
295310
if !strings.HasPrefix(comment, "+kubebuilder:validation:") {
@@ -392,6 +407,8 @@ func getValidation(comment string, props *v1beta1.JSONSchemaProps) {
392407
}
393408
}
394409

410+
// getMembers builds maps by field name of the JSONSchemaProps and their Go
411+
// serializations.
395412
func (b *APIs) getMembers(t *types.Type, found sets.String) (map[string]v1beta1.JSONSchemaProps, map[string]string) {
396413
members := map[string]v1beta1.JSONSchemaProps{}
397414
result := map[string]string{}

0 commit comments

Comments
 (0)