Skip to content

Order of header parameters #448

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

Merged
merged 4 commits into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#### Fixes

* Your contribution here.
* [#448](https://github.com/ruby-grape/grape-swagger/pull/448): Header parameters are now prepended to the parameter list - [@anakinj](https://github.com/anakinj).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the entry to features, cause it is not a bug 😉


### 0.21.0 (June 1, 2016)

Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def tag_object(route, version)
def partition_params(route)
declared_params = route.settings[:declared_params] if route.settings[:declared_params].present?
required, exposed = route.params.partition { |x| x.first.is_a? String }
required.concat GrapeSwagger::DocMethods::Headers.parse(route) unless route.headers.nil?
required = GrapeSwagger::DocMethods::Headers.parse(route) + required unless route.headers.nil?
default_type(required)
default_type(exposed)

Expand Down
23 changes: 14 additions & 9 deletions spec/swagger_v2/api_swagger_v2_headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class HeadersApi < Grape::API
},

entity: Entities::UseResponse
params do
optional :param_x, type: String, desc: 'This is a parameter', documentation: { param_type: 'query' }
end
get '/use_headers' do
{ 'declared_params' => declared(params) }
end
Expand All @@ -37,15 +40,17 @@ def app
end

specify do
expect(subject['paths']['/use_headers']['get']['parameters']).to eql(
[
{ 'in' => 'header',
'name' => 'X-Rate-Limit-Limit',
'description' => 'The number of allowed requests in the current period',
'type' => 'integer',
'format' => 'int32',
'required' => false }
]
parameters = subject['paths']['/use_headers']['get']['parameters']
expect(parameters).to include(
'in' => 'header',
'name' => 'X-Rate-Limit-Limit',
'description' => 'The number of allowed requests in the current period',
'type' => 'integer',
'format' => 'int32',
'required' => false
)
expect(parameters.size).to eq(2)
expect(parameters.first['in']).to eq('header')
expect(parameters.last['in']).to eq('query')
end
end