Skip to content

Commit

Permalink
Fixed: Consistent types in header params
Browse files Browse the repository at this point in the history
  • Loading branch information
lasseebert committed Jun 23, 2015
1 parent dd284f4 commit a0940ce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
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

* [#264](https://github.com/tim-vandecasteele/grape-swagger/pull/264): Consistent header param types - [@QuickPay](https://github.com/QuickPay).
* [#260](https://github.com/tim-vandecasteele/grape-swagger/pull/260), [#261](https://github.com/tim-vandecasteele/grape-swagger/pull/261): Fixed endpoints that would wrongly be hidden if `hide_documentation_path` is set - [@QuickPay](https://github.com/QuickPay).
* [#259](https://github.com/tim-vandecasteele/grape-swagger/pull/259): Fixed range values and converting integer :values range to a minimum/maximum numeric Range - [@u2](https://github.com/u2).
* [#252](https://github.com/tim-vandecasteele/grape-swagger/pull/252): Allow docs to mounted in separate class than target - [@iangreenleaf](https://github.com/iangreenleaf).
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def parse_header_params(params)
params ||= []

params.map do |param, value|
data_type = 'String'
data_type = 'string'
description = value.is_a?(Hash) ? value[:description] : ''
required = value.is_a?(Hash) ? !!value[:required] : false
default_value = value.is_a?(Hash) ? value[:default] : nil
Expand Down
2 changes: 1 addition & 1 deletion spec/grape-swagger_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class CustomType
'XAuthToken' => { description: 'A required header.', required: true, default: 'default' }
}
expect(subject.parse_header_params(params)).to eq [
{ paramType: 'header', name: 'XAuthToken', description: 'A required header.', type: 'String', required: true, defaultValue: 'default' }
{ paramType: 'header', name: 'XAuthToken', description: 'A required header.', type: 'string', required: true, defaultValue: 'default' }
]
end
end
Expand Down
22 changes: 22 additions & 0 deletions spec/param_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,26 @@ def app
{ 'paramType' => 'query', 'name' => 'input', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false }
]
end

describe 'header params' do
def app
Class.new(Grape::API) do
format :json

desc 'Some API', headers: { 'My-Header' => { required: true, description: 'Set this!' } }
params do
requires :input, type: String
end
post :action do
end

add_swagger_documentation
end
end

it 'has consistent types' do
types = subject.map { |param| param['type'] }
expect(types).to eq(%w(string string))
end
end
end
4 changes: 2 additions & 2 deletions spec/simple_mounted_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def app
'nickname' => 'GET-simple_with_headers---format-',
'method' => 'GET',
'parameters' => [
{ 'paramType' => 'header', 'name' => 'XAuthToken', 'description' => 'A required header.', 'type' => 'String', 'required' => true },
{ 'paramType' => 'header', 'name' => 'XOtherHeader', 'description' => 'An optional header.', 'type' => 'String', 'required' => false }
{ 'paramType' => 'header', 'name' => 'XAuthToken', 'description' => 'A required header.', 'type' => 'string', 'required' => true },
{ 'paramType' => 'header', 'name' => 'XOtherHeader', 'description' => 'An optional header.', 'type' => 'string', 'required' => false }
],
'type' => 'void',
'responseMessages' => [
Expand Down

0 comments on commit a0940ce

Please sign in to comment.