dry-rb / dry-validation

Validation library with type-safe schemas and rules
https://dry-rb.org/gems/dry-validation
MIT License
1.34k stars 188 forks source link

errors(full: true), for nested input, could be better #731

Open jaredbeck opened 1 year ago

jaredbeck commented 1 year ago

Describe the bug

result = contract.call(params)

# errors(full: false) works fine ..
result.errors.to_h.to_json
# "{\"items\":{\"0\":{\"weight\":{\"unit\":[\"must be one of: g, kg, lb, oz\"]}}}}"

# errors(full: true), for nested input, could be better
result.errors(full: true).to_h.values.join(', ')
# "{0=\u003e{:weight=\u003e{:unit=\u003e[\"unit must be one of: g, kg, lb, oz\"]}}}"

I'm happy to attempt a PR, if requested.

To Reproduce

Call a Contract that validates nested input, as shown above. If the above is unclear, I'm happy to provide more detail.

Expected behavior

It'd be great to have better output. For example:

result.errors(full: true).to_h.values.join(', ')
# "items 0 weight unit must be one of: g, kg, lb, oz"

My environment

flash-gordon commented 1 year ago

Could you please post sample code for reproducing it?