diff --git a/lib/apipie/generator/swagger/param_description/type.rb b/lib/apipie/generator/swagger/param_description/type.rb index cbf9bde1f..f35c49b71 100644 --- a/lib/apipie/generator/swagger/param_description/type.rb +++ b/lib/apipie/generator/swagger/param_description/type.rb @@ -56,7 +56,7 @@ def type def for_array_type validator_opts = validator.param_description.options - items_type = validator_opts[:of].to_s || validator_opts[:array_of].to_s + items_type = (validator_opts[:of] || validator_opts[:array_of]).to_s if items_type == 'Hash' && params_in_body_use_reference? reference_name = Apipie::Generator::Swagger::OperationId. @@ -67,7 +67,7 @@ def for_array_type '$ref' => reference_name } else - items = { type: 'string' } + items = { type: array_items_type(items_type).to_s } end enum = @param_description.options[:in] @@ -80,6 +80,19 @@ def for_array_type } end + # @param [String] items_type + # + # @return [Apipie::Generator::Swagger::Type] + def array_items_type(items_type) + type = Apipie::Generator::Swagger::TypeExtractor::TYPES[items_type.downcase.to_sym] + + if type == 'object' || type.blank? + Apipie::Generator::Swagger::TypeExtractor::TYPES[:string] + else + type + end + end + def for_enum_type { type: 'string', diff --git a/spec/lib/apipie/generator/swagger/param_description/type_spec.rb b/spec/lib/apipie/generator/swagger/param_description/type_spec.rb index fd190edf7..dbbe34f04 100644 --- a/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +++ b/spec/lib/apipie/generator/swagger/param_description/type_spec.rb @@ -115,10 +115,15 @@ it 'returns the reference' do expect(subject).to eq({ '$ref' => reference }) end - end end + context 'of a Swagger type' do + let(:validator_options) { { of: Integer } } + + it { is_expected.to eq({ type: 'integer' }) } + end + describe 'enum' do subject { items[:enum] }