|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe '#605 Group Params as Array' do |
| 6 | + let(:app) do |
| 7 | + Class.new(Grape::API) do |
| 8 | + params do |
| 9 | + requires :array_of_range_string, type: [String], values: %w[a b c] |
| 10 | + requires :array_of_range_integer, type: [Integer], values: [1, 2, 3] |
| 11 | + end |
| 12 | + post '/array_of_range' do |
| 13 | + { 'declared_params' => declared(params) } |
| 14 | + end |
| 15 | + |
| 16 | + params do |
| 17 | + requires :array_with_default_string, type: [String], default: 'abc' |
| 18 | + requires :array_with_default_integer, type: Array[Integer], default: 123 |
| 19 | + end |
| 20 | + post '/array_with_default' do |
| 21 | + { 'declared_params' => declared(params) } |
| 22 | + end |
| 23 | + |
| 24 | + add_swagger_documentation |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + describe 'retrieves the documentation for typed group range parameters' do |
| 29 | + subject do |
| 30 | + get '/swagger_doc/array_of_range' |
| 31 | + JSON.parse(last_response.body) |
| 32 | + end |
| 33 | + |
| 34 | + specify do |
| 35 | + expect(subject['paths']['/array_of_range']['post']['parameters']).to eql( |
| 36 | + [ |
| 37 | + { 'in' => 'formData', 'name' => 'array_of_range_string', 'type' => 'array', 'items' => { 'type' => 'string', 'enum' => %w[a b c] }, 'required' => true }, |
| 38 | + { 'in' => 'formData', 'name' => 'array_of_range_integer', 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32', 'enum' => [1, 2, 3] }, 'required' => true } |
| 39 | + ] |
| 40 | + ) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + describe 'retrieves the documentation for typed group parameters with default' do |
| 45 | + subject do |
| 46 | + get '/swagger_doc/array_with_default' |
| 47 | + JSON.parse(last_response.body) |
| 48 | + end |
| 49 | + |
| 50 | + specify do |
| 51 | + expect(subject['paths']['/array_with_default']['post']['parameters']).to eql( |
| 52 | + [ |
| 53 | + { 'in' => 'formData', 'name' => 'array_with_default_string', 'type' => 'array', 'items' => { 'type' => 'string', 'default' => 'abc' }, 'required' => true }, |
| 54 | + { 'in' => 'formData', 'name' => 'array_with_default_integer', 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32', 'default' => 123 }, 'required' => true } |
| 55 | + ] |
| 56 | + ) |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments