I know I can make a custom predicate to circumvent this exclusion, but this seems overhead.
I guess there is a good reason to exclude this info from the hints, but I fail to see why…
some follow-up, I’m actually trying to validate an array of Hashes and want to:
(1) first detect it is an array
(2) detect it is not empty
(3) validate that each element of the array complies to something (lets keep it simple :value must be Hash)
The dry-validation docs contain an example which does (1) and (3)
schema = Dry::Validation.Schema do
required(:phone_numbers).each(:hash?)
end
schema.call(phone_numbers: '').messages
---> { :phone_numbers => ["must be an array"] }
But if I try to add restriction (2) it changes the error to {:phone_numbers=>[“must be filled”]} and looses the info on being an array…
Dry::Validation.Schema { required(:phone_numbers).filled(:array?).each(:hash?)}.call(phone_numbers: []).messages
=> {:phone_numbers=>["must be filled"]}
or
Dry::Validation.Schema { required(:phone_numbers).filled.each(:hash?)}.call(phone_numbers: []).messages
=> {:phone_numbers=>["must be filled"]}
or
Dry::Validation.Schema { required(:phone_numbers) { array? & filled? { each { hash?} } }}.call(phone_numbers: []).messages
TypeError: no implicit conversion of Symbol into Integer
There are two caveats here, both are high priority for fixing/improving before 1.0.0:
chaining is not supported, and it doesn’t raise when you try to do that. We’ll either add support for chaining (I would prefer that) or at least make it raise
each actually adds array? check for you, which is implicit and problematic in some cases, so it will be changed before 1.0.0
Oh and to answer your question regarding hints, we exclude all primitive type checks from hints as they are so basic it didn’t make sense to include them, it is expected that your rules defines type checks as the very first rule, so it will always cause an error so we don’t need them as hints. We may try to experiment with enforcing that, so that if you have rules that don’t have any primitive type check, it’ll warn you.
Key point is indeed that chaining is not supported:
required(:phone_numbers).value(:array?, :filled?).each(:hash?) does not work
required(:phone_numbers).value(:array?, :filled?) { each(:hash?) } works fine...