norm
norm copied to clipboard
[Suggestion] Support for validation messaging
Norm is proving to be very useful for validating schemas of internal processes. With that success, we're looking to use Norm as our primary validation within Ecto due to its robustness as well as an interest in keeping our approach to validation unified.
That said, the biggest thing that's holding us back is the error messages returned. Our approach to adding Norm errors to a changeset is simple (https://github.com/keathley/norm/issues/7#issuecomment-621971281), but results in errors like Title failed schema validation: &(String.length(&1) > 2) which is something we can't show to our end users.
I'd be open to taking a stab at allowing per-spec error messaging, but I worry that this would be outside of Norm's scope as it currently stands. Would there be any interest in a PR for this? If so, are there any suggestions for a preferred syntax?
I've been thinking for a while about the best way to support customizable error messages. So far I haven't come up with anything that I really love. I was considering using a behaviour for this, but it would mean that you would need a way to set it either globally (probably through application env) or per spec or per conform call. Or perhaps some combination of all 3.
If you'd like to submit a PR I'd be happy to take a look at what you come up with. At the very least it would provide a basis for discussion.
@keathley Thanks for the input! I've thrown together a PR here with an initial attempt: https://github.com/keathley/norm/pull/83
Hopefully that can be a jumping off point for conversation