validate
validate copied to clipboard
Nested resources are evaluated differently
System (please complete the following information):
- OS:
macOS - GO Version:
1.20 - Pkg Version:
1.4.6
Describe the bug
Nested resources are evaluated differently. This is super confusing and buggy.
To Reproduce
https://go.dev/play/p/-4zzXj4NxLK
package main
import (
"fmt"
"github.com/gookit/validate"
)
type Sample struct {
Val *bool `validate:"required"`
}
type Nested struct {
Samples []Sample `validate:"slice"`
}
func main() {
val, val2 := false, true
data := Sample{
Val: &val,
}
data2 := Sample{
Val: &val2,
}
data3 := Sample{
Val: nil,
}
data4 := Nested{
Samples: []Sample{data, data2},
}
v1 := validate.Struct(data)
ok1 := v1.Validate()
v2 := validate.Struct(data2)
ok2 := v2.Validate()
v3 := validate.Struct(data3)
ok3 := v3.Validate()
v4 := validate.Struct(data4)
ok4 := v4.Validate()
fmt.Println(ok1, v1.Errors) // Should not fail and does not fail.
fmt.Println(ok2, v2.Errors) // Should not fail and does not fail.
fmt.Println(ok3, v3.Errors) // Should fail and fails.
fmt.Println(ok4, v4.Errors) // Should not fail and fails.
}
Expected behavior
The Nested data structure at data4 should validate correctly.
Screenshots
n/a
Additional context
n/a