Skip to content

Commit

Permalink
A boolean parameters can be configured with both :bool and :boolean o…
Browse files Browse the repository at this point in the history
…ptions. A boolean parameter can be any of: 'true', 'false', '1', '0'
  • Loading branch information
Nerian committed May 17, 2014
1 parent bc1e5f3 commit 5fbc975
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
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
Expand Up @@ -328,17 +328,17 @@ 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

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

Expand Down

0 comments on commit 5fbc975

Please sign in to comment.