We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
System :
macOS
1.19
1.5.1
Describe the bug
required_if 中,当指定的 anotherField 为 uint8 类型时,校验失效. 我的待验证结构体为
type MyStruc struct { ID int64 `json:"id" validate:"required"` Type uint8 `json:"ip_type" validate:"in:0,1"` IpList []string `json:"ip_list" validate:"required|validateIP"` Field int `json:"field" validate:"required_if:Type,1"` }
我指定了,当 Type=1 时,Field 是必须的,但实际上此条 required_if 并为生效。
Type=1
Field
required_if
原因 阅读源码,发现在进行 required_if 校验时,调用 convTypeByBaseKind 方法将结构体 tag 中的值进行类型转换为目标类型并与目标值对比时,方法中并未做 uint8 的类型转换,截图如下:
convTypeByBaseKind
uint8
我将短暂的将我的 Type 类型设置为 int 以解决我的问题。
Type
int
The text was updated successfully, but these errors were encountered:
已修复,下个版本发布
Sorry, something went wrong.
🐛 fix: util convTypeByBaseKind support more basic type convert. issues …
b24adf8
…#245
Please upgrade to https://github.com/gookit/validate/releases/tag/v1.5.2
inhere
No branches or pull requests
System :
macOS
1.19
1.5.1
Describe the bug
required_if 中,当指定的 anotherField 为 uint8 类型时,校验失效.
我的待验证结构体为
我指定了,当
Type=1
时,Field
是必须的,但实际上此条required_if
并为生效。原因

阅读源码,发现在进行
required_if
校验时,调用convTypeByBaseKind
方法将结构体 tag 中的值进行类型转换为目标类型并与目标值对比时,方法中并未做uint8
的类型转换,截图如下:我将短暂的将我的
Type
类型设置为int
以解决我的问题。The text was updated successfully, but these errors were encountered: