Skip to content

Commit

Permalink
Use array items type from validator
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosCodes committed Dec 19, 2023
1 parent 912316c commit 5eb27ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 15 additions & 2 deletions lib/apipie/generator/swagger/param_description/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] }

Expand Down

0 comments on commit 5eb27ec

Please sign in to comment.