-
-
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
Allow parameter only if another parameter is present. #958
Comments
That's a good idea.I just have this demand.
We want at least one of |
@u2 We already have |
Thank you.:smile: |
After thinking about this for a bit, I think it'd be more useful to be able to say "if Option 1 (DSL style)https://github.com/rnubel/grape/compare/dependent_parameters_dsl params do
optional :shelf_id, type: Integer
if_given :shelf_id do
requires :shelf_reachable, type: Boolean
end
end Option 2 (Validation style)https://github.com/rnubel/grape/compare/dependent_parameters_validation params do
optional :shelf_id, type: Integer
optional :shelf_reachable, type: Boolean
if_given :shelf_id, require: :shelf_reachable
end What do you think? |
I like the first one, but I don't love the name. Maybe just |
Hmm... params do
optional :shelf_id, type: Integer
given :shelf_id do
requires :shelf_reachable, type: Boolean
end
end |
I like |
Usage: # ... params do optional :shelf_id, type: Integer given :shelf_id do requires :bin_id, type: Integer end end This implements ruby-grape#958. In order to achieve the DSL-style implementation, I introduced the concept of a "lateral scope" as opposed to the "nested scope" which `requires :foo do` opens up. A lateral scope is subordinate to its parent, but not nested under an element.
Usage: # ... params do optional :shelf_id, type: Integer given :shelf_id do requires :bin_id, type: Integer end end This implements ruby-grape#958. In order to achieve the DSL-style implementation, I introduced the concept of a "lateral scope" as opposed to the "nested scope" which `requires :foo do` opens up. A lateral scope is subordinate to its parent, but not nested under an element.
Usage: # ... params do optional :shelf_id, type: Integer given :shelf_id do requires :bin_id, type: Integer end end This implements ruby-grape#958. In order to achieve the DSL-style implementation, I introduced the concept of a "lateral scope" as opposed to the "nested scope" which `requires :foo do` opens up. A lateral scope is subordinate to its parent, but not nested under an element.
Usage: # ... params do optional :shelf_id, type: Integer given :shelf_id do requires :bin_id, type: Integer end end This implements ruby-grape#958. In order to achieve the DSL-style implementation, I introduced the concept of a "lateral scope" as opposed to the "nested scope" which `requires :foo do` opens up. A lateral scope is subordinate to its parent, but not nested under an element.
This was resolved in #1047. |
For example:
You shouldn't be able to specify
shelf_reachable
unless:shelf_id
is present.The text was updated successfully, but these errors were encountered: