Hello community,
here is the log from the commit of package perl-JSON-Validator for
openSUSE:Factory checked in at 2020-03-11 18:50:18
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-JSON-Validator (Old)
and /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.3160 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-JSON-Validator"
Wed Mar 11 18:50:18 2020 rev:17 rq:783470 version:3.24
Changes:
--------
--- /work/SRC/openSUSE:Factory/perl-JSON-Validator/perl-JSON-Validator.changes
2020-02-20 14:56:14.878390206 +0100
+++
/work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.3160/perl-JSON-Validator.changes
2020-03-11 18:52:29.099598117 +0100
@@ -1,0 +2,15 @@
+Wed Mar 4 03:09:18 UTC 2020 - <[email protected]>
+
+- updated to 3.24
+ see /usr/share/doc/packages/perl-JSON-Validator/Changes
+
+ 3.24 2020-03-03T15:46:39+0900
+ - Optimize checksum generation #202
+ Contributor: Ere Maijala
+ - Improved "type":[...] error messages #199
+ Contributor: Karen Etheridge
+ - Fix handle validation of true, false schemas in oneOf #201 #203
+ Contributor: Karen Etheridge
+ - Fix guessing type:object if "dependencies" is present #206
+
+-------------------------------------------------------------------
Old:
----
JSON-Validator-3.23.tar.gz
New:
----
JSON-Validator-3.24.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-JSON-Validator.spec ++++++
--- /var/tmp/diff_new_pack.ruZYH0/_old 2020-03-11 18:52:32.175599493 +0100
+++ /var/tmp/diff_new_pack.ruZYH0/_new 2020-03-11 18:52:32.175599493 +0100
@@ -17,7 +17,7 @@
Name: perl-JSON-Validator
-Version: 3.23
+Version: 3.24
Release: 0
%define cpan_name JSON-Validator
Summary: Validate data against a JSON schema
@@ -34,8 +34,10 @@
BuildRequires: perl(Mojolicious) >= 7.28
BuildRequires: perl(Test::Deep)
BuildRequires: perl(Test::More) >= 1.30
+BuildRequires: perl(YAML::XS) >= 0.80
Requires: perl(List::Util) >= 1.45
Requires: perl(Mojolicious) >= 7.28
+Requires: perl(YAML::XS) >= 0.80
%{perl_requires}
%description
++++++ JSON-Validator-3.23.tar.gz -> JSON-Validator-3.24.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/Changes
new/JSON-Validator-3.24/Changes
--- old/JSON-Validator-3.23/Changes 2020-02-19 01:37:44.000000000 +0100
+++ new/JSON-Validator-3.24/Changes 2020-03-03 07:46:39.000000000 +0100
@@ -1,7 +1,16 @@
Revision history for perl distribution JSON-Validator
+3.24 2020-03-03T15:46:39+0900
+ - Optimize checksum generation #202
+ Contributor: Ere Maijala
+ - Improved "type":[...] error messages #199
+ Contributor: Karen Etheridge
+ - Fix handle validation of true, false schemas in oneOf #201 #203
+ Contributor: Karen Etheridge
+ - Fix guessing type:object if "dependencies" is present #206
+
3.23 2020-02-19T09:37:44+0900
- - Using List::Util::uniq() instead of JSON::Validator::Util::uniq #198
+ - Using List::Util::uniq() instead of JSON::Validator::Util::uniq() #198
3.22 2020-02-15T08:35:29+0900
- Add support for "dependencies" keyword #192 #197
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/MANIFEST
new/JSON-Validator-3.24/MANIFEST
--- old/JSON-Validator-3.23/MANIFEST 2020-02-19 01:37:45.000000000 +0100
+++ new/JSON-Validator-3.24/MANIFEST 2020-03-03 07:46:40.000000000 +0100
@@ -91,6 +91,7 @@
t/jv-string.t
t/load-data.t
t/load-file.t
+t/load-from-app.t
t/load-http.t
t/load-json.t
t/load-yaml.t
@@ -115,6 +116,7 @@
t/stack/Some.pm
t/stack/Some/Module.pm
t/to-json.t
+t/util-checksum-yaml-xs.t
t/util.t
t/validate-draft07.t
t/validate-id.t
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/META.json
new/JSON-Validator-3.24/META.json
--- old/JSON-Validator-3.23/META.json 2020-02-19 01:37:45.000000000 +0100
+++ new/JSON-Validator-3.24/META.json 2020-03-03 07:46:40.000000000 +0100
@@ -36,6 +36,7 @@
"requires" : {
"List::Util" : "1.45",
"Mojolicious" : "7.28",
+ "YAML::XS" : "0.80",
"perl" : "5.010001"
}
},
@@ -62,6 +63,6 @@
},
"x_IRC" : "irc://irc.freenode.net/#mojo"
},
- "version" : "3.23",
+ "version" : "3.24",
"x_serialization_backend" : "JSON::PP version 4.02"
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/META.yml
new/JSON-Validator-3.24/META.yml
--- old/JSON-Validator-3.23/META.yml 2020-02-19 01:37:45.000000000 +0100
+++ new/JSON-Validator-3.24/META.yml 2020-03-03 07:46:40.000000000 +0100
@@ -24,6 +24,7 @@
requires:
List::Util: '1.45'
Mojolicious: '7.28'
+ YAML::XS: '0.80'
perl: '5.010001'
resources:
IRC: irc://irc.freenode.net/#mojo
@@ -31,5 +32,5 @@
homepage: https://mojolicious.org
license: http://www.opensource.org/licenses/artistic-license-2.0
repository: https://github.com/mojolicious/json-validator.git
-version: '3.23'
+version: '3.24'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/Makefile.PL
new/JSON-Validator-3.24/Makefile.PL
--- old/JSON-Validator-3.23/Makefile.PL 2020-02-18 08:56:50.000000000 +0100
+++ new/JSON-Validator-3.24/Makefile.PL 2020-03-03 07:38:57.000000000 +0100
@@ -30,9 +30,10 @@
x_IRC => 'irc://irc.freenode.net/#mojo',
},
},
- PREREQ_PM => {'List::Util' => '1.45', 'Mojolicious' => '7.28'},
- TEST_REQUIRES => {'Test::More' => '1.30', 'Test::Deep' => '0'},
- test => {TESTS => (-e 'META.yml' ? 't/*.t' : 't/*.t xt/*.t')},
+ PREREQ_PM =>
+ {'List::Util' => '1.45', 'Mojolicious' => '7.28', 'YAML::XS' => '0.80'},
+ TEST_REQUIRES => {'Test::More' => '1.30', 'Test::Deep' => '0'},
+ test => {TESTS => (-e 'META.yml' ? 't/*.t' : 't/*.t
xt/*.t')},
);
unless (eval { ExtUtils::MakeMaker->VERSION('6.63_03') }) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/lib/JSON/Validator/Util.pm
new/JSON-Validator-3.24/lib/JSON/Validator/Util.pm
--- old/JSON-Validator-3.23/lib/JSON/Validator/Util.pm 2020-02-18
08:56:16.000000000 +0100
+++ new/JSON-Validator-3.24/lib/JSON/Validator/Util.pm 2020-03-03
07:36:29.000000000 +0100
@@ -1,8 +1,7 @@
package JSON::Validator::Util;
use Mojo::Base -strict;
-use Carp ();
-use Data::Dumper ();
+use Carp ();
use Exporter 'import';
use JSON::Validator::Error;
use List::Util;
@@ -11,14 +10,19 @@
use Mojo::Loader;
use Mojo::Util;
use Scalar::Util 'blessed';
+use YAML::XS;
our @EXPORT_OK
= qw(E data_checksum data_section data_type is_type schema_extract
json_pointer prefix_errors schema_type);
sub E { JSON::Validator::Error->new(@_) }
+my $serializer
+ = eval 'use Sereal::Encoder;1' ? \&_sereal_encode : \&YAML::XS::Dump;
+
sub data_checksum {
- Mojo::Util::md5_sum(Data::Dumper->new([@_])->Sortkeys(1)->Useqq(1)->Dump);
+ return Mojo::Util::md5_sum(
+ ref $_[0] ? $serializer->($_[0]) : defined $_[0] ? qq('$_[0]') : 'undef');
}
sub data_section {
@@ -110,7 +114,7 @@
push @errors, map {
my $msg = sprintf '/%s/%s %s', $type, $index, $_->message;
$msg =~ s!(\d+)\s/!$1/!g;
- E $_->path, $msg;
+ E +{%$_, message => $msg}; # preserve 'details', for later
introspection
} @$e;
}
@@ -118,12 +122,14 @@
}
sub schema_type {
+ return '' if ref $_[0] ne 'HASH';
return $_[0]->{type} if $_[0]->{type};
return _guessed_right(object => $_[1]) if $_[0]->{additionalProperties};
return _guessed_right(object => $_[1]) if $_[0]->{patternProperties};
return _guessed_right(object => $_[1]) if $_[0]->{properties};
return _guessed_right(object => $_[1]) if $_[0]->{propertyNames};
return _guessed_right(object => $_[1]) if $_[0]->{required};
+ return _guessed_right(object => $_[1]) if $_[0]->{dependencies};
return _guessed_right(object => $_[1])
if defined $_[0]->{maxProperties}
or defined $_[0]->{minProperties};
@@ -190,6 +196,11 @@
return $data;
}
+sub _sereal_encode {
+ state $s = Sereal::Encoder->new({canonical => 1});
+ return $s->encode($_[0]);
+}
+
1;
=encoding utf8
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/lib/JSON/Validator.pm
new/JSON-Validator-3.24/lib/JSON/Validator.pm
--- old/JSON-Validator-3.23/lib/JSON/Validator.pm 2020-02-19
01:37:44.000000000 +0100
+++ new/JSON-Validator-3.24/lib/JSON/Validator.pm 2020-03-03
07:46:39.000000000 +0100
@@ -24,7 +24,7 @@
use constant SPECIFICATION_URL => 'http://json-schema.org/draft-04/schema#';
use constant YAML_SUPPORT => eval 'use YAML::XS 0.67;1';
-our $VERSION = '3.23';
+our $VERSION = '3.24';
our @EXPORT_OK = qw(joi validate_json);
my $BUNDLED_CACHE_DIR = path(path(__FILE__)->dirname, qw(Validator cache));
@@ -519,8 +519,7 @@
# Test base schema before allOf, anyOf or oneOf
if (ref $type eq 'ARRAY') {
push @{$self->{temp_schema}}, [map { +{%$schema, type => $_} } @$type];
- push @errors,
- $self->_validate_any_of($to_json ? $$to_json : $_[1],
+ return $self->_validate_any_of_types($to_json ? $$to_json : $_[1],
$path, $self->{temp_schema}[-1]);
}
elsif ($type) {
@@ -574,69 +573,105 @@
sub _validate_all_of {
my ($self, $data, $path, $rules) = @_;
- my $type = data_type $data, $rules;
- my (@errors, @expected);
+ my (@errors, @errors_with_prefix);
my $i = 0;
for my $rule (@$rules) {
next unless my @e = $self->_validate($_[1], $path, $rule);
- my $schema_type = schema_type $rule;
- push @expected, $schema_type if $schema_type;
- push @errors, [$i, @e] if !$schema_type or $schema_type eq $type;
+ push @errors, @e;
+ push @errors_with_prefix, [$i, @e];
}
continue {
$i++;
}
- return E $path, [allOf => type => join('/', uniq @expected), $type]
- if !@errors and @expected;
- return prefix_errors allOf => @errors if @errors;
- return;
+ return if not @errors;
+
+ return prefix_errors(allOf => @errors_with_prefix)
+ if @errors == 1
+ or
+ (grep { $_->details->[1] ne 'type' or $_->path ne ($path || '/') }
@errors);
+
+ # combine all 'type' errors at the base path together
+ my @details = map $_->details, @errors;
+ my $want_types = join '/', uniq map $_->[0], @details;
+ return E $path, [allOf => type => $want_types, $details[-1][2]];
+}
+
+sub _validate_any_of_types {
+ my ($self, $data, $path, $rules) = @_;
+ my @errors;
+
+ for my $rule (@$rules) {
+ return unless my @e = $self->_validate($_[1], $path, $rule);
+ push @errors, @e;
+ }
+
+ # favour a non-type error from one of the rules
+ if (my @e
+ = grep { $_->details->[1] ne 'type' or $_->path ne ($path || '/') }
@errors)
+ {
+ return @e;
+ }
+
+ # the type didn't match any of the rules: combine the errors together
+ my @details = map $_->details, @errors;
+ my $want_types = join '/', uniq map $_->[0], @details;
+ return E $path, [$want_types => 'type', $details[-1][2]];
}
sub _validate_any_of {
my ($self, $data, $path, $rules) = @_;
- my $type = data_type $data, $rules;
- my (@e, @errors, @expected);
+ my (@errors, @errors_with_prefix);
my $i = 0;
for my $rule (@$rules) {
- @e = $self->_validate($_[1], $path, $rule);
- return unless @e;
- my $schema_type = schema_type $rule;
- push @errors, [$i, @e] and next if !$schema_type or $schema_type eq $type;
- push @expected, $schema_type;
+ return unless my @e = $self->_validate($_[1], $path, $rule);
+ push @errors, @e;
+ push @errors_with_prefix, [$i, @e];
}
continue {
$i++;
}
- my $expected = join '/', uniq @expected;
- return E $path, [anyOf => type => $expected, $type] unless @errors;
- return prefix_errors anyOf => @errors;
+ return prefix_errors(anyOf => @errors_with_prefix)
+ if @errors == 1
+ or
+ (grep { $_->details->[1] ne 'type' or $_->path ne ($path || '/') }
@errors);
+
+ # combine all 'type' errors at the base path together
+ my @details = map $_->details, @errors;
+ my $want_types = join '/', uniq map $_->[0], @details;
+ return E $path, [anyOf => type => $want_types, $details[-1][2]];
}
sub _validate_one_of {
my ($self, $data, $path, $rules) = @_;
- my $type = data_type $data, $rules;
- my (@errors, @expected);
+ my (@errors, @errors_with_prefix);
my ($i, @passed) = (0);
for my $rule (@$rules) {
my @e = $self->_validate($_[1], $path, $rule) or push @passed, $i and next;
- my $schema_type = schema_type $rule;
- push @errors, [$i, @e] and next if !$schema_type or $schema_type eq $type;
- push @expected, $schema_type;
+ push @errors_with_prefix, [$i, @e];
+ push @errors, @e;
}
continue {
$i++;
}
return if @passed == 1;
- return E $path, [oneOf => 'all_rules_match'] unless @errors + @expected;
+ return E $path, [oneOf => 'all_rules_match'] unless @errors;
return E $path, [oneOf => 'n_rules_match', join(', ', @passed)] if @passed;
- return prefix_errors oneOf => @errors if @errors;
- return E $path, [oneOf => type => join('/', uniq @expected), $type];
+
+ return prefix_errors(oneOf => @errors_with_prefix)
+ if @errors == 1
+ or
+ (grep { $_->details->[1] ne 'type' or $_->path ne ($path || '/') }
@errors);
+
+ # the type didn't match any of the rules: combine the errors together
+ my @details = map $_->details, @errors;
+ my $want_types = join '/', uniq map $_->[0], @details;
+ return E $path, [oneOf => type => $want_types, $details[-1][2]];
}
sub _validate_number_max {
@@ -862,7 +897,7 @@
if (my $n_schema = $schema->{propertyNames}) {
for my $name (keys %$data) {
next unless my @e = $self->_validate($name, $path, $n_schema);
- push @errors, prefix_errors propertyName => [map { ($name, $_) } @e];
+ push @errors, prefix_errors propertyName => map [$name, $_], @e;
}
}
@@ -1327,7 +1362,11 @@
=item * Any other URL
An URL (without a recognized scheme) will be treated as a path to a file on
-disk.
+disk. If the file could not be found on disk and the path starts with "/", then
+the will be loaded from the app defined in L</ua>. Something like this:
+
+ $jv->ua->server->app(MyMojoApp->new);
+ $jv->ua->get('/any/other/url.json');
=back
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/acceptance.t
new/JSON-Validator-3.24/t/acceptance.t
--- old/JSON-Validator-3.23/t/acceptance.t 2020-02-18 08:49:52.000000000
+0100
+++ new/JSON-Validator-3.24/t/acceptance.t 2020-03-03 07:35:36.000000000
+0100
@@ -18,7 +18,6 @@
my $test_only_re = $ENV{TEST_ONLY} || '';
my $todo_re = join('|',
- 'dependencies',
'change resolution scope - changed scope ref valid',
$ENV{TEST_ONLINE} ? () : ('remote ref'),
);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/issue-103-one-of.t
new/JSON-Validator-3.24/t/issue-103-one-of.t
--- old/JSON-Validator-3.23/t/issue-103-one-of.t 2020-02-07
03:10:28.000000000 +0100
+++ new/JSON-Validator-3.24/t/issue-103-one-of.t 2020-03-01
09:09:31.000000000 +0100
@@ -5,7 +5,8 @@
desc => 'foo'}, 'data://main/example.json',
E('/sym', '/oneOf/0/allOf/0/allOf/0 Missing property.'),
E('/template', '/oneOf/0/allOf/2 Missing property.'),
- E('/sym', '/oneOf/1/allOf/0 Missing property.');
+ E('/sym', '/oneOf/1/allOf/0 Missing property.'),
+ E('/', '/oneOf/2 Expected string - got object.');
validate_ok {
sym => 'a',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/jv-allof.t
new/JSON-Validator-3.24/t/jv-allof.t
--- old/JSON-Validator-3.23/t/jv-allof.t 2020-02-18 08:49:52.000000000
+0100
+++ new/JSON-Validator-3.24/t/jv-allof.t 2020-03-03 07:36:29.000000000
+0100
@@ -39,4 +39,31 @@
E('/', '/oneOf/1 String is too long: 10/4.'),
E('/', '/oneOf/1 String does not match ^[a-z]+$.');
+validate_ok 'hello', {type => ['integer', 'boolean']},
+ E('/', 'Expected integer/boolean - got string.');
+
+validate_ok 'hello', {allOf => [{type => ['integer', 'boolean']}]},
+ E('/', '/allOf/0 Expected integer/boolean - got string.');
+
+validate_ok 'hello',
+ {
+ allOf => [
+ {allOf => [{type => 'boolean'}, {type => 'string', maxLength => 2}]},
+ {type => 'integer'},
+ ],
+ },
+ E('/', '/allOf/0/allOf/0 Expected boolean - got string.'),
+ E('/', '/allOf/0/allOf/1 String is too long: 5/2.'),
+ E('/', '/allOf/1 Expected integer - got string.');
+
+validate_ok {foo => 'not an arrayref'},
+ {
+ allOf => [
+ {type => 'object', properties => {foo => {type => 'array'}}},
+ {type => 'boolean'},
+ ]
+ },
+ E('/foo', '/allOf/0 Expected array - got string.'),
+ E('/', '/allOf/1 Expected boolean - got object.');
+
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/jv-anyof.t
new/JSON-Validator-3.24/t/jv-anyof.t
--- old/JSON-Validator-3.23/t/jv-anyof.t 2018-12-15 05:26:03.000000000
+0100
+++ new/JSON-Validator-3.24/t/jv-anyof.t 2020-03-03 07:36:29.000000000
+0100
@@ -6,10 +6,14 @@
[{type => "string", maxLength => 5}, {type => "number", minimum => 0}]
};
-validate_ok 'short', $schema;
-validate_ok 'too long', $schema, E('/', '/anyOf/0 String is too long: 8/5.');
-validate_ok 12, $schema;
-validate_ok int(-1), $schema, E('/', '/anyOf/1 -1 < minimum(0)');
+validate_ok 'short', $schema;
+validate_ok 'too long', $schema, E('/', '/anyOf/0 String is too long: 8/5.'),
+ E('/', '/anyOf/1 Expected number - got string.');
+
+validate_ok 12, $schema;
+validate_ok int(-1), $schema, E('/', '/anyOf/0 Expected string - got number.'),
+ E('/', '/anyOf/1 -1 < minimum(0)');
+
validate_ok {}, $schema, E('/', '/anyOf Expected string/number - got object.');
# anyOf with explicit integer (where _guess_data_type returns 'number')
@@ -63,4 +67,42 @@
E('/b', '/anyOf/1 Missing property.'),
);
+validate_ok 'hello', {type => ['integer', 'string'], enum => [123, 'HELLO']},
+ E('/', 'Not in enum list: 123, HELLO.');
+
+validate_ok 'hello', {anyOf => [false, {type => ['integer', 'boolean']}]},
+ E('/', '/anyOf/0 Should not match.'),
+ E('/', '/anyOf/1 Expected integer/boolean - got string.');
+
+validate_ok 'hello', {type => ['integer', 'boolean']},
+ E('/', 'Expected integer/boolean - got string.');
+
+validate_ok 'hello', {anyOf => [{type => ['integer', 'boolean']}]},
+ E('/', '/anyOf/0 Expected integer/boolean - got string.');
+
+validate_ok 'hello',
+ {
+ anyOf => [
+ {anyOf => [{type => 'boolean'}, {type => 'string', maxLength => 2}]},
+ {type => 'integer'},
+ ],
+ },
+ E('/', '/anyOf/0/anyOf/0 Expected boolean - got string.'),
+ E('/', '/anyOf/0/anyOf/1 String is too long: 5/2.'),
+ E('/', '/anyOf/1 Expected integer - got string.');
+
+validate_ok {foo => 'not an arrayref'},
+ {type => ['object', 'boolean'], properties => {foo => {type => 'array'}}},
+ E('/foo', 'Expected array - got string.');
+
+validate_ok {foo => 'not an arrayref'},
+ {
+ anyOf => [
+ {type => 'object', properties => {foo => {type => 'array'}}},
+ {type => 'boolean'},
+ ]
+ },
+ E('/foo', '/anyOf/0 Expected array - got string.'),
+ E('/', '/anyOf/1 Expected boolean - got object.');
+
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/jv-enum.t
new/JSON-Validator-3.24/t/jv-enum.t
--- old/JSON-Validator-3.23/t/jv-enum.t 2019-04-04 03:03:18.000000000 +0200
+++ new/JSON-Validator-3.24/t/jv-enum.t 2020-03-01 09:09:31.000000000 +0100
@@ -57,7 +57,16 @@
properties =>
{name => {type => ['string'], enum => [qw(n yes true false)]}},
},
- E('/name', '/anyOf Expected string - got null.'),
+ E('/name', 'Expected string - got null.'),
+);
+
+validate_ok(
+ {name => undef},
+ {
+ type => 'object',
+ required => ['name'],
+ properties => {name => {enum => [qw(n yes true false)]}},
+ },
E('/name', 'Not in enum list: n, yes, true, false.'),
);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/jv-object.t
new/JSON-Validator-3.24/t/jv-object.t
--- old/JSON-Validator-3.23/t/jv-object.t 2020-02-18 08:49:52.000000000
+0100
+++ new/JSON-Validator-3.24/t/jv-object.t 2020-03-03 07:35:36.000000000
+0100
@@ -189,4 +189,21 @@
, {additionalProperties => {'$ref' => '#/definitions/my_false_ref'}},
{patternProperties => {foo => {'$ref' => '#/definitions/my_false_ref'}}};
+$schema = {dependencies => {bar => ['foo']}};
+validate_ok {bar => 2}, $schema, E('/foo', 'Missing property. Dependee: bar.');
+
+validate_ok {FOO => 1},
+ {
+ type => 'object',
+ propertyNames => {
+ anyOf => [
+ {type => 'string', enum => ['foo', 'bar', 'baz']},
+ {type => 'string', enum => ['hello']},
+ ],
+ },
+ additionalProperties => {type => 'integer'},
+ },
+ E('/', '/propertyName/FOO /anyOf/0 Not in enum list: foo, bar, baz.'),
+ E('/', '/propertyName/FOO /anyOf/1 Not in enum list: hello.');
+
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/jv-oneof.t
new/JSON-Validator-3.24/t/jv-oneof.t
--- old/JSON-Validator-3.23/t/jv-oneof.t 2020-02-07 03:10:28.000000000
+0100
+++ new/JSON-Validator-3.24/t/jv-oneof.t 2020-03-03 07:36:29.000000000
+0100
@@ -23,20 +23,73 @@
validate_ok 13, $schema, E('/', '/oneOf Expected object/string - got number.');
$schema = {oneOf => [{type => 'object'}, {type => 'number', multipleOf => 3}]};
-validate_ok 13, $schema, E('/', '/oneOf/1 Not multiple of 3.');
+validate_ok 13, $schema, E('/', '/oneOf/0 Expected object - got number.'),
+ E('/', '/oneOf/1 Not multiple of 3.');
# Alternative oneOf
-# http://json-schema.org/latest/json-schema-validation.html#anchor79
+# https://json-schema.org/draft-07/json-schema-validation.html#rfc.section.7
$schema = {
type => 'object',
properties => {x => {type => ['string', 'null'], format => 'date-time'}}
};
-validate_ok {x => 'foo'}, $schema,
- E('/x', '/anyOf/0 Does not match date-time format.');
+validate_ok {x => 'foo'}, $schema, E('/x', 'Does not match date-time format.'),
+ E('/x', 'Not null.');
+
validate_ok {x => '2015-04-21T20:30:43.000Z'}, $schema;
-validate_ok {x => undef}, $schema;
+validate_ok {x => undef}, $schema;
validate_ok 1, {oneOf => [{minimum => 1}, {minimum => 2}, {maximum => 3}]},
E('/', 'oneOf rules 0, 2 match.');
+validate_ok 'hello', {oneOf => [true, false]};
+
+validate_ok 'hello', {oneOf => [true, true]},
+ E('/', 'All of the oneOf rules match.');
+
+validate_ok 'hello', {oneOf => [false, false]},
+ E('/', '/oneOf/0 Should not match.'), E('/', '/oneOf/1 Should not match.');
+
+validate_ok 'hello', {oneOf => [true, {type => ['string', 'boolean']}]},
+ E('/', 'All of the oneOf rules match.');
+
+validate_ok 'hello', {type => ['integer', 'boolean']},
+ E('/', 'Expected integer/boolean - got string.');
+
+validate_ok 'hello',
+ {oneOf => [false, {type => ['integer', 'string'], enum => [123, 'HELLO']}]},
+ E('/', '/oneOf/0 Should not match.'),
+ E('/', '/oneOf/1 Not in enum list: 123, HELLO.');
+
+validate_ok 'hello', {oneOf => [false, {type => ['integer', 'boolean']}]},
+ E('/', '/oneOf/0 Should not match.'),
+ E('/', '/oneOf/1 Expected integer/boolean - got string.');
+
+validate_ok 'hello', {oneOf => [false, {type => 'integer'}]},
+ E('/', '/oneOf/0 Should not match.'),
+ E('/', '/oneOf/1 Expected integer - got string.');
+
+validate_ok 'hello', {oneOf => [{type => ['integer', 'boolean']}]},
+ E('/', '/oneOf/0 Expected integer/boolean - got string.');
+
+validate_ok 'hello',
+ {
+ oneOf => [
+ {oneOf => [{type => 'boolean'}, {type => 'string', maxLength => 2}]},
+ {type => 'integer'},
+ ],
+ },
+ E('/', '/oneOf/0/oneOf/0 Expected boolean - got string.'),
+ E('/', '/oneOf/0/oneOf/1 String is too long: 5/2.'),
+ E('/', '/oneOf/1 Expected integer - got string.');
+
+validate_ok {foo => 'not an arrayref'},
+ {
+ oneOf => [
+ {type => 'object', properties => {foo => {type => 'array'}}},
+ {type => 'boolean'},
+ ]
+ },
+ E('/foo', '/oneOf/0 Expected array - got string.'),
+ E('/', '/oneOf/1 Expected boolean - got object.');
+
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/load-from-app.t
new/JSON-Validator-3.24/t/load-from-app.t
--- old/JSON-Validator-3.23/t/load-from-app.t 1970-01-01 01:00:00.000000000
+0100
+++ new/JSON-Validator-3.24/t/load-from-app.t 2020-03-01 09:09:31.000000000
+0100
@@ -0,0 +1,21 @@
+use Mojo::Base -strict;
+use JSON::Validator;
+use Mojolicious;
+use Test::More;
+
+my $jv = JSON::Validator->new;
+$jv->ua->server->app(Mojolicious->new);
+$jv->ua->server->app->routes->get(
+ '/spec' => sub {
+ shift->render(json => {'$ref' => 'http://swagger.io/v2/schema.json'});
+ }
+);
+
+# Some CPAN testers says: [JSON::Validator] GET http://127.0.0.1:61594/api ==
Service Unavailable at JSON/Validator.pm
+eval { $jv->schema('/spec') };
+plan skip_all => $@ if $@ =~ /\sGET\s/i;
+
+is $@, '', 'loaded schema from app';
+is $jv->get('/properties/swagger/enum/0'), '2.0', 'loaded schema structure';
+
+done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/util-checksum-yaml-xs.t
new/JSON-Validator-3.24/t/util-checksum-yaml-xs.t
--- old/JSON-Validator-3.23/t/util-checksum-yaml-xs.t 1970-01-01
01:00:00.000000000 +0100
+++ new/JSON-Validator-3.24/t/util-checksum-yaml-xs.t 2020-03-03
07:41:40.000000000 +0100
@@ -0,0 +1,36 @@
+BEGIN {
+ unshift @INC, sub {
+ my $file = $_[1];
+ die "Skipping $file in this test" if $file =~ m!Sereal\W+Encoder\.pm$!;
+ };
+}
+
+use Mojo::Util 'md5_sum';
+use JSON::Validator;
+use JSON::Validator::Util qw(data_checksum);
+use Test::More;
+
+my $d_hash = {foo => {}, bar => {}};
+my $d_hash2 = {bar => {}, foo => {}};
+my $d_undef = {foo => undef};
+my $d_obj = {foo => JSON::Validator::Error->new};
+my $d_array = ['foo', 'bar'];
+my $d_array2 = ['bar', 'foo'];
+
+use_ok 'YAML::XS';
+ok !$INC{'Sereal/Encoder.pm'}, 'Sereal::Encoder was not loaded';
+
+isnt data_checksum($d_array), data_checksum($d_array2), 'data_checksum array';
+is data_checksum($d_hash), data_checksum($d_hash2),
+ 'data_checksum hash field order';
+isnt data_checksum($d_hash), data_checksum($d_undef),
+ 'data_checksum hash not undef';
+isnt data_checksum($d_hash), data_checksum($d_obj),
+ 'data_checksum hash not object';
+isnt data_checksum($d_obj), data_checksum($d_undef),
+ 'data_checksum object not undef';
+isnt data_checksum(3.14), md5_sum(3.15), 'data_checksum numeric';
+is data_checksum(3.14), data_checksum('3.14'),
+ 'data_checksum numeric like string';
+
+done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.23/t/util.t
new/JSON-Validator-3.24/t/util.t
--- old/JSON-Validator-3.23/t/util.t 2020-02-19 01:37:18.000000000 +0100
+++ new/JSON-Validator-3.24/t/util.t 2020-03-03 07:28:36.000000000 +0100
@@ -1,8 +1,9 @@
use Mojo::Base -strict;
use Mojo::JSON 'false';
+use Mojo::Util 'md5_sum';
use JSON::Validator;
use JSON::Validator::Util
- qw(E data_type schema_type prefix_errors is_type json_pointer);
+ qw(E data_checksum data_type schema_type prefix_errors is_type json_pointer);
use Test::More;
my $e = E '/path/x', 'some error';
@@ -52,4 +53,29 @@
is schema_type({const => 42}), 'const', 'schema_type const';
is schema_type({cannot => 'guess'}), '', 'schema_type no idea';
+subtest 'data_checksum with Sereal::Encoder' => sub {
+ plan skip_all => 'Sereal::Encoder not installed'
+ unless eval 'use Sereal::Encoder;1';
+
+ my $d_hash = {foo => {}, bar => {}};
+ my $d_hash2 = {bar => {}, foo => {}};
+ my $d_undef = {foo => undef};
+ my $d_obj = {foo => JSON::Validator::Error->new};
+ my $d_array = ['foo', 'bar'];
+ my $d_array2 = ['bar', 'foo'];
+
+ isnt data_checksum($d_array), data_checksum($d_array2), 'data_checksum
array';
+ is data_checksum($d_hash), data_checksum($d_hash2),
+ 'data_checksum hash field order';
+ isnt data_checksum($d_hash), data_checksum($d_undef),
+ 'data_checksum hash not undef';
+ isnt data_checksum($d_hash), data_checksum($d_obj),
+ 'data_checksum hash not object';
+ isnt data_checksum($d_obj), data_checksum($d_undef),
+ 'data_checksum object not undef';
+ isnt data_checksum(3.14), md5_sum(3.15), 'data_checksum numeric';
+ is data_checksum(3.14), data_checksum('3.14'),
+ 'data_checksum numeric like string';
+};
+
done_testing;