json-schema icon indicating copy to clipboard operation
json-schema copied to clipboard

Changing error message format

Open Trevoke opened this issue 11 years ago • 14 comments

It would be nice to have a way to customize the formatting of the error messages.

Trevoke avatar Jan 28 '14 18:01 Trevoke

+1

polmiro avatar Jun 02 '14 15:06 polmiro

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).

iainbeeston avatar Oct 29 '14 09:10 iainbeeston

:thumbsup: on the i18n tactic. I kept drawing a blank when trying to think of a reasonable way to implement this.

pd avatar Oct 29 '14 15:10 pd

Any progress on this? I would love the replace the validation logic in my rails-api app with JSON::Validator :smile:

ream88 avatar Mar 01 '15 20:03 ream88

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

iainbeeston avatar Mar 01 '15 20:03 iainbeeston

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.

ream88 avatar Mar 02 '15 09:03 ream88

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!)

GrooveStomp avatar May 06 '15 22:05 GrooveStomp

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 avatar May 07 '15 07:05 iainbeeston

@iainbeeston That sounds great. I may forge ahead with a fork here. Are you amenable to pull requests?

GrooveStomp avatar May 08 '15 21:05 GrooveStomp

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 .

iainbeeston avatar May 09 '15 06:05 iainbeeston

any progress on that ? I think it's important as more and more people are using JSON schema for their API validations :)

vasilakisfil avatar Oct 08 '15 11:10 vasilakisfil

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 avatar Oct 08 '15 16:10 GrooveStomp

@GrooveStomp please do I think your work is vital to the community :)

vasilakisfil avatar Oct 09 '15 07:10 vasilakisfil

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

iainbeeston avatar Nov 10 '15 09:11 iainbeeston