diff --git a/lib/apipie/param_description.rb b/lib/apipie/param_description.rb index 7b917d68..10e155e0 100644 --- a/lib/apipie/param_description.rb +++ b/lib/apipie/param_description.rb @@ -120,11 +120,11 @@ def validate(value) return true if allow_nil && value.nil? return true if allow_blank && value.blank? value = normalized_value(value) - if (!allow_nil && value.nil?) || (blank_forbidden? && value.blank?) || !validator.valid?(value) - error = validator.error - error = ParamError.new(error) unless error.is_a? StandardError - raise error - end + return true if !validator.valid?(value) + + error = validator.error + error = ParamError.new(error) unless error.is_a? StandardError + raise error end def blank_forbidden? diff --git a/lib/apipie/validator.rb b/lib/apipie/validator.rb index a56f227c..fd47fe48 100644 --- a/lib/apipie/validator.rb +++ b/lib/apipie/validator.rb @@ -50,6 +50,14 @@ def self.raise_if_missing_params # check if value is valid def valid?(value) + if !param_description.allow_nil && value.nil? + @error_value = nil + return false + elsif !param_description.allow_blank && value.blank? + @error_value = 'blank' + return false + end + if self.validate(value) @error_value = nil true