Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A boolean parameters can be configured with both :bool and :boolean #124

Merged
merged 1 commit into from
Dec 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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