-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1.4.6 change has broken existing behaviour #192
Comments
I thought I was going crazy! I'm new to In my case I have: type SubConfig1 struct {
Val int `validate:"required|min:1|max:65535"`
}
type SubConfig2 struct {
Name string `validate:"required|in:foobar"`
}
type Config struct {
Sub1 *SubConfig1
Sub2 *SubConfig2
} and then ignoring the other sub-config structs depending on what the user passes in: // [...]
user_command := "do2"
idx := map[string]string{
"Sub1": "do1",
"Sub2": "do2",
}
for field_name, cmd := range idx {
if user_command != cmd {
v.AddRule(field_name, "safe")
}
} I'm sure there is an easier way (that doesn't involve that Thanks @inhere for saving my evening :) |
Can I get some indication if this is a bug that will be fixed or if I was relying on undocumented behaviour? If I was relying on undocumented behaviour and this isn't a bug to be fixed then I need to find some other way or library to achieve this validation. |
hi @lsh-0 @madhurbhaiya @OscarVanL Add new validator On struct, add Lines 1267 to 1306 in 27b33f1
|
thank you @inhere, using the master branch of |
Please upgrade to https://github.com/gookit/validate/releases/tag/v1.5.2 |
Regression
This change has broken existing behaviour.
For eg: I have a JSON:
Now, as per validation rules, key
main1
andmain2
are optional. And their respective children keys should be validated only when main key exists.The validation rules are defined as:
Earlier, uptil v1.4.5, these definitions were working fine and children struct was validated only when the respective main key existed
Now, with the release v1.4.6 , this behaviour does not work anymore as nil pointer check is removed.
Originally posted by @madhurbhaiya in #191 (comment)
The text was updated successfully, but these errors were encountered: