Skip to content

Commit c334cfa

Browse files
committed
Include headers when body parameters have been defined
1 parent 053713c commit c334cfa

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#### Fixes
88

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

1112
### 0.23.0 (August 5, 2016)

lib/grape-swagger/endpoint.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,17 @@ def partition_params(route)
215215
declared_params = route.settings[:declared_params] if route.settings[:declared_params].present?
216216
required, exposed = route.params.partition { |x| x.first.is_a? String }
217217
required = GrapeSwagger::DocMethods::Headers.parse(route) + required unless route.headers.nil?
218+
218219
default_type(required)
219220
default_type(exposed)
220221

221-
unless declared_params.nil? && route.headers.nil?
222-
request_params = parse_request_params(required)
223-
end
222+
request_params = unless declared_params.nil? && route.headers.nil?
223+
parse_request_params(required)
224+
end || {}
225+
226+
request_params = route.params.merge(request_params) if route.params.present? && !route.settings[:declared_params].present?
224227

225-
return route.params if route.params.present? && !route.settings[:declared_params].present?
226-
request_params || {}
228+
request_params
227229
end
228230

229231
def default_type(params)

spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def app
3939
'body_param' => { 'type' => 'string', 'description' => 'param' },
4040
'body_type_as_const_param' => { 'type' => 'string', 'description' => 'string_param' }
4141
)
42+
43+
expect(subject['paths']['/endpoint']['post']['parameters'].any? { |p| p['name'] == 'XAuthToken' && p['in'] == 'header' }).to eql(true)
4244
end
4345
end
4446
end

0 commit comments

Comments
 (0)