Closed luisbelloch closed 7 months ago
The workaround, in case anyone is interested:
require "dry/types"
require "dry/schema"
module Types
include Dry.Types()
FilledOrNilString = Types::String.constructor { |s| s.to_s.empty? ? nil : s }
end
Contract = Dry::Schema.Params do
optional(:foo).maybe(Types::FilledOrNilString)
end
ok, I've spot the error, my bad. It should be :string
, not :str?
.
Contract = Dry::Schema.Params do
- optional(:foo).maybe(:str?)
+ optional(:foo).maybe(:string)
end
I'm sorry you hit this gotcha :/ We should finally deprecate this behavior as in 2.0.0 type specs will be mandatory.
I was looking at the documentation about Handling empty strings and it states the following:
However, this example gives me a different result:
I was wondering if that behavior is correct or not, I would have expect second example to return
nil
instead.I've found similar issues in #227 and also different fix in #229 and #397.
Thanks!
dry-schema
version 1.8.0