You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[#1568](https://github.com/ruby-grape/grape/pull/1568): Add `proc` option to `values` validator to allow custom checks - [@jlfaber](https://github.com/jlfaber).
8
8
*[#1575](https://github.com/ruby-grape/grape/pull/1575): Include nil values for missing nested params in declared - [@thogg4](https://github.com/thogg4).
Copy file name to clipboardExpand all lines: README.md
+19-6
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,7 @@
29
29
-[Param](#param)
30
30
-[Describing Methods](#describing-methods)
31
31
-[Parameters](#parameters)
32
+
-[Params Class](#params-class)
32
33
-[Declared](#declared)
33
34
-[Include Missing](#include-missing)
34
35
-[Parameter Validation and Coercion](#parameter-validation-and-coercion)
@@ -501,9 +502,19 @@ Route string parameters will have precedence.
501
502
502
503
By default parameters are available as `ActiveSupport::HashWithIndifferentAccess`. This can be changed to, for example, Ruby `Hash` or `Hashie::Mash` for the entire API.
The class can be overridden on individual parameter blocks using `build_with` as follows.
517
+
The class can also be overridden on individual parameter blocks using `build_with` as follows.
507
518
508
519
```ruby
509
520
params do
@@ -514,6 +525,8 @@ end
514
525
515
526
In the example above, `params["color"]` will return `nil` since `params` is a plain `Hash`.
516
527
528
+
Available parameter builders are `Grape::Extensions::Hash::ParamBuilder`, `Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder` and `Grape::Extensions::Hashie::Mash::ParamBuilder`.
529
+
517
530
### Declared
518
531
519
532
Grape allows you to access only the parameters that have been declared by your `params` block. It filters out the params that have been passed, but are not allowed. Consider the following API endpoint:
@@ -526,7 +539,7 @@ post 'users/signup' do
526
539
end
527
540
````
528
541
529
-
If we do not specify any params, `declared` will return an empty`ActiveSupport::HashWithIndifferentAccess` hash.
542
+
If you do not specify any parameters, `declared` will return an empty hash.
Copy file name to clipboardExpand all lines: UPGRADING.md
+27-3
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,33 @@ Upgrading Grape
5
5
6
6
#### Changes in Parameter Class
7
7
8
-
The default class for `params` has changed from `Hashie::Mash` to `ActiveSupport::HashWithIndifferentAccess` and the `hashie` dependency has been removed. To restore the behavior of prior versions, add `hashie` to your `Gemfile` and use `TODO`.
8
+
The default class for `params` has changed from `Hashie::Mash` to `ActiveSupport::HashWithIndifferentAccess` and the `hashie` dependency has been removed. This means that by default you can no longer access parameters by method name.
9
9
10
-
[TODO]
10
+
```
11
+
class API < Grape::API
12
+
params do
13
+
optional :color, type: String
14
+
end
15
+
get do
16
+
params[:color] # use params[:color] instead of params.color
17
+
end
18
+
end
19
+
```
20
+
21
+
To restore the behavior of prior versions, add `hashie` to your `Gemfile` and `include Grape::Extensions::Hashie::Mash::ParamBuilder` in your API.
22
+
23
+
```
24
+
class API < Grape::API
25
+
include Grape::Extensions::Hashie::Mash::ParamBuilder
26
+
27
+
params do
28
+
optional :color, type: String
29
+
end
30
+
get do
31
+
# params.color works
32
+
end
33
+
end
34
+
```
11
35
12
36
This behavior can also be overridden on individual parameter blocks using `build_with`.
13
37
@@ -26,7 +50,7 @@ def request
26
50
end
27
51
```
28
52
29
-
See [#1594](https://github.com/ruby-grape/grape/pull/1594) for more information.
53
+
See [#1610](https://github.com/ruby-grape/grape/pull/1610) for more information.
0 commit comments