Skip to content
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

Unmarshalling failure happens before validation failure #94

Open
maxsokolovsky opened this issue Apr 21, 2020 · 1 comment
Open

Unmarshalling failure happens before validation failure #94

maxsokolovsky opened this issue Apr 21, 2020 · 1 comment

Comments

@maxsokolovsky
Copy link

Looks like for some use-cases govalidator tries to unmarshal request body fields into Go struct fields before running validation. I have a struct:
type S struct { Foo bool `json:"foo"` }

And the following rules:
rules := govalidator.MapData{"foo": []string{"bool"}}

On request, foo could be specified as a value of any type, govalidator should notice that a value cannot be cast to a boolean. But because the struct value is of type bool (and not string, interface{}, etc.), govalidator does not run validation, it first tries to unmarshal the value into a proper bool value of the struct, which fails if the provided value is a string, for example. Should the order be different? Should it stop at the validation error without failing on an unmarshalling error?

@insanrizky
Copy link

Is there any solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants