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

Include headers when body parameters have been defined #494

Merged
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 @@ -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