|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe '#832 array of objects with nested Float/BigDecimal fields' do |
| 6 | + let(:app) do |
| 7 | + Class.new(Grape::API) do |
| 8 | + resource :issue_832 do |
| 9 | + params do |
| 10 | + requires :array_param, type: Array do |
| 11 | + requires :float_param, type: Float |
| 12 | + requires :big_decimal_param, type: BigDecimal |
| 13 | + requires :object_param, type: Hash do |
| 14 | + requires :float_param, type: Float |
| 15 | + requires :big_decimal_param, type: BigDecimal |
| 16 | + requires :object_param, type: Hash do |
| 17 | + requires :float_param, type: Float |
| 18 | + requires :big_decimal_param, type: BigDecimal |
| 19 | + requires :array_param, type: Array do |
| 20 | + requires :integer_param, type: Integer |
| 21 | + end |
| 22 | + end |
| 23 | + end |
| 24 | + end |
| 25 | + end |
| 26 | + post do |
| 27 | + { message: 'hello world' } |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + add_swagger_documentation |
| 32 | + end |
| 33 | + end |
| 34 | + let(:parameters) { subject['paths']['/issue_832']['post']['parameters'] } |
| 35 | + |
| 36 | + subject do |
| 37 | + get '/swagger_doc' |
| 38 | + JSON.parse(last_response.body) |
| 39 | + end |
| 40 | + |
| 41 | + specify do |
| 42 | + expect(parameters).to eql( |
| 43 | + [ |
| 44 | + { |
| 45 | + 'in' => 'formData', |
| 46 | + 'name' => 'array_param[float_param]', |
| 47 | + 'type' => 'array', |
| 48 | + 'required' => true, |
| 49 | + 'items' => { |
| 50 | + 'type' => 'number', |
| 51 | + 'format' => 'float' |
| 52 | + } |
| 53 | + }, { |
| 54 | + 'in' => 'formData', |
| 55 | + 'name' => 'array_param[big_decimal_param]', |
| 56 | + 'type' => 'array', |
| 57 | + 'required' => true, |
| 58 | + 'items' => { |
| 59 | + 'type' => 'number', |
| 60 | + 'format' => 'double' |
| 61 | + } |
| 62 | + }, { |
| 63 | + 'in' => 'formData', |
| 64 | + 'name' => 'array_param[object_param][float_param]', |
| 65 | + 'type' => 'array', |
| 66 | + 'required' => true, |
| 67 | + 'items' => { |
| 68 | + 'type' => 'number', |
| 69 | + 'format' => 'float' |
| 70 | + } |
| 71 | + }, { |
| 72 | + 'in' => 'formData', |
| 73 | + 'name' => 'array_param[object_param][big_decimal_param]', |
| 74 | + 'type' => 'array', |
| 75 | + 'required' => true, |
| 76 | + 'items' => { |
| 77 | + 'type' => 'number', |
| 78 | + 'format' => 'double' |
| 79 | + } |
| 80 | + }, { |
| 81 | + 'in' => 'formData', |
| 82 | + 'name' => 'array_param[object_param][object_param][float_param]', |
| 83 | + 'type' => 'array', |
| 84 | + 'required' => true, |
| 85 | + 'items' => { |
| 86 | + 'type' => 'number', |
| 87 | + 'format' => 'float' |
| 88 | + } |
| 89 | + }, { |
| 90 | + 'in' => 'formData', |
| 91 | + 'name' => 'array_param[object_param][object_param][big_decimal_param]', |
| 92 | + 'type' => 'array', |
| 93 | + 'required' => true, |
| 94 | + 'items' => { |
| 95 | + 'type' => 'number', |
| 96 | + 'format' => 'double' |
| 97 | + } |
| 98 | + }, { |
| 99 | + 'in' => 'formData', |
| 100 | + 'name' => 'array_param[object_param][object_param][array_param][integer_param]', |
| 101 | + 'type' => 'array', |
| 102 | + 'required' => true, |
| 103 | + 'items' => { |
| 104 | + 'type' => 'integer', |
| 105 | + 'format' => 'int32' |
| 106 | + } |
| 107 | + } |
| 108 | + ] |
| 109 | + ) |
| 110 | + end |
| 111 | +end |
0 commit comments