Skip to content

Commit 792417c

Browse files
Fix include_missing for aliased parameters
1 parent ee43a64 commit 792417c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [#1737](https://github.com/ruby-grape/grape/pull/1737): Fix translating error when passing symbols as params in custom validations - [@mlzhuyi](https://github.com/mlzhuyi).
1111
* [#1749](https://github.com/ruby-grape/grape/pull/1749): Allow rescue from non-`StandardError` exceptions - [@dm1try](https://github.com/dm1try).
1212
* [#1750](https://github.com/ruby-grape/grape/pull/1750): Fix a circular dependency warning due to router being loaded by API - [@salasrod](https://github.com/salasrod).
13+
* [#1752](https://github.com/ruby-grape/grape/pull/1752): Fix `include_missing` behavior for aliased parameters - [@jonasoberschweiber](https://github.com/jonasoberschweiber).
1314
* Your contribution here.
1415

1516
### 1.0.2 (1/10/2018)

lib/grape/dsl/inside_route.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def declared_hash(passed_params, options, declared_params)
6464
has_alias = route_setting(:aliased_params) && route_setting(:aliased_params).find { |current| current[declared_param] }
6565
param_alias = has_alias[declared_param] if has_alias
6666

67-
next unless options[:include_missing] || passed_params.key?(declared_param) || param_alias
67+
next unless options[:include_missing] || passed_params.key?(declared_param) || (param_alias && passed_params.key?(param_alias))
6868

6969
if param_alias
7070
memo[optioned_param_key(param_alias, options)] = passed_params[param_alias]

spec/grape/endpoint_spec.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,20 @@ def app
464464

465465
it 'does not include missing attributes if that option is passed' do
466466
subject.get '/declared' do
467-
error! 400, 'expected nil' if declared(params, include_missing: false)[:second]
467+
error! 'expected nil', 400 if declared(params, include_missing: false).key?(:second)
468+
''
469+
end
470+
471+
get '/declared?first=one&other=two'
472+
expect(last_response.status).to eq(200)
473+
end
474+
475+
it 'does not include aliased missing attributes if that option is passed' do
476+
subject.params do
477+
optional :aliased_original, as: :aliased
478+
end
479+
subject.get '/declared' do
480+
error! 'expected nil', 400 if declared(params, include_missing: false).key?(:aliased)
468481
''
469482
end
470483

0 commit comments

Comments
 (0)