I have a schema that has an optional Hash. That Hash is always a <string, string> type, and the Hash can be empty. I’m trying to write a validation Contract for that.
The dry-types documentation has a definition and example for a Map. And yet when I use that in my validation Contract, I get a ‘NotImplemented’ error with the message “map types are not supported yet”
Here’s a minimal example:
require "dry-validation"
StringStringMap = ::Dry::Types['hash'].map(::Dry::Types['string'], ::Dry::Types['string'])
class StringStringMapContract < Dry::Validation::Contract
schema do
optional(:properties).value(StringStringMap)
end
end
Does Map work with validation or schema? If so, what am I missing? (I’ve only recently started using dry-rb, so it’s very probably that it’s my error.)
If not, the documentation should be updated – perhaps for all 3 gems (dry-types, dry-schema, dry-validation) noting the context where Map does and does not work.
I’m using the latest versions of the gems. ruby 3.4.5