Decoupling input pre-processing from validation rules

Currently, it is possible to define, for example, the validation of a form through Dry::Validation.Params. It will pre-process given input (symbolizing keys and coercing values) and later it will apply the “expected schema”.

However, I’d like to be able to define just a “core business” schema, and then be able to call it from different interfaces applying an input pre-processor which only makes sense for that interface. For example, for the web interface, something like that:

result = MySchema.(

I think it makes more sense because it is decoupling validation rules from input pre-processing. However, if I’m not wrong, it is possible to do that easily. Pre-processors expect the AST, and doing it manually through type_specs would be very cumbersome.

Is there another way to do that, or is it planned for 1.0?

Thanks in advance.

This will be separated in dry-schema that dry-validation will use. I recently started working on it in this PR. The idea is that pre-processing (aka coercion) will be an even more distinct step, furthermore, you’ll be able to provide “filter” rules that will reject any input that cannot be coerced.

Happy to hear that, that looks even better. Thanks for your reply!

Since dry-schema and dry-validation both exist now, are there any clear examples of this idea being applied?

@shepmaster dry-schema is responsible for the input pre-processing (coercion, like to Params or JSON) while dry-validation handles validation rules. It’s its core behaviour, so you just have to look at their documentation to see examples :slight_smile: