go-macaron / binding

Package binding is a middleware that provides request data binding and validation for Macaron.
Apache License 2.0
23 stars 17 forks source link

Error In Validation "In()" also implies Required #21

Closed toni-moreno closed 7 years ago

toni-moreno commented 7 years ago

When I'm defining an enum validation , I would like also give a default value.

SnmpDebug bool `xorm:"snmpdebug" binding:"Default(0);In(0,1)"`  

but when omitting the "snmpdebug" parameter the following error is shown

[
  {
    "fieldNames": [
      "SnmpDebug"
    ],
    "classification": "InError",
    "message": "In"
  }
]

But I've set the Default value as 0, so validation has been done erroneously.

unknwon commented 7 years ago

Hi, I think you should use OmitEmpty before other rules in this case: https://go-macaron.com/docs/middlewares/binding#validation-rules