add meta info to dry-validation schema

Hello, I’m playing with the idea of defining a dry-validation schema and using it to dynamically generate
an html form based on it, i’ve reached a point where i it would be nice to pass some additional metadata to the form, I’ve searched and saw the Dry::Types::Meta and that seems to fulfill my needs but it’s a bit verbose having to pass filled(Dry::Type[“integer”]) instead of filled(:integer), is there an api to pass the meta directly from the dry-validation schema or would i need to roll my own?

thanks in advance, and thank you for such an amazing proyect

I’m not aware of any interface for metadata in dry-schema, I have only ever seen that applied to concrete types directly.

It probably wouldn’t be very difficult to add a new Macro for metadata, but you’re on your own there.

If you’re doing anything remotely complicated, you’ll almost certainly want custom types for things. My approach is to define a Types module and alias it to T for brevity

# since this is for HTML forms, you'll probably want params
Types = Dry::Types(default: :params)

module Types
  # custom types defined here
end

T = Types

Then I will reference it in schemas like T::Integer

required(:field).value(T::Integer.meta(foo: "bar"))
1 Like

Thanks for the reply, the T shortcut looks pretty good will definitely use it, and look at adding a macro for the metadata. :slight_smile: