Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entity data type identification #1863

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Fixes

* Your contribution here.
* [#1863](https://github.com/ruby-grape/grape/pull/1863): Fix entity data type identification - [@fotos](https://github.com/fotos).

### 1.2.3 (2019/01/16)

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def should_be_empty_array?(declared_param, passed_children_params)
end

def declared_param_is_array?(declared_param)
route_options_params[declared_param.to_s] && route_options_params[declared_param.to_s][:type] == 'Array'
route_options_params[declared_param.to_s] && route_options_params[declared_param.to_s][:type] <= Array
end

def route_options_params
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/params_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def validates(attrs, validations)

coerce_type = infer_coercion(validations)

doc_attrs[:type] = coerce_type.to_s if coerce_type
doc_attrs[:type] = coerce_type if coerce_type

desc = validations.delete(:desc) || validations.delete(:description)
doc_attrs[:desc] = desc if desc
Expand Down
6 changes: 3 additions & 3 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2795,10 +2795,10 @@ def static
subject.get 'method'

expect(subject.routes.map(&:params)).to eq [{
'group1' => { required: true, type: 'Array' },
'group1' => { required: true, type: Array },
'group1[param1]' => { required: false, desc: 'group1 param1 desc' },
'group1[param2]' => { required: true, desc: 'group1 param2 desc' },
'group2' => { required: true, type: 'Array' },
'group2' => { required: true, type: Array },
'group2[param1]' => { required: false, desc: 'group2 param1 desc' },
'group2[param2]' => { required: true, desc: 'group2 param2 desc' }
}]
Expand All @@ -2818,7 +2818,7 @@ def static
{ description: 'nesting',
params: {
'root_param' => { required: true, desc: 'root param' },
'nested' => { required: true, type: 'Array' },
'nested' => { required: true, type: Array },
'nested[nested_param]' => { required: true, desc: 'nested param' }
} }
]
Expand Down