Skip to content

Commit

Permalink
Include headers when body parameters have been defined (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj authored and peter scholz committed Sep 8, 2016
1 parent fdbe8e4 commit 3e855dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#### Fixes

* [#494](https://github.com/ruby-grape/grape-swagger/pull/494): Header parametes are now included in documentation when body parameters have been defined - [@anakinj](https://github.com/anakinj).
* Your contribution here.

### 0.23.0 (August 5, 2016)
Expand Down
12 changes: 7 additions & 5 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,17 @@ 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 = GrapeSwagger::DocMethods::Headers.parse(route) + required unless route.headers.nil?

default_type(required)
default_type(exposed)

unless declared_params.nil? && route.headers.nil?
request_params = parse_request_params(required)
end
request_params = unless declared_params.nil? && route.headers.nil?
parse_request_params(required)
end || {}

request_params = route.params.merge(request_params) if route.params.present? && !route.settings[:declared_params].present?

return route.params if route.params.present? && !route.settings[:declared_params].present?
request_params || {}
request_params
end

def default_type(params)
Expand Down
2 changes: 2 additions & 0 deletions spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def app
'body_param' => { 'type' => 'string', 'description' => 'param' },
'body_type_as_const_param' => { 'type' => 'string', 'description' => 'string_param' }
)

expect(subject['paths']['/endpoint']['post']['parameters'].any? { |p| p['name'] == 'XAuthToken' && p['in'] == 'header' }).to eql(true)
end
end
end

0 comments on commit 3e855dd

Please sign in to comment.