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 1010* [ #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 ) .
1111* [ #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 ) .
1212* [ #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.
1315
1416### 0.19.1 (1/9/2017)
1517
Original file line number Diff line number Diff line change @@ -29,8 +29,11 @@ module PostBeforeFilter
2929 def declared ( params , options = { } , declared_params = nil )
3030 options = options . reverse_merge ( include_missing : true , include_parent_namespaces : true )
3131
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 ) )
3437
3538 declared_params ||= options [ :include_parent_namespaces ] ? all_declared_params : current_namespace_declared_params
3639
Original file line number Diff line number Diff line change @@ -583,6 +583,39 @@ def app
583583 end
584584 end
585585
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+
586619 describe '#declared; with multiple route_param' do
587620 before do
588621 mounted = Class . new ( Grape ::API )
You can’t perform that action at this time.
0 commit comments