jhthorsen / json-validator

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

JSON Core schema does not validate against itself #144

Closed merkys closed 5 years ago

merkys commented 5 years ago

Steps to reproduce the behavior

Validate JSON Core meta-schema (draft-07) against itself.

Expected behavior

Successful validation.

Actual behavior

Not a HASH reference at /usr/share/perl5/JSON/Validator.pm line 531.
jhthorsen commented 5 years ago

Can you extend the "Steps to reproduce the behavior" section with actual code?

merkys commented 5 years ago

Sorry for not being specific enough initially. Here is my code:

#!/usr/bin/perl

use strict;
use warnings;
use JSON;
use JSON::Validator;
use Data::Dumper;

open( my $inp, 'schema-draft07.json' );
my $json = decode_json( join( "\n", <$inp> ) );
close $inp;

my $v = JSON::Validator->new->schema( $json );
print Dumper [ $v->validate( $json, $json ) ];

where schema-draft07.json is http://json-schema.org/draft-07/schema.

jhthorsen commented 5 years ago

Thank you for the example code. I'll hopefully find time to look at it in the next days.

jhthorsen commented 5 years ago

This should be fixed in 3.04, which will soon be available on CPAN.

merkys commented 5 years ago

Great, thanks!

karenetheridge commented 5 years ago

I just ran into this on a machine that hadn't upgraded JSON::Validator in a few months...

This was fixed in commit 046cd3f3f:

+  # Do not validate against "default" in draft-07 schema
+  return if blessed $schema and $schema->isa('JSON::PP::Boolean');

I am wondering if it should also be checking the value of the boolean - i.e. if it is false, rather than true, validate should return false? or am I totally misunderstanding what is happening here?

jhthorsen commented 5 years ago

Sorry, I don’t follow.