Skip to content

Fixed: Consistent types in header params #264

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 23, 2015
Merged
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

* [#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