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
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@
7
7
#### Fixes
8
8
9
9
* Your contribution here.
10
+
*[#2103](https://github.com/ruby-grape/grape/pull/2103): Ensure complete declared params structure is present - [@tlconnor](https://github.com/tlconnor).
10
11
*[#2099](https://github.com/ruby-grape/grape/pull/2099): Added truffleruby to Travis-CI - [@gogainda](https://github.com/gogainda).
11
12
*[#2089](https://github.com/ruby-grape/grape/pull/2089): Specify order of mounting Grape with Rack::Cascade in README - [@jonmchan](https://github.com/jonmchan).
12
13
*[#2083](https://github.com/ruby-grape/grape/pull/2083): Set `Cache-Control` header only for streamed responses - [@stanhu](https://github.com/stanhu).
Copy file name to clipboardExpand all lines: README.md
+48-5Lines changed: 48 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -353,7 +353,7 @@ use Rack::Session::Cookie
353
353
run Rack::Cascade.new [Web, API]
354
354
```
355
355
356
-
Note that order of loading apps using `Rack::Cascade` matters. The grape application must be last if you want to raise custom 404 errors from grape (such as `error!('Not Found',404)`). If the grape application is not last and returns 404 or 405 response, [cascade utilizes that as a signal to try the next app](https://www.rubydoc.info/gems/rack/Rack/Cascade). This may lead to undesirable behavior showing the [wrong 404 page from the wrong app](https://github.com/ruby-grape/grape/issues/1515).
356
+
Note that order of loading apps using `Rack::Cascade` matters. The grape application must be last if you want to raise custom 404 errors from grape (such as `error!('Not Found',404)`). If the grape application is not last and returns 404 or 405 response, [cascade utilizes that as a signal to try the next app](https://www.rubydoc.info/gems/rack/Rack/Cascade). This may lead to undesirable behavior showing the [wrong 404 page from the wrong app](https://github.com/ruby-grape/grape/issues/1515).
357
357
358
358
359
359
### Rails
@@ -787,7 +787,12 @@ Available parameter builders are `Grape::Extensions::Hash::ParamBuilder`, `Grape
787
787
788
788
### Declared
789
789
790
-
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:
790
+
Grape allows you to access only the parameters that have been declared by your `params` block. It will:
791
+
792
+
* Filter out the params that have been passed, but are not allowed.
793
+
* Include any optional params that are declared but not passed.
794
+
795
+
Consider the following API endpoint:
791
796
792
797
````ruby
793
798
format:json
@@ -820,9 +825,9 @@ Once we add parameters requirements, grape will start returning only the declare
Copy file name to clipboardExpand all lines: UPGRADING.md
+43-4Lines changed: 43 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,45 @@
1
1
Upgrading Grape
2
2
===============
3
3
4
+
### Upgrading to >= 1.4.1
5
+
6
+
Prior to 1.3.3, the `declared` helper would always return the complete params structure if `include_missing=true` was set. In 1.3.3 the behavior was changed, so a missing Hash with or without nested parameters would always resolve to `{}`.
7
+
8
+
In 1.4.1 this behavior is reverted, so the whole params structure will always be available via `declared`, regardless of whether any params are passed.
9
+
10
+
The following rules now apply to the `declared` helper when params are missing and `include_missing=true`:
11
+
12
+
* Hash params with children will resolve to a Hash with keys for each declared child.
13
+
* Hash params with no children will resolve to `{}`.
14
+
* Set params will resolve to `Set.new`.
15
+
* Array params will resolve to `[]`.
16
+
* All other params will resolve to `nil`.
17
+
18
+
#### Example
19
+
20
+
```ruby
21
+
classApi < Grape::API
22
+
params do
23
+
optional :outer, type:Hashdo
24
+
optional :inner, type:Hashdo
25
+
optional :value, type:String
26
+
end
27
+
end
28
+
end
29
+
get 'example'do
30
+
declared(params, include_missing:true)
31
+
end
32
+
end
33
+
```
34
+
35
+
```
36
+
get '/example'
37
+
# 1.4.0 = {}
38
+
# 1.4.1 = {outer: {inner: {value:null}}}
39
+
```
40
+
41
+
For more information see [#2103](https://github.com/ruby-grape/grape/pull/2103).
42
+
4
43
### Upgrading to >= 1.4.0
5
44
6
45
#### Reworking stream and file and un-deprecating stream like-objects
@@ -28,17 +67,17 @@ class API < Grape::API
28
67
end
29
68
```
30
69
31
-
Or use `stream` to stream other kinds of content. In the following example a streamer class
70
+
Or use `stream` to stream other kinds of content. In the following example a streamer class
32
71
streams paginated data from a database.
33
72
34
73
```ruby
35
-
classMyObject
74
+
classMyObject
36
75
attr_accessor:result
37
76
38
77
definitialize(query)
39
78
@result= query
40
79
end
41
-
80
+
42
81
defeach
43
82
yield'['
44
83
# Do paginated DB fetches and return each page formatted
0 commit comments