2017-03-08 16:32:31 +08:00
# frozen_string_literal: true
2016-09-20 23:07:13 +08:00
require 'spec_helper'
describe 'Group Array Params, using collection format' do
def app
Class . new ( Grape :: API ) do
format :json
params do
optional :array_of_strings , type : Array [ String ] , desc : 'array in csv collection format'
end
get '/array_of_strings_without_collection_format' do
{ 'declared_params' = > declared ( params ) }
end
params do
optional :array_of_strings , type : Array [ String ] , desc : 'array in multi collection format' , documentation : { collectionFormat : 'multi' }
end
get '/array_of_strings_multi_collection_format' do
{ 'declared_params' = > declared ( params ) }
end
params do
optional :array_of_strings , type : Array [ String ] , documentation : { collectionFormat : 'foo' }
end
get '/array_of_strings_invalid_collection_format' do
{ 'declared_params' = > declared ( params ) }
end
add_swagger_documentation
end
end
describe 'documentation for array parameter in default csv collectionFormat' do
subject do
get '/swagger_doc/array_of_strings_without_collection_format'
JSON . parse ( last_response . body )
end
specify do
expect ( subject [ 'paths' ] [ '/array_of_strings_without_collection_format' ] [ 'get' ] [ 'parameters' ] ) . to eql (
[
{ 'in' = > 'formData' , 'name' = > 'array_of_strings' , 'type' = > 'array' , 'items' = > { 'type' = > 'string' } , 'required' = > false , 'description' = > 'array in csv collection format' }
]
)
end
end
describe 'documentation for array parameters in multi collectionFormat set from documentation' do
subject do
get '/swagger_doc/array_of_strings_multi_collection_format'
JSON . parse ( last_response . body )
end
specify do
expect ( subject [ 'paths' ] [ '/array_of_strings_multi_collection_format' ] [ 'get' ] [ 'parameters' ] ) . to eql (
[
{ 'in' = > 'formData' , 'name' = > 'array_of_strings' , 'type' = > 'array' , 'items' = > { 'type' = > 'string' } , 'required' = > false , 'collectionFormat' = > 'multi' , 'description' = > 'array in multi 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'
JSON . parse ( last_response . body )
end
specify do
expect ( subject [ 'paths' ] [ '/array_of_strings_invalid_collection_format' ] [ 'get' ] [ 'parameters' ] ) . to eql (
[
{ 'in' = > 'formData' , 'name' = > 'array_of_strings' , 'type' = > 'array' , 'items' = > { 'type' = > 'string' } , 'required' = > false }
]
)
end
end
end