Skip to content

Commit 88f0bdd

Browse files
author
Phillip Wittrock
authored
Merge pull request #71 from Liujingfang1/kube
update validation for core types
2 parents d81dcab + 3758197 commit 88f0bdd

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

cmd/internal/codegen/parse/validation.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,27 @@ var objectTemplate = template.Must(template.New("object-template").Parse(
265265
}`))
266266

267267
func (b *APIs) parseObjectValidation(t *types.Type, found sets.String, comments []string) (v1beta1.JSONSchemaProps, string) {
268-
m, result := b.getMembers(t, found)
268+
buff := &bytes.Buffer{}
269269
props := v1beta1.JSONSchemaProps{
270-
Type: "object",
271-
Properties: m,
270+
Type: "object",
272271
}
273272

274-
// Only add field validation for non-inlined fields
275-
for _, l := range comments {
276-
getValidation(l, &props)
277-
}
273+
if strings.HasPrefix(t.Name.String(), "k8s.io/api") {
274+
if err := objectTemplate.Execute(buff, objectTemplateArgs{props, nil}); err != nil {
275+
log.Fatalf("%v", err)
276+
}
277+
} else {
278+
m, result := b.getMembers(t, found)
279+
props.Properties = m
278280

279-
buff := &bytes.Buffer{}
280-
if err := objectTemplate.Execute(buff, objectTemplateArgs{props, result}); err != nil {
281-
log.Fatalf("%v", err)
281+
// Only add field validation for non-inlined fields
282+
for _, l := range comments {
283+
getValidation(l, &props)
284+
}
285+
286+
if err := objectTemplate.Execute(buff, objectTemplateArgs{props, result}); err != nil {
287+
log.Fatalf("%v", err)
288+
}
282289
}
283290
return props, buff.String()
284291
}

0 commit comments

Comments
 (0)