go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.06k stars 1.29k forks source link

Make docs for required more explicit regarding boolean values #1261

Closed alexongh closed 1 month ago

alexongh commented 1 month ago

required validates that the value is not the data types default zero value. For boolean the default zero value is false. Therefore, a false boolean value would be interpreted as not matching the required validation and fail.

This, in my opinion, is a little unexpected. Judging from the name required only, I expected that a false boolean value would be ok, since a value was provided.

Nevertheless, in my opinion, this behavior should be documented a little more explicitly. Which is why I propose this change to the docs.

@go-playground/validator-maintainers

coveralls commented 1 month ago

Coverage Status

coverage: 74.243%. remained the same when pulling 043e9ee10186ea374ef9b82d45419cdee8a8a5ee on alexongh:master into e20b94842ab102ba94e73eaf66f5c0466e405882 on go-playground:master.

JackFeng7 commented 3 weeks ago

This, in my opinion, is a little unexpected. Judging from the name required only, I expected that a false boolean value would be ok, since a value was provided.

Can we recover the literal meaning of required instead of being kidnapped by go's zero value ?