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

Add support for validation oneOf #9

Open
raderio opened this issue Apr 12, 2019 · 1 comment · May be fixed by #177
Open

Add support for validation oneOf #9

raderio opened this issue Apr 12, 2019 · 1 comment · May be fixed by #177
Labels
enhancement New feature or request
Milestone

Comments

@raderio
Copy link

raderio commented Apr 12, 2019

For example a login field can be a phone or and email.

@nlochschmidt nlochschmidt added the enhancement New feature or request label Apr 13, 2019
@nlochschmidt nlochschmidt added the help wanted Extra attention is needed label May 3, 2022
@Frontrider
Copy link

Frontrider commented Jul 18, 2023

I'd see the dsl as this:

oneOf("only one of arrayOne or arrayTwo can be present!",{
        MyData::arrayOne{
                minItems(1)
        }
        MyData::arrayTwo{
                maxItems(0)
        }
},{
        MyData::arrayOne{
                maxItems(0)
        }
        MyData::arrayTwo{
                minItems(1)
        }
})

This creates a validation error, if not only one of the rules passed. This specific validation ensures that only one of the specified arrays have any items. I'd set both of the default values to an empty array, and after I parsed it from say json only the array that was present in the input will contain any items.

anyOf("custom message",{
//first validation
},{
//second validation
})

This throws if none of the validations passed.

This may also be just enough for:

@dhoepelman dhoepelman modified the milestones: v0.9.0, v0.10.0 Nov 9, 2024
@dhoepelman dhoepelman removed the help wanted Extra attention is needed label Nov 14, 2024
@dhoepelman dhoepelman modified the milestones: v0.10.0, v0.11.0 Nov 17, 2024
@dhoepelman dhoepelman linked a pull request Nov 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants