Skip to content

Add support for 'brackets' collection format #622

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jul 22, 2017
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#### Features

* Your contribution here.
* [#622](https://github.com/ruby-grape/grape-swagger/pull/622): Add support for 'brackets' collection format - [@korstiaan](https://github.com/korstiaan).

#### Fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def mapping(value)
end

def collections
%w[csv ssv tsv pipes multi]
%w[csv ssv tsv pipes multi brackets]
end
end

Expand Down
23 changes: 23 additions & 0 deletions spec/swagger_v2/params_array_collection_fromat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def app
{ 'declared_params' => declared(params) }
end

params do
optional :array_of_strings, type: Array[String], desc: 'array in brackets collection format', documentation: { collectionFormat: 'brackets' }
end

get '/array_of_strings_brackets_collection_format' do
{ 'declared_params' => declared(params) }
end

add_swagger_documentation
end
end
Expand Down Expand Up @@ -65,6 +73,21 @@ def app
end
end

describe 'documentation for array parameters in brackets collectionFormat set from documentation' do
subject do
get '/swagger_doc/array_of_strings_brackets_collection_format'
JSON.parse(last_response.body)
end

specify do
expect(subject['paths']['/array_of_strings_brackets_collection_format']['get']['parameters']).to eql(
[
{ 'in' => 'formData', 'name' => 'array_of_strings', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false, 'collectionFormat' => 'brackets', 'description' => 'array in brackets collection format' }
]
)
end
end

describe 'documentation for array parameters with collectionFormat set to invalid option' do
subject do
get '/swagger_doc/array_of_strings_invalid_collection_format'
Expand Down