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
Corrected the endpoint parameter name generation. (#2189)
* Corrected the endpoint parameter name generation.
Signed-off-by: Hermann Mayer <[email protected]>
* Reworked the parameter renaming to be a declared-only feature.
Signed-off-by: Hermann Mayer <[email protected]>
* Corrected already existing, but now broken specs.
Signed-off-by: Hermann Mayer <[email protected]>
* PR fixes and docs.
Signed-off-by: Hermann Mayer <[email protected]>
* Version bump and rephrasing.
Signed-off-by: Hermann Mayer <[email protected]>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
### 1.5.4 (Next)
1
+
### 1.6.0 (Next)
2
2
3
3
#### Features
4
4
@@ -9,7 +9,9 @@
9
9
*[#2176](https://github.com/ruby-grape/grape/pull/2176): Fix: OPTIONS fails if matching all routes - [@myxoh](https://github.com/myxoh).
10
10
*[#2177](https://github.com/ruby-grape/grape/pull/2177): Fix: `default` validator fails if preceded by `as` validator - [@Catsuko](https://github.com/Catsuko).
11
11
*[#2180](https://github.com/ruby-grape/grape/pull/2180): Call `super` in `API.inherited` - [@yogeshjain999](https://github.com/yogeshjain999).
12
+
*[#2189](https://github.com/ruby-grape/grape/pull/2189): Fix: rename parameters when using `:as` (behaviour and grape-swagger documentation) - [@Jack12816](https://github.com/Jack12816).
Copy file name to clipboardExpand all lines: UPGRADING.md
+41-1Lines changed: 41 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,50 @@
1
1
Upgrading Grape
2
2
===============
3
3
4
+
### Upgrading to >= 1.6.0
5
+
6
+
#### Parameter renaming with :as
7
+
8
+
Prior to 1.6.0 the [parameter renaming](https://github.com/ruby-grape/grape#renaming) with `:as` was directly touching the request payload ([`#params`](https://github.com/ruby-grape/grape#parameters)) while duplicating the old and the new key to be both available in the hash. This allowed clients to bypass any validation in case they knew the internal name of the parameter. Unfortunately, in combination with [grape-swagger](https://github.com/ruby-grape/grape-swagger) the internal name (name set with `:as`) of the parameters were documented.
9
+
10
+
This behavior was fixed. Parameter renaming is now done when using the [`#declared(params)`](https://github.com/ruby-grape/grape#declared) parameters helper. This stops confusing validation/coercion behavior.
11
+
12
+
Here comes an illustration of the old and new behaviour as code:
Another implication of this change is the dependent parameter resolution. Prior to 1.6.0 the following code produced an `Grape::Exceptions::UnknownParameter` because `:a` was replace by `:b`:
31
+
32
+
```ruby
33
+
params do
34
+
optional :a, as::b
35
+
given :ado# (<= 1.5.3 you had to reference +:b+ here to make it work)
36
+
requires :c
37
+
end
38
+
end
39
+
```
40
+
41
+
This code now works without any errors, as the renaming is just an internal behaviour of the `#declared(params)` parameter helper.
42
+
43
+
See [#2189](https://github.com/ruby-grape/grape/pull/2189) for more information.
4
44
5
45
### Upgrading to >= 1.5.3
6
46
7
-
### Nil value and coercion
47
+
####Nil value and coercion
8
48
9
49
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
50
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:
0 commit comments