Skip to content

Patch to handle Array Declaration #237 #268

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

Merged
merged 1 commit into from
Jul 3, 2015
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 @@ -18,6 +18,7 @@
* [#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).
* [#206](https://github.com/tim-vandecasteele/grape-swagger/pull/206): Fixed 'is_array' in the return entity being ignored - [@igormoochnick](https://github.com/igormoochnick).
* [#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).
* [#268](https://github.com/tim-vandecasteele/grape-swagger/pull/268): Patch to handle Array Declaration [#237] - [@frodrigo](https://github.com/frodrigo).

### 0.10.1 (March 11, 2015)

Expand Down
6 changes: 6 additions & 0 deletions lib/grape-swagger/doc_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def parse_params(params, path, method)
'double'
when 'Symbol'
'string'
when /^\[(?<type>.*)\]$/
items[:type] = Regexp.last_match[:type].downcase
if PRIMITIVE_MAPPINGS.key?(items[:type])
items[:type], items[:format] = PRIMITIVE_MAPPINGS[items[:type]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-read this and find it a bit strange (or at least looks like a side-effect) that we're assigning items[] inside the case statement. Feels like this logic belongs below where we deal with items? I am not sure though, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later we deal with parsed_params[:type], not items[:type], items just affected into parsed_params[:items].

end
'array'
else
@@documentation_class.parse_entity_name(raw_data_type)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/array_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def app
get :raw_array_splines do
end

params do
optional :raw_array, type: Array[Integer]
end
get :raw_array_integers do
end

add_swagger_documentation
end
end
Expand All @@ -44,4 +50,14 @@ def app
{ 'paramType' => 'query', 'name' => 'raw_array', 'description' => nil, 'type' => 'Array', 'required' => false, 'allowMultiple' => false }
]
end

it 'get raw array integer' do
get '/swagger_doc/raw_array_integers'
expect(last_response.status).to eq 200
body = JSON.parse last_response.body
parameters = body['apis'].first['operations'].first['parameters']
expect(parameters).to eq [
{ 'paramType' => 'query', 'name' => 'raw_array', 'description' => nil, 'type' => 'array', 'required' => false, 'allowMultiple' => false, 'items' => { 'type' => 'integer', 'format' => 'int32' } }
]
end
end