Open raybog opened 3 years ago
0 is treated as nil value and validators are ignored due to omiempty
you should use pointer for that, because of omitempty behavior
this is on the documentation:
Omit Empty Allows conditional validation, for example if a field is not set with a value (Determined by the "required" validator) then other validation such as min or max won't run, but if a value is set validation will run.
Required This validates that the value is not the data types default zero value. For numbers ensures value is not zero. For strings ensures value is not "". For slices, maps, pointers, interfaces, channels and functions ensures the value is not nil.
In your case, you use int where it's default value is 0, so omitempty will be triggered if it is 0.
Description
Binding error when using
omitempty
along withgte
ormin
whengte=1
ormin=1
and parmaeter is0
.How to reproduce
Expectations
Actual result
Environment