Fix CRD validation error for 'items' field

Signed-off-by: He Xiaoxi <xxhe@alauda.io>
This commit is contained in:
He Xiaoxi
2019-06-26 15:30:49 +08:00
parent 879f289ed7
commit 2e37a3bebe
108 changed files with 2356 additions and 1176 deletions

View File

@@ -36,31 +36,39 @@ type schemaPropsValidator struct {
notValidator *SchemaValidator
Root interface{}
KnownFormats strfmt.Registry
Options SchemaValidatorOptions
}
func (s *schemaPropsValidator) SetPath(path string) {
s.Path = path
}
func newSchemaPropsValidator(path string, in string, allOf, oneOf, anyOf []spec.Schema, not *spec.Schema, deps spec.Dependencies, root interface{}, formats strfmt.Registry) *schemaPropsValidator {
func newSchemaPropsValidator(path string, in string, allOf, oneOf, anyOf []spec.Schema, not *spec.Schema, deps spec.Dependencies, root interface{}, formats strfmt.Registry, options ...Option) *schemaPropsValidator {
anyValidators := make([]SchemaValidator, 0, len(anyOf))
for _, v := range anyOf {
anyValidators = append(anyValidators, *NewSchemaValidator(&v, root, path, formats))
v := v
anyValidators = append(anyValidators, *NewSchemaValidator(&v, root, path, formats, options...))
}
allValidators := make([]SchemaValidator, 0, len(allOf))
for _, v := range allOf {
allValidators = append(allValidators, *NewSchemaValidator(&v, root, path, formats))
v := v
allValidators = append(allValidators, *NewSchemaValidator(&v, root, path, formats, options...))
}
oneValidators := make([]SchemaValidator, 0, len(oneOf))
for _, v := range oneOf {
oneValidators = append(oneValidators, *NewSchemaValidator(&v, root, path, formats))
v := v
oneValidators = append(oneValidators, *NewSchemaValidator(&v, root, path, formats, options...))
}
var notValidator *SchemaValidator
if not != nil {
notValidator = NewSchemaValidator(not, root, path, formats)
notValidator = NewSchemaValidator(not, root, path, formats, options...)
}
schOptions := &SchemaValidatorOptions{}
for _, o := range options {
o(schOptions)
}
return &schemaPropsValidator{
Path: path,
In: in,
@@ -75,6 +83,7 @@ func newSchemaPropsValidator(path string, in string, allOf, oneOf, anyOf []spec.
notValidator: notValidator,
Root: root,
KnownFormats: formats,
Options: *schOptions,
}
}
@@ -209,7 +218,7 @@ func (s *schemaPropsValidator) Validate(data interface{}) *Result {
if dep, ok := s.Dependencies[key]; ok {
if dep.Schema != nil {
mainResult.Merge(NewSchemaValidator(dep.Schema, s.Root, s.Path+"."+key, s.KnownFormats).Validate(data))
mainResult.Merge(NewSchemaValidator(dep.Schema, s.Root, s.Path+"."+key, s.KnownFormats, s.Options.Options()...).Validate(data))
continue
}