json-schema
json-schema copied to clipboard
Changing error message format
It would be nice to have a way to customize the formatting of the error messages.
+1
I plan on working on this in the near future. My plan is that if you have the i18n gem installed them you can customize error messages through that (but if you don't have i18n nothing will change).
:thumbsup: on the i18n tactic. I kept drawing a blank when trying to think of a reasonable way to implement this.
Any progress on this? I would love the replace the validation logic in my rails-api app with JSON::Validator :smile:
Haven't had a chance yet.
If you're interested I did make a gem that used Json Schema for active model validations:
https://github.com/iainbeeston/json_validator
Wow, this is incredible useful! :)
On 01 Mar 2015, at 21:33, Iain Beeston [email protected] wrote:
Haven't had a chance yet.
If you're interested I did make a gem that used Json Schema for active model validations:
https://github.com/iainbeeston/json_validator https://github.com/iainbeeston/json_validator — Reply to this email directly or view it on GitHub https://github.com/ruby-json-schema/json-schema/issues/97#issuecomment-76628922.
i18n support would be great, but I'm not sure it's quite what my team is looking for.
What we'd like to see is the ability to call #fully_validate
and get a list of error objects in return, like this:
[
{
fragment: '#/',
property: 'city',
failed_attribute: 'required'
}
]
That way we could meaningfully construct our own keys for translation. Or would your idealized implementation obviate this approach, @iainbeeston ? (PS - Thanks for the gem!)
I see. That's a good idea. At the minimum I can make sure errors as objects includes the i18n keys for the error messages On Wed, 6 May 2015 at 11:28 pm, GrooveStomp [email protected] wrote:
i18n support would be great, but I'm not sure it's quite what my team is looking for. What we'd like to see is the ability to call #fully_validate and get a list of error objects in return, like this:
[ { fragment: '#/', property: 'city', failed_attribute: 'required' } ]
That way we could meaningfully construct our own keys for translation. Or would your idealized implementation obviate this approach, @iainbeeston https://github.com/iainbeeston ? (PS - Thanks for the gem!)
— Reply to this email directly or view it on GitHub https://github.com/ruby-json-schema/json-schema/issues/97#issuecomment-99629950 .
@iainbeeston That sounds great. I may forge ahead with a fork here. Are you amenable to pull requests?
Yes of course - go ahead! A minimal implementation would be to add the fields you suggested to the errors object and later I can use the error type as the key for an i18n translation On Fri, 8 May 2015 at 10:49 pm, GrooveStomp [email protected] wrote:
@iainbeeston https://github.com/iainbeeston That sounds great. I may forge ahead with a fork here. Are you amenable to pull requests?
— Reply to this email directly or view it on GitHub https://github.com/ruby-json-schema/json-schema/issues/97#issuecomment-100377084 .
any progress on that ? I think it's important as more and more people are using JSON schema for their API validations :)
We've been using a fork for several months now that implements behavior based on the above. I have some work left on it before submitting, but you can view my changes here: https://github.com/GrooveStomp/json-schema/pull/1
@GrooveStomp please do I think your work is vital to the community :)
Thanks for sharing @GrooveStomp , I still haven't had time to work on my own solution, but my plan was to make all of the error messages customisable, as well as the property names.
I'd like to put some time into this in the near future but unfortunately there are performance issues with the gem that are even more pressing