Skip to content

Commit

Permalink
fix blank error message when allow_blank is false and value is balnk
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyeon-langdy committed Jun 4, 2024
1 parent eef4770 commit 5c2552b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/apipie/param_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 8 additions & 0 deletions lib/apipie/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c2552b

Please sign in to comment.