hoxworth/json-schema — Issue #29: Add in a validation error structure
Author: hoxworth
Created: 2012-02-14 14:12:31+00:00
State: open

From @obfuscurity (yes, I'll actually do this instead of ignore it for another month):

How difficult would it be to pass back an AoH with the property
attribute? For example, instead of:

[6] pry(main)>
JSON::Validator.fully_validate('{"name":"User","properties":{"firstname":{"description":"Name","type":"string","minLength":1,"required":true},"lastname":{"description":"Surname","type":"string","minLength":1,"required":false}}}', '{"firstname":""}', :validate_schema => true)
=> ["The property '#/firstname' was not of a minimum string length of 1 in schema 57060c97-bfe0-5cfd-a710-1b7f675d98e7#"]

You get:

=>
[
{
:property => 'firstname',
:failed_attribute => 'minLength',
:message => "The property '#/firstname' was not of a minimum string length of 1 in schema 57060c97-bfe0-5cfd-a710-1b7f675d98e7#"
}
]

It's not a huge deal, but it could be very useful. Assuming the format
is static I can just regex it out. Either way thank you for this
feature. :)