Skip to content

Conversation

ClaytonPassmore
Copy link
Contributor

@ClaytonPassmore ClaytonPassmore commented Sep 27, 2021

Description

The 1.0 release introduced a regression where parameters that were not
required and had a default that isn't #present? would cause an invalid
parameter error to be raised. This commit fixes the logic in the
required validator and adds a spec so it doesn't break in the future :)

Here's an example of where this regression can come into play:

param! :sort, Hash, required: false, default: {} do |s|
  s.param! :order, String, in: [ "asc", "desc" ]
end

If no sort parameter is provided in the request, it defaults to {}, then the required validator ends up raising an error because {} is not present, nor is the parameter required.

The 1.0 release introduced a regression where parameters that were not
required and had a default that isn't `#present?` would cause an invalid
parameter error to be raised. This commit fixes the logic in the
required validator and adds a spec so it doesn't break in the future :)
@ifellinaholeonce
Copy link
Collaborator

thanks @ClaytonPassmore great find.

@ifellinaholeonce ifellinaholeonce merged commit e4d9e2c into nicolasblanco:master Sep 27, 2021
@ClaytonPassmore ClaytonPassmore deleted the fix/default-empty-wo-required branch September 27, 2021 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants