voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.52k stars 241 forks source link

It would be very useful if the required property name was included in the error object #417

Closed ndbroadbent closed 5 years ago

ndbroadbent commented 5 years ago
=> [{:schema=>#<Addressable::URI:0x3ffe4475df78 URI:https://example.com/schema.json>,
  :fragment=>"#/",
  :message=>"The root object did not contain a required property of 'title'",
  :failed_attribute=>"Required"}]

I'm using the errors_as_objects: true option, and was hoping that this would give me "title" somewhere as a value, which would make it easier to work with the errors. With the current data, I need to manually construct a regex to match title in the :message string, which is pretty ugly.

I will work on a PR to add this as a new :failed_property field.

ndbroadbent commented 5 years ago

Opened a PR: