When using a custom type for example: ExpirationDate = Types::DateTime.constructor { |value| value.to_time.round.to_datetime }
The constructor does not apply to nested hashes in a schema:
ExpirationDate = Types::DateTime.constructor { |value| value.to_time.round.to_datetime }
NestedCustomTypeHash = Dry::Schema.define do
required(:foo).hash do
required(:bar).value(ExpirationDate)
end
end
result = NestedCustomTypeHash.call(foo: { bar: '2021-11-11T00:00:00+00:00'} )
# result.errors.to_h => {:foo=>{:bar=>["must be a date time"]}}
Describe the bug
When using a custom type for example:
ExpirationDate = Types::DateTime.constructor { |value| value.to_time.round.to_datetime }
The constructor does not apply to nested hashes in a schema:To Reproduce
I've reproduced it in this PR: https://github.com/dry-rb/dry-schema/pull/395 but could not figure out how to get the spec to pass
Expected behavior
My environment