Get keys instead of sentences for validation errors

I have an API where I am wanting to just return the error symbols/keys rather than sentences/text when validation fails. Something along the lines of {amount: [:missing, :min_size]} or maybe {amount: {missing: {text: 'is missing'}, size: {left: 0, right: 1000, text: 'must be between 0 and 1000'}}. Is this possible to do currently in dry-validation?

Thanks,
Steve

You have two options:

  1. Implement a custom message compiler by subclassing this built in one - this is more advanced but it will give you complete control over the structure that’s returned by validation result
  2. Simply use Dry::Validation::Result#message_set and see if you have enough information in the message objects to map them to the structure that you want to have. ie schema.(params).message_set(hints: false).map { |msg| ... } would yield error message objects to the block and you can do whatever you want there

Lemme know which one sounds like a better fit.