dry-rb / dry-validation

Validation library with type-safe schemas and rules
https://dry-rb.org/gems/dry-validation
MIT License
1.34k stars 188 forks source link

Building contract failed when or-ing types #712

Closed sdalu closed 2 years ago

sdalu commented 2 years ago

The following code result in key not found: "int?" (Dry::Container::KeyError)

module Types
  include Dry::Types()
end
class B < Dry::Validation::Contract
  json do
    optional(:id).filled(Types::Integer | Types::String)
  end
end

dry-validation: 1.8.1 dry-schema: 1.10.2 dry-types: 1.5.1 ruby: 3.1.2

solnic commented 2 years ago

Please provide a reproduction script, the snippet you provided works for me.

solnic commented 2 years ago

oh and btw, I would do it like that anyway:

optional(:id) { int? | (str? & filled?) }

This makes more sense, because it's supposed to be either an integer or a string that's not empty.