Skip to content

Conversation

@amclain
Copy link
Member

@amclain amclain commented Sep 17, 2025

In the case of the following spec, it would be expected that if param1 is not present, the value would be nil (currently it is coerced to false). In this case, true/false/nil makes it easy to detect if the value was present, and is easy to "coerce" after validation with if (data.param1) or !!param1.

attribute :param1, :boolean, optional: true

If the intent is to use spec to coerce an optional property to only true/false, use default:

attribute :param1, :boolean, default: false

@amclain amclain self-assigned this Sep 17, 2025
@amclain amclain merged commit 4729f0d into main Sep 17, 2025
2 checks passed
@amclain amclain deleted the optional-booleans-are-nil branch September 17, 2025 23:37
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.

3 participants