Skip to content

Commit

Permalink
Merge pull request #124 from Nerian/boolean
Browse files Browse the repository at this point in the history
A boolean parameters can be configured with both :bool and :boolean
  • Loading branch information
Pajk committed Dec 12, 2015
2 parents 1b1be7d + 5fbc975 commit da6c8b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/apipie/extractor/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def refine_params_description(params_desc, recorded_params)
# we specify what type it might be. At the end the first type
# that left is taken as the more general one
unless param_desc[:type]
param_desc[:type] = [:bool, :number]
param_desc[:type] = [:bool, :boolean, :number]
param_desc[:type] << Hash if value.is_a? Hash
param_desc[:type] << :undef
end

if param_desc[:type].first == :bool && (! [true, false].include?(value))
if [:boolean, :bool].include?(param_desc[:type].first) && (! [true, false, 1, 0].include?(value))
param_desc[:type].shift
end

Expand Down
6 changes: 3 additions & 3 deletions lib/apipie/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ def self.validate(value)
class BooleanValidator < BaseValidator

def validate(value)
%w[true false].include?(value.to_s)
%w[true false 1 0].include?(value.to_s)
end

def self.build(param_description, argument, options, block)
if argument == :bool
if argument == :bool || argument == :boolean
self.new(param_description)
end
end
Expand All @@ -412,7 +412,7 @@ def expected_type
end

def description
"Must be 'true' or 'false'"
"Must be 'true' or 'false' or '1' or '0'"
end
end

Expand Down

0 comments on commit da6c8b2

Please sign in to comment.