Skip to content

Commit ac2c43e

Browse files
committed
Merge pull request #232 from u2/array_params
Fixed missing raw array params
2 parents a0f6ad9 + 212f854 commit ac2c43e

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

.rubocop_todo.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
# Offense count: 10
99
Metrics/AbcSize:
10-
Max: 357
10+
Max: 358
1111

1212
# Offense count: 1
1313
# Configuration parameters: CountComments.
1414
Metrics/ClassLength:
15-
Max: 494
15+
Max: 498
1616

1717
# Offense count: 6
1818
Metrics/CyclomaticComplexity:
19-
Max: 105
19+
Max: 106
2020

2121
# Offense count: 297
2222
# Configuration parameters: AllowURI, URISchemes.
@@ -26,11 +26,11 @@ Metrics/LineLength:
2626
# Offense count: 20
2727
# Configuration parameters: CountComments.
2828
Metrics/MethodLength:
29-
Max: 377
29+
Max: 379
3030

3131
# Offense count: 5
3232
Metrics/PerceivedComplexity:
33-
Max: 107
33+
Max: 108
3434

3535
# Offense count: 8
3636
Style/ClassVars:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
### 0.10.2 (Next)
22

3+
#### Features
4+
35
* [#215](https://github.com/tim-vandecasteele/grape-swagger/pull/223): Support swagger `defaultValue` without the need to set a Grape `default` - [@jv-dan](https://github.com/jv-dan).
46
* Your contribution here.
57

8+
#### Fixes
9+
10+
* [#232](https://github.com/tim-vandecasteele/grape-swagger/pull/232): Fixed missing raw array params - [@u2](https://github.com/u2).
11+
612
### 0.10.1 (March 11, 2015)
713

814
* [#227](https://github.com/tim-vandecasteele/grape-swagger/issues/227): Fix: nested routes under prefix not documented - [@dblock](https://github.com/dblock).

lib/grape-swagger.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ def parse_array_params(params)
145145
params.each_key do |k|
146146
if params[k].is_a?(Hash) && params[k][:type] == 'Array'
147147
array_param = k
148+
modified_params[k] = params[k]
148149
else
149150
new_key = k
150151
unless array_param.nil?
151152
if k.to_s.start_with?(array_param.to_s + '[')
152153
new_key = array_param.to_s + '[]' + k.to_s.split(array_param)[1]
154+
modified_params.delete array_param
153155
end
154156
end
155157
modified_params[new_key] = params[k]

spec/array_params_spec.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,34 @@ def app
1414
post :splines do
1515
end
1616

17+
params do
18+
optional :raw_array, type: Array
19+
end
20+
get :raw_array_splines do
21+
end
22+
1723
add_swagger_documentation
1824
end
1925
end
2026

21-
subject do
27+
it 'gets array types' do
2228
get '/swagger_doc/splines'
2329
expect(last_response.status).to eq 200
2430
body = JSON.parse last_response.body
25-
body['apis'].first['operations'].first['parameters']
26-
end
27-
28-
it 'gets array types' do
29-
expect(subject).to eq [
31+
parameters = body['apis'].first['operations'].first['parameters']
32+
expect(parameters).to eq [
3033
{ 'paramType' => 'form', 'name' => 'a_array[][param_1]', 'description' => nil, 'type' => 'integer', 'required' => true, 'allowMultiple' => false, 'format' => 'int32' },
3134
{ 'paramType' => 'form', 'name' => 'a_array[][param_2]', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false }
3235
]
3336
end
37+
38+
it 'get raw array type' do
39+
get '/swagger_doc/raw_array_splines'
40+
expect(last_response.status).to eq 200
41+
body = JSON.parse last_response.body
42+
parameters = body['apis'].first['operations'].first['parameters']
43+
expect(parameters).to eq [
44+
{ 'paramType' => 'query', 'name' => 'raw_array', 'description' => nil, 'type' => 'Array', 'required' => false, 'allowMultiple' => false }
45+
]
46+
end
3447
end

0 commit comments

Comments
 (0)