Commit 0177cbae authored by Xing Zhou's avatar Xing Zhou

Improve error messages for ValidateObject method.

Improved error messages for method #ValidateObject in pkg/api/validation/schema.go.
parent 13424d87
...@@ -281,7 +281,7 @@ func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName stri ...@@ -281,7 +281,7 @@ func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName stri
// handle required fields // handle required fields
for _, requiredKey := range model.Required { for _, requiredKey := range model.Required {
if _, ok := fields[requiredKey]; !ok { if _, ok := fields[requiredKey]; !ok {
allErrs = append(allErrs, fmt.Errorf("field %s for %s: is required", requiredKey, typeName)) allErrs = append(allErrs, fmt.Errorf("field %s%s for %s is required", fieldName, requiredKey, typeName))
} }
} }
for key, value := range fields { for key, value := range fields {
...@@ -302,7 +302,7 @@ func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName stri ...@@ -302,7 +302,7 @@ func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName stri
continue continue
} }
if details.Type == nil && details.Ref == nil { if details.Type == nil && details.Ref == nil {
allErrs = append(allErrs, fmt.Errorf("could not find the type of %s from object: %v", key, details)) allErrs = append(allErrs, fmt.Errorf("could not find the type of %s%s from object %v", fieldName, key, details))
} }
var fieldType string var fieldType string
if details.Type != nil { if details.Type != nil {
...@@ -311,7 +311,7 @@ func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName stri ...@@ -311,7 +311,7 @@ func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName stri
fieldType = *details.Ref fieldType = *details.Ref
} }
if value == nil { if value == nil {
glog.V(2).Infof("Skipping nil field: %s", key) glog.V(2).Infof("Skipping nil field: %s%s", fieldName, key)
continue continue
} }
errs := s.validateField(value, fieldName+key, fieldType, &details) errs := s.validateField(value, fieldName+key, fieldType, &details)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment