File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 10
10
* [ #1559 ] ( https://github.com/ruby-grape/grape/pull/1559 ) : You can once again pass ` nil ` to optional attributes with ` values ` validation set - [ @ghiculescu ] ( https://github.com/ghiculescu ) .
11
11
* [ #1562 ] ( https://github.com/ruby-grape/grape/pull/1562 ) : Fix rainbow gem installation failure above ruby 2.3.3 on travis-ci - [ @brucehsu ] ( https://github.com/brucehsu ) .
12
12
* [ #1561 ] ( https://github.com/ruby-grape/grape/pull/1561 ) : Fix performance issue introduced by duplicated calls in StackableValue#[ ] - [ @brucehsu ] ( https://github.com/brucehsu ) .
13
+ * [ #1564 ] ( https://github.com/ruby-grape/grape/pull/1564 ) : Fix declared params bug with nested namespaces - [ @bmarini ] ( https://github.com/bmarini ) .
14
+ * Your contribution here.
13
15
14
16
### 0.19.1 (1/9/2017)
15
17
Original file line number Diff line number Diff line change @@ -29,8 +29,11 @@ module PostBeforeFilter
29
29
def declared ( params , options = { } , declared_params = nil )
30
30
options = options . reverse_merge ( include_missing : true , include_parent_namespaces : true )
31
31
32
- all_declared_params = route_setting ( :declared_params )
33
- current_namespace_declared_params = route_setting ( :saved_declared_params ) . last
32
+ # Declared params including parent namespaces
33
+ all_declared_params = route_setting ( :saved_declared_params ) . flatten | Array ( route_setting ( :declared_params ) )
34
+
35
+ # Declared params at current namespace
36
+ current_namespace_declared_params = route_setting ( :saved_declared_params ) . last & Array ( route_setting ( :declared_params ) )
34
37
35
38
declared_params ||= options [ :include_parent_namespaces ] ? all_declared_params : current_namespace_declared_params
36
39
Original file line number Diff line number Diff line change @@ -583,6 +583,39 @@ def app
583
583
end
584
584
end
585
585
586
+ describe '#declared; mixed nesting' do
587
+ before do
588
+ subject . format :json
589
+ subject . resource :users do
590
+ route_param :id , type : Integer , desc : 'ID desc' do
591
+ # Adding this causes route_setting(:declared_params) to be nil for the
592
+ # get block in namespace 'foo' below
593
+ get do
594
+ end
595
+
596
+ namespace 'foo' do
597
+ get do
598
+ {
599
+ params : params ,
600
+ declared_params : declared ( params ) ,
601
+ declared_params_no_parent : declared ( params , include_parent_namespaces : false )
602
+ }
603
+ end
604
+ end
605
+ end
606
+ end
607
+ end
608
+
609
+ it 'can access parent route_param' do
610
+ get '/users/123/foo' , bar : 'bar'
611
+ expect ( last_response . status ) . to eq 200
612
+ json = JSON . parse ( last_response . body , symbolize_names : true )
613
+
614
+ expect ( json [ :declared_params ] [ :id ] ) . to eq 123
615
+ expect ( json [ :declared_params_no_parent ] [ :id ] ) . to eq nil
616
+ end
617
+ end
618
+
586
619
describe '#declared; with multiple route_param' do
587
620
before do
588
621
mounted = Class . new ( Grape ::API )
You can’t perform that action at this time.
0 commit comments