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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@
10
10
11
11
*[#2161](https://github.com/ruby-grape/grape/pull/2157): Handle EOFError from Rack when given an empty multipart body - [@bschmeck](https://github.com/bschmeck).
12
12
*[#2162](https://github.com/ruby-grape/grape/pull/2162): Corrected a hash modification while iterating issue - [@Jack12816](https://github.com/Jack12816).
13
+
*[#2164](https://github.com/ruby-grape/grape/pull/2164): Fix: `coerce_with` is now called for params with `nil` value - [@braktar](https://github.com/braktar).
Copy file name to clipboardExpand all lines: UPGRADING.md
+27Lines changed: 27 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,33 @@
1
1
Upgrading Grape
2
2
===============
3
3
4
+
5
+
### Upgrading to >= 1.5.3
6
+
7
+
### Nil value and coercion
8
+
9
+
Prior to 1.2.5 version passing a `nil` value for a parameter with a custom coercer would invoke the coercer, and not passing a parameter would not invoke it.
10
+
This behavior was not tested or documented. Version 1.3.0 quietly changed this behavior, in such that `nil` values skipped the coercion. Version 1.5.3 fixes and documents this as follows:
11
+
12
+
```ruby
13
+
classApi < Grape::API
14
+
params do
15
+
optional :value, type:Integer, coerce_with:->(val) { val ||0 }
16
+
end
17
+
18
+
get 'example'do
19
+
params[:my_param]
20
+
end
21
+
get '/example', params: { value:nil }
22
+
# 1.5.2 = nil
23
+
# 1.5.3 = 0
24
+
get '/example', params: {}
25
+
# 1.5.2 = nil
26
+
# 1.5.3 = nil
27
+
end
28
+
```
29
+
See [#2164](https://github.com/ruby-grape/grape/pull/2164) for more information.
0 commit comments