Add parameter alias#1674
Conversation
dblock
left a comment
There was a problem hiding this comment.
I find it rather strange that declared(params) needs to be used to enable the alias. I feel like when I use as, params should just be the target structure and maybe there should be some other way to access the "raw" parameters. That seems more predictable, no?
|
|
||
| ### Alias | ||
|
|
||
| It's possible to set alias for parameters using `as` (it can be useful when refactoring an existing API): |
There was a problem hiding this comment.
You can set an alias for parameters using as, which can be useful when refactoring existing APIs.
| end | ||
| ``` | ||
|
|
||
| The value passed to `as` will be the key when calling `declared(params)` (calling only `params` will not set the alias). |
There was a problem hiding this comment.
Maybe ", but params will not use the alias."
| # Adds a parameter declaration to our list of validations. | ||
| # @param attrs [Array] (see Grape::DSL::Parameters#requires) | ||
| def push_declared_params(attrs) | ||
| def push_declared_params(attrs, param_alias = nil) |
There was a problem hiding this comment.
Instead of param_alias I would make it opts and a Hash of different options, starting with as, for future proofing.
|
I am not sure if would be cool to use alias with |
When we use |
|
So much better! Merging. |
|
Nice work @glaucocustodio. |
Closes #1673.
Please, check if it's ok.
The methods
requiresandoptionalhave aif opts[:using](grape/dsl/parameters.rb) but I don't know how this condition can be true, I also didn't find any mention tousingon readme.