Decoupling input pre-processing from validation rules


#1

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.(
  Dry::Validation::Processors::Params.(my_input)
)

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.


#2

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.


#3

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