jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 58 forks source link

Structure of error messages in 3.15 not compatible with previous versions? #176

Closed phochste closed 4 years ago

phochste commented 4 years ago

Steps to reproduce the behavior

Run this code in 3.15 and in a previous version of JSON::Validator. One can see that the error handling has been changed and is not backwards compatible.

use Data::Dumper;
use JSON::Validator;
my $jv = JSON::Validator->new;

$jv->schema({
  type       => "object",
  required   => ["firstName", "lastName"],
  properties => {
    firstName => {type => "string"},
    lastName  => {type => "string"},
    age       => {type => "integer", minimum => 0, description => "Age in years"}
  }
});

my @errors = $jv->validate({firstName => "Jan Henning", lastName => "Thorsen", age => -42});

warn Dumper(\@errors);

Expected behavior

I expect a path and a message key (and maybe a new details key)

Actual behavior

The message key has been deleted from the error messages

jhthorsen commented 4 years ago

Do you mean hash lookup keys? I don’t think that’s ever been documented to work, so by poking knot the hash-ref, you’re breaking encapsulation. If you want the Dumper() code to work as you expect, the you have to call TO_JSON() on each of the error objects.

The proper way is to use the message() method to get the message.