Check for an empty value in validateField
reflect.TypeOf() can take a nil (it then returns a nil), but Kind() panics on a nil. Fixes #20627
This commit is contained in:
@@ -297,6 +297,10 @@ func (s *SwaggerSchema) isGenericArray(p swagger.ModelProperty) bool {
|
||||
var versionRegexp = regexp.MustCompile(`^v.+\..*`)
|
||||
|
||||
func (s *SwaggerSchema) validateField(value interface{}, fieldName, fieldType string, fieldDetails *swagger.ModelProperty) []error {
|
||||
allErrs := []error{}
|
||||
if reflect.TypeOf(value) == nil {
|
||||
return append(allErrs, fmt.Errorf("unexpected nil value for field %v", fieldName))
|
||||
}
|
||||
// TODO: caesarxuchao: because we have multiple group/versions and objects
|
||||
// may reference objects in other group, the commented out way of checking
|
||||
// if a filedType is a type defined by us is outdated. We use a hacky way
|
||||
@@ -310,7 +314,6 @@ func (s *SwaggerSchema) validateField(value interface{}, fieldName, fieldType st
|
||||
// if strings.HasPrefix(fieldType, apiVersion) {
|
||||
return s.ValidateObject(value, fieldName, fieldType)
|
||||
}
|
||||
allErrs := []error{}
|
||||
switch fieldType {
|
||||
case "string":
|
||||
// Be loose about what we accept for 'string' since we use IntOrString in a couple of places
|
||||
|
Reference in New Issue
Block a user