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

fix blank error message when allow_blank is false and value is blank #935

Closed
wants to merge 1 commit into from
Closed
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
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

Suggested change
return true if !validator.valid?(value)
return true if validator.valid?(value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is my miss but test code it bothers me ㅠ_ㅠ


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
Loading