Skip to content

Commit e467f52

Browse files
committed
Remove incorrect zero value check
This check never returned true prior to go1.16, because using DeepEqual on reflect.Value return values checks their internal fields, and reflect.Zero included a unique unsafe pointer. In go1.16, reflect.Zero started returning shared zero values, and this check started returning true. However, requiring nullable on zero values is not correct. A zero value string "" should be valid even if the schema does not allow the field to be null.
1 parent 15cd8fa commit e467f52

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/validation/validate/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (t *typeValidator) Applies(source interface{}, kind reflect.Kind) bool {
132132
func (t *typeValidator) Validate(data interface{}) *Result {
133133
result := new(Result)
134134
result.Inc()
135-
if data == nil || reflect.DeepEqual(reflect.Zero(reflect.TypeOf(data)), reflect.ValueOf(data)) {
135+
if data == nil {
136136
// nil or zero value for the passed structure require Type: null
137137
if len(t.Type) > 0 && !t.Type.Contains(nullType) && !t.Nullable { // TODO: if a property is not required it also passes this
138138
return errorHelp.sErr(errors.InvalidType(t.Path, t.In, strings.Join(t.Type, ","), nullType))

0 commit comments

Comments
 (0)