-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 mutually_exclusive params validation #626
Conversation
squashed latest commits with tweaks. |
@@ -28,3 +28,4 @@ en: | |||
unknown_validator: 'unknown validator: %{validator_type}' | |||
unknown_options: 'unknown options: %{options}' | |||
incompatible_option_values: '%{option1}: %{value1} is incompatible with %{option2}: %{value2}' | |||
mutual_exclusion: 'are mutually exclusive params' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, should this say 'are mutually exclusive', without the 'params'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, removed
I like it very much. I know this is internal, but I think the word It needs an update to CHANGELOG and documentation in README, please. |
Another question, how would you do two groups of mutually exclusive parameters? |
Awesome, I'm glad you like it. About About different groups of mutually exclusive params, good point - I hadn't thought about it. Seems like in the happy scenario each group should just add another validation error if it's caught, and I've added a spec for this. But it is possible to have conflicting groups. Then again, conflict is possible with a single group too: if someone declares two required params as mutually_exclusive, they'll render the endpoint inaccessible. I can add a warning to the README noting this. I'll update it and the changelog tomorrow. Have to say I'm enjoying this DSL design thing ;) It's new to me |
@@ -1,2 +1,2 @@ | |||
--color | |||
--format=progress | |||
--format=documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo this.
I think multiple groups for multiple mutually exclusive parameters is what we want. Make sure to document that clearly in README. Squash the commit. |
@@ -3,6 +3,7 @@ Next Release | |||
|
|||
#### Features | |||
|
|||
* [#626](https://github.com/intridea/grape/pull/626): Mutually exclusive params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please match the format below, you need to add a - [@username](github link).
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
See my minor comments. It's ready to merge otherwise. |
Done. |
Add mutually_exclusive params validation
Merged, thank you. |
I'm working on a project using Grape that validates mutually exclusive params quite a bit, and while digging around for an elegant solution, found somebody asking if there was a way to do it through the dsl.
Seems possible to me, thought I'd take a stab at it. Does this work?
ps noob to Grape's code-base, let me know if I'm doing something stupid :)