dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
415 stars 108 forks source link

Array defnitions are broken after 1.9.3 #436

Closed pyromaniac closed 1 year ago

pyromaniac commented 1 year ago

Describe the bug

Hello there. It looks like array definitions got broken after dry-schema 1.9.3

To Reproduce

In 1.9.3:

Dry::Schema.Params do
  required(:foo).array(Types::Params::Integer | Types::Params::Nil)
end
#=> #<Dry::Schema::Params keys=["foo"] rules={:foo=>"key?(:foo) AND key[foo](array? AND each(int? OR nil?))"}>

In any later version:

Dry::Schema.Params do
  required(:foo).array(Types::Params::Integer | Types::Params::Nil)
end
# Dry::Container::KeyError: key not found: "int?"
# from /Users/pyromaniac/.rvm/gems/ruby-2.7.6@bookingsync/gems/dry-container-0.11.0/lib/dry/container/resolver.rb:31:in `block in call'

However, I found a workaround for this that seemingly gives the same schema definition and works in all the versions so far:

Dry::Schema.Params do
  required(:foo).value(array[Types::Params::Integer | Types::Params::Nil])
end
#=> #<Dry::Schema::Params keys=["foo"] rules={:foo=>"key?(:foo) AND key[foo](array? AND each(int? OR nil?))"}>

Though it is uglier to my taste. I saw similar issues with types resolving but they were fixed in 1.10.something.

Expected behavior

The first definition supposed to work in all the versions.

My environment

Thanks in advance!

solnic commented 1 year ago

Thanks for reporting this. I just released 1.11.3 with a fix. I hope it'll work as expected now.