Skip to content

Commit 3e43830

Browse files
committed
Patch to handle Array Declaration #237
1 parent bc76e74 commit 3e43830

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [#235](https://github.com/tim-vandecasteele/grape-swagger/pull/235): Fixed nested entity names in parameters and as `$ref` in models - [@frodrigo](https://github.com/frodrigo).
1919
* [#206](https://github.com/tim-vandecasteele/grape-swagger/pull/206): Fixed 'is_array' in the return entity being ignored - [@igormoochnick](https://github.com/igormoochnick).
2020
* [#266](https://github.com/tim-vandecasteele/grape-swagger/pull/266): Respect primitve mapping on type and format attributs of 1.2 swagger spec - [@frodrigo](https://github.com/frodrigo).
21+
* [#268](https://github.com/tim-vandecasteele/grape-swagger/pull/268): Patch to handle Array Declaration [#237] - [@frodrigo](https://github.com/frodrigo).
2122

2223
### 0.10.1 (March 11, 2015)
2324

lib/grape-swagger/doc_methods.rb

+6
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 /^\[(?<type>.*)\]$/
51+
items[:type] = Regexp.last_match[:type].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

+16
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)