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

Use param foo in default for bar #2290

Open
jamesarosen opened this issue Dec 16, 2022 · 1 comment
Open

Use param foo in default for bar #2290

jamesarosen opened this issue Dec 16, 2022 · 1 comment

Comments

@jamesarosen
Copy link

What I'd like to do:

params do
  requires :foo
  optional :bar, default: -> (other_params) { "bar from foo #{other_params[:foo]} }
end

or perhaps

params do
  requires :foo
  optional :bar, coerce: -> (bar_value, other_params) { "bar from foo #{other_params[:foo]} }
end

Unfortunately, neither default nor coerce seems to accept the other params as an argument. It may be possible to get them from self (which is a ParamsScope) within that block, but it's not obvious how.

@dblock
Copy link
Member

dblock commented Dec 16, 2022

Does params[:foo] work? If not this is a great feature request. Note that circular dependencies might become possible 🤔

jcagarcia added a commit to jcagarcia/grape that referenced this issue Nov 17, 2023
jcagarcia added a commit to jcagarcia/grape that referenced this issue Nov 17, 2023
jcagarcia added a commit to jcagarcia/grape that referenced this issue Nov 17, 2023
jcagarcia added a commit to jcagarcia/grape that referenced this issue Nov 17, 2023
dblock pushed a commit that referenced this issue Nov 19, 2023
…am (#2371)

* feature(#2290): Use a param value as the `default` value of other param

* feature(#2290): Updating version to 2.1.0

* feature(#2290): Updating stable release section with 2.1.0

* feature(#2290): Updating README for following one-line format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants