Commit 5b31512
authored
Align required_without with the contract stated in the documentation (#1422)
## Fixes Or Enhances
Resolves #617
Fixes `required_without` so that it aligns with the stated contract and
usage examples.
The
[docs](https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Required_Without)
valid usage to be:
```
// require the field if the Field1 is not present:
Usage: required_without=Field1
// require the field if the Field1 or Field2 is not present:
Usage: required_without=Field1 Field2
```
However, as show in this issue:
#617, you can only use
`required_without` on multiple fields like:
```golang
type Test struct {
Field1 string `validator:required_without=Field2,required_without=Field3"
...
}
```
This PR aligns the behavior of the `required_without` validator such
that you can also use it as shown in the example:
```golang
type Test struct {
Field1 string `validator:required_without=Field2 Field3"
...
}
```
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.
Note: Sorry for the duplication of #1324. I was cleaning up my profile
and deleted my fork before it could be merged.
@go-playground/validator-maintainers1 parent c3fc72e commit 5b31512
2 files changed
+31
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2004 | 2004 | | |
2005 | 2005 | | |
2006 | 2006 | | |
2007 | | - | |
2008 | | - | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
2009 | 2012 | | |
2010 | 2013 | | |
2011 | 2014 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11865 | 11865 | | |
11866 | 11866 | | |
11867 | 11867 | | |
| 11868 | + | |
| 11869 | + | |
| 11870 | + | |
| 11871 | + | |
| 11872 | + | |
| 11873 | + | |
| 11874 | + | |
| 11875 | + | |
| 11876 | + | |
| 11877 | + | |
| 11878 | + | |
| 11879 | + | |
| 11880 | + | |
| 11881 | + | |
| 11882 | + | |
| 11883 | + | |
| 11884 | + | |
| 11885 | + | |
| 11886 | + | |
| 11887 | + | |
| 11888 | + | |
| 11889 | + | |
| 11890 | + | |
| 11891 | + | |
| 11892 | + | |
| 11893 | + | |
11868 | 11894 | | |
11869 | 11895 | | |
11870 | 11896 | | |
| |||
0 commit comments