Skip to content

Commit 64897b5

Browse files
committed
Patch to handle Array Declaration #237
1 parent 77305c4 commit 64897b5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/grape-swagger/doc_methods.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ def parse_params(params, path, method)
4747
'double'
4848
when 'Symbol'
4949
'string'
50+
when /^\[(.*)\]$/
51+
items[:type] = Regexp.last_match[1].downcase
52+
if PRIMITIVE_MAPPINGS.key?(items[:type])
53+
items[:type], items[:format] = PRIMITIVE_MAPPINGS[items[:type]]
54+
end
55+
'array'
5056
else
5157
@@documentation_class.parse_entity_name(raw_data_type)
5258
end

spec/array_params_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def app
2020
get :raw_array_splines do
2121
end
2222

23+
params do
24+
optional :raw_array, type: Array[Integer]
25+
end
26+
get :raw_array_integers do
27+
end
28+
2329
add_swagger_documentation
2430
end
2531
end
@@ -44,4 +50,14 @@ def app
4450
{ 'paramType' => 'query', 'name' => 'raw_array', 'description' => nil, 'type' => 'Array', 'required' => false, 'allowMultiple' => false }
4551
]
4652
end
53+
54+
it 'get raw array integer' do
55+
get '/swagger_doc/raw_array_integers'
56+
expect(last_response.status).to eq 200
57+
body = JSON.parse last_response.body
58+
parameters = body['apis'].first['operations'].first['parameters']
59+
expect(parameters).to eq [
60+
{ 'paramType' => 'query', 'name' => 'raw_array', 'description' => nil, 'type' => 'array', 'required' => false, 'allowMultiple' => false, 'items' => { 'type' => 'integer', 'format' => 'int32' } }
61+
]
62+
end
4763
end

0 commit comments

Comments
 (0)