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

Align required_without with usage shown in the docs #1324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jmfrees
Copy link

@jmfrees jmfrees commented Oct 3, 2024

Fixes Or Enhances

Resolves #617

Fixes required_without so that it aligns with the stated contract and usage examples.

The docs 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:

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:

type Test struct {
    Field1 string `validator:required_without=Field2 Field3"
    ...
}

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

@jmfrees jmfrees requested a review from a team as a code owner October 3, 2024 23:50
@jmfrees jmfrees changed the title Align required_without with the contract stated in the documentation Align required_without with usage shown in the docs Oct 3, 2024
@coveralls
Copy link

Coverage Status

coverage: 74.295% (+0.003%) from 74.292%
when pulling 91f421e on jmfrees:jmfrees/fix-required_without
into f1939ee on go-playground:master.

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

Successfully merging this pull request may close these issues.

required_without doesn't seem to work with multiple fields
2 participants