Skip to content

Commit

Permalink
Merge pull request #71 from Liujingfang1/kube
Browse files Browse the repository at this point in the history
update validation for core types
  • Loading branch information
Phillip Wittrock authored Apr 17, 2018
2 parents d81dcab + 3758197 commit 88f0bdd
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions cmd/internal/codegen/parse/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,27 @@ var objectTemplate = template.Must(template.New("object-template").Parse(
}`))

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

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

buff := &bytes.Buffer{}
if err := objectTemplate.Execute(buff, objectTemplateArgs{props, result}); err != nil {
log.Fatalf("%v", err)
// Only add field validation for non-inlined fields
for _, l := range comments {
getValidation(l, &props)
}

if err := objectTemplate.Execute(buff, objectTemplateArgs{props, result}); err != nil {
log.Fatalf("%v", err)
}
}
return props, buff.String()
}
Expand Down

0 comments on commit 88f0bdd

Please sign in to comment.