konform-kt / konform

Portable validations for Kotlin
https://www.konform.io
MIT License
663 stars 39 forks source link

Custom types for hints / error messages #146

Closed Bendzae closed 2 hours ago

Bendzae commented 7 hours ago

Context

Currently a hint or errorMessage has to be a string. It would be great to be able to supply a custom type for these to allow a more flexibility in the we different applications might model their errors.

Proposed solution

Of course library default messages like "is required" would need to be customisable then (which would be a great feature anyways).

I would be more then happy to create a PR to implement this if it is something that could be considered 🙂

dhoepelman commented 5 hours ago

Thanks for the proposal. Currently not interested in doing this for mainly 2 reasons:

  1. It's a large breaking change to the API, would require much existing code to be rewritten
    • The alternative would be to add a second type, but this would bloat the API a lot
  2. The primary purpose of this library is to validate with human-readable, not to handle different validation scenarios separately.

You can take a look at Arrow's Either, which has the customizable error type.

For the specific example given I would personally probably make a Validation per severity level, and then collect them using the ValidationResult.errors list with a severity attached

Bendzae commented 2 hours ago

Alright that makes a lot of sense. Thank you for the quick reply and great work on konform anyways!