dry-rb / dry-rb/dry-validation
Errors without messages
- Dominant language
- Ruby
- Stars
- 1.4k
- Forks
- 195
- PR merge metrics
- No merged PRs in 30d
Description
At the moment validation contract returns nice human-readable errors via translation backend. Being a robot, I do not like it and I'd prefer pure data object/hash to be returned.
Justification: I don't think it is contract responsibility to translate it's errors. When used within API, all the i18n normally happens on the client side, so API can be completely translation-free.
## Examples
class MyContract < Dry::Validation::Contract
json do
required(:name).filled(:string)
required(:age).filled(:integer)
end
rule(:age) do
key.failure(:too_young, min: 32) if age < 32
end
end
contract = MyContract.new
errors = MyContract.new(age: 28).errors
errors.to_h # => {
name: [{error: :missing}]
age: [{error: :too_young, min: 32}]
}
(The above is only example response, I have no strong preference/opinion on how that data should be represented)
## Resources
Discourse "discussion": https://discourse.dry-rb.org/t/dry-validation-and-error-translations/919
Contributor guide
Research direction
Start by examining the Contract error API and the errors.to_h example in this issue, then read the linked Discourse discussion about error translations. Define the data-only error representation and its compatibility with the translation backend before identifying the relevant implementation and tests; done means validation errors can be consumed as structured data without human-readable translation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100