voxpupuli / json-schema

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

Add :property_fragment to errors hash, to show which required property was missing #420

Open ndbroadbent opened 5 years ago

ndbroadbent commented 5 years ago

I understand the reasoning behind :fragment => "#/" for a required property that is missing from the root object. But I really needed to know which required property is missing, and I didn't want to parse it out of the message string.

I've added a new :property_fragment to the validation error hash, and this is a more consistent way of detecting which field is causing the validation error. For required fields, it will show the property that is missing. And it will be the same for fields that have the wrong data type, etc (because it falls back to :fragment by default.)

This change should be fully backwards compatible, since it just adds a new key to the error hash.

RST-J commented 5 years ago

LGTM

ssrihari commented 5 years ago

plz2merge @iainbeeston

pboling commented 3 years ago

https://github.com/ruby-json-schema/json-schema/issues/423#issuecomment-634811990