Hello community,
here is the log from the commit of package perl-JSON-Validator for
openSUSE:Factory checked in at 2020-02-18 10:42:23
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-JSON-Validator (Old)
and /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.26092 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-JSON-Validator"
Tue Feb 18 10:42:23 2020 rev:15 rq:774958 version:3.22
Changes:
--------
--- /work/SRC/openSUSE:Factory/perl-JSON-Validator/perl-JSON-Validator.changes
2020-02-14 16:41:26.659721830 +0100
+++
/work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.26092/perl-JSON-Validator.changes
2020-02-18 10:42:41.293223967 +0100
@@ -1,0 +2,11 @@
+Sat Feb 15 03:10:34 UTC 2020 - <[email protected]>
+
+- updated to 3.22
+ see /usr/share/doc/packages/perl-JSON-Validator/Changes
+
+ 3.22 2020-02-15T08:35:29+0900
+ - Add support for "dependencies" keyword #192 #197
+ - Add support for anyOf/allOf/oneOf at the same time #196 #197
+ - Allow if/then/else to be in any sort of schema #190 #197
+
+-------------------------------------------------------------------
Old:
----
JSON-Validator-3.21.tar.gz
New:
----
JSON-Validator-3.22.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-JSON-Validator.spec ++++++
--- /var/tmp/diff_new_pack.ZEabnZ/_old 2020-02-18 10:42:42.549226530 +0100
+++ /var/tmp/diff_new_pack.ZEabnZ/_new 2020-02-18 10:42:42.553226538 +0100
@@ -17,7 +17,7 @@
Name: perl-JSON-Validator
-Version: 3.21
+Version: 3.22
Release: 0
%define cpan_name JSON-Validator
Summary: Validate data against a JSON schema
++++++ JSON-Validator-3.21.tar.gz -> JSON-Validator-3.22.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/Changes
new/JSON-Validator-3.22/Changes
--- old/JSON-Validator-3.21/Changes 2020-02-14 02:14:14.000000000 +0100
+++ new/JSON-Validator-3.22/Changes 2020-02-15 00:35:29.000000000 +0100
@@ -1,5 +1,10 @@
Revision history for perl distribution JSON-Validator
+3.22 2020-02-15T08:35:29+0900
+ - Add support for "dependencies" keyword #192 #197
+ - Add support for anyOf/allOf/oneOf at the same time #196 #197
+ - Allow if/then/else to be in any sort of schema #190 #197
+
3.21 2020-02-14T10:14:14+0900
- Fix data_section() without a class #193
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/MANIFEST
new/JSON-Validator-3.22/MANIFEST
--- old/JSON-Validator-3.21/MANIFEST 2020-02-14 02:14:15.000000000 +0100
+++ new/JSON-Validator-3.22/MANIFEST 2020-02-15 00:35:30.000000000 +0100
@@ -81,6 +81,7 @@
t/jv-const.t
t/jv-enum.t
t/jv-formats.t
+t/jv-if-then-else.t
t/jv-integer.t
t/jv-not.t
t/jv-number.t
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/META.json
new/JSON-Validator-3.22/META.json
--- old/JSON-Validator-3.21/META.json 2020-02-14 02:14:15.000000000 +0100
+++ new/JSON-Validator-3.22/META.json 2020-02-15 00:35:30.000000000 +0100
@@ -61,6 +61,6 @@
},
"x_IRC" : "irc://irc.freenode.net/#mojo"
},
- "version" : "3.21",
+ "version" : "3.22",
"x_serialization_backend" : "JSON::PP version 4.02"
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/META.yml
new/JSON-Validator-3.22/META.yml
--- old/JSON-Validator-3.21/META.yml 2020-02-14 02:14:15.000000000 +0100
+++ new/JSON-Validator-3.22/META.yml 2020-02-15 00:35:30.000000000 +0100
@@ -30,5 +30,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.21'
+version: '3.22'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/lib/JSON/Validator/Error.pm
new/JSON-Validator-3.22/lib/JSON/Validator/Error.pm
--- old/JSON-Validator-3.21/lib/JSON/Validator/Error.pm 2020-02-10
01:52:05.000000000 +0100
+++ new/JSON-Validator-3.22/lib/JSON/Validator/Error.pm 2020-02-15
00:33:29.000000000 +0100
@@ -35,6 +35,7 @@
maxProperties => 'Too many properties: %3/%4.',
minProperties => 'Not enough properties: %3/%4.',
required => 'Missing property.',
+ dependencies => 'Missing property. Dependee: %3.',
},
oneOf => {
all_rules_match => 'All of the oneOf rules match.',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/lib/JSON/Validator/Util.pm
new/JSON-Validator-3.22/lib/JSON/Validator/Util.pm
--- old/JSON-Validator-3.21/lib/JSON/Validator/Util.pm 2020-02-14
02:12:56.000000000 +0100
+++ new/JSON-Validator-3.22/lib/JSON/Validator/Util.pm 2020-02-15
00:33:29.000000000 +0100
@@ -123,7 +123,6 @@
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]->{if};
return _guessed_right(object => $_[1])
if defined $_[0]->{maxProperties}
or defined $_[0]->{minProperties};
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/lib/JSON/Validator.pm
new/JSON-Validator-3.22/lib/JSON/Validator.pm
--- old/JSON-Validator-3.21/lib/JSON/Validator.pm 2020-02-14
02:14:14.000000000 +0100
+++ new/JSON-Validator-3.22/lib/JSON/Validator.pm 2020-02-15
00:35:29.000000000 +0100
@@ -23,8 +23,8 @@
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.21';
-our @EXPORT_OK = qw(joi validate_json);
+our $VERSION = '3.22';
+our @EXPORT_OK = qw(joi validate_json);
my $BUNDLED_CACHE_DIR = path(path(__FILE__)->dirname, qw(Validator cache));
my $HTTP_SCHEME_RE = qr{^https?:};
@@ -54,7 +54,7 @@
sub bundle {
my ($self, $args) = @_;
- my ($cloner, $tied);
+ my ($cloner);
my $schema
= $args->{schema} ? $self->_resolve($args->{schema}) : $self->schema->data;
@@ -64,6 +64,7 @@
$cloner = sub {
my $from = shift;
my $from_type = ref $from;
+ my $tied;
$from = $tied->schema if $from_type eq 'HASH' and $tied = tied %$from;
my $to = $from_type eq 'ARRAY' ? [] : $from_type eq 'HASH' ? {} : $from;
push @topics, [$from, $to] if $from_type;
@@ -75,7 +76,7 @@
my $from = shift;
my $from_type = ref $from;
- $tied = $from_type eq 'HASH' && tied %$from;
+ my $tied = $from_type eq 'HASH' && tied %$from;
unless ($tied) {
my $to = $from_type eq 'ARRAY' ? [] : $from_type eq 'HASH' ? {} :
$from;
push @topics, [$from, $to] if $from_type;
@@ -293,7 +294,6 @@
sub _load_schema_from_text {
my ($self, $text) = @_;
- my $visit;
# JSON
return Mojo::JSON::decode_json($$text) if $$text =~ /^\s*\{/s;
@@ -311,7 +311,6 @@
my ($self, $url) = @_;
my $cache_path = $self->cache_paths->[0];
my $cache_file = Mojo::Util::md5_sum("$url");
- my ($err, $tx);
for (@{$self->cache_paths}) {
my $path = path $_, $cache_file;
@@ -320,8 +319,8 @@
return $self->_load_schema_from_text(\$path->slurp);
}
- $tx = $self->ua->get($url);
- $err = $tx->error && $tx->error->{message};
+ my $tx = $self->ua->get($url);
+ my $err = $tx->error && $tx->error->{message};
confess "GET $url == $err" if DEBUG and $err;
die "[JSON::Validator] GET $url == $err" if $err;
@@ -378,7 +377,7 @@
sub _resolve {
my ($self, $schema) = @_;
my $id_key = $self->_id_key;
- my ($id, $resolved, @refs);
+ my ($id, $resolved);
local $self->{level} = $self->{level} || 0;
delete $_[0]->{schemas}{''} unless $self->{level};
@@ -416,7 +415,7 @@
$self->{level}++;
$self->_register_schema($schema, $id);
- my %seen;
+ my (%seen, @refs);
my @topics
= ([$schema, is_type($id, 'Mojo::File') ? $id : Mojo::URL->new($id)]);
while (@topics) {
@@ -497,13 +496,12 @@
sub _validate {
my ($self, $data, $path, $schema) = @_;
- my ($seen_addr, $to_json, $type);
$schema = $self->_ref_to_schema($schema)
if ref $schema eq 'HASH' and $schema->{'$ref'};
return $schema ? () : E $path, [not => 'not'] if is_type $schema, 'BOOL';
- $seen_addr = join ':', refaddr($schema),
+ my $seen_addr = join ':', refaddr($schema),
(ref $data ? refaddr $data : ++$self->{seen}{scalar});
# Avoid recursion
@@ -512,10 +510,10 @@
}
$self->{seen}{$seen_addr} = \my @errors;
- $to_json
+ my $to_json
= (blessed $data and $data->can('TO_JSON')) ? \$data->TO_JSON : undef;
$data = $$to_json if $to_json;
- $type = $schema->{type} || schema_type $schema, $data;
+ my $type = $schema->{type} || schema_type $schema, $data;
# Test base schema before allOf, anyOf or oneOf
if (ref $type eq 'ARRAY') {
@@ -551,15 +549,25 @@
push @errors,
$self->_validate_all_of($to_json ? $$to_json : $_[1], $path, $rules);
}
- elsif ($rules = $schema->{anyOf}) {
+
+ if (my $rules = $schema->{anyOf}) {
push @errors,
$self->_validate_any_of($to_json ? $$to_json : $_[1], $path, $rules);
}
- elsif ($rules = $schema->{oneOf}) {
+
+ if (my $rules = $schema->{oneOf}) {
push @errors,
$self->_validate_one_of($to_json ? $$to_json : $_[1], $path, $rules);
}
+ if ($schema->{if}) {
+ my $rules
+ = $self->_validate($data, $path, $schema->{if})
+ ? $schema->{else}
+ : $schema->{then};
+ push @errors, $self->_validate($data, $path, $rules // {});
+ }
+
return @errors;
}
@@ -856,12 +864,6 @@
push @errors, prefix_errors propertyName => [map { ($name, $_) } @e];
}
}
- if ($schema->{if}) {
- push @errors,
- $self->_validate($data, $path, $schema->{if})
- ? $self->_validate($data, $path, $schema->{else} // {})
- : $self->_validate($data, $path, $schema->{then} // {});
- }
my %rules;
for my $k (keys %{$schema->{properties}}) {
@@ -897,7 +899,21 @@
for my $k (sort uniq @{$schema->{required} || []}) {
next if exists $data->{$k};
push @errors, E json_pointer($path, $k), [object => 'required'];
- delete $rules{$k};
+ delete $rules{$k}; # why bother?
+ }
+
+ my $dependencies = $schema->{dependencies} || {};
+ for my $k (keys %$dependencies) {
+ next if not exists $data->{$k};
+ if (ref $dependencies->{$k} eq 'ARRAY') {
+ push @errors,
+ map { E json_pointer($path, $_), [object => dependencies => $k] }
+ grep { !exists $data->{$_} } @{$dependencies->{$k}};
+ }
+ elsif (ref $dependencies->{$k} eq 'HASH') {
+ push @errors,
+ $self->_validate_type_object($data, $path,
$schema->{dependencies}{$k});
+ }
}
for my $k (sort keys %rules) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/t/jv-allof.t
new/JSON-Validator-3.22/t/jv-allof.t
--- old/JSON-Validator-3.21/t/jv-allof.t 2018-12-15 05:22:39.000000000
+0100
+++ new/JSON-Validator-3.22/t/jv-allof.t 2020-02-15 00:33:29.000000000
+0100
@@ -17,4 +17,26 @@
E('/', '/allOf/1 String is too long: 9/5.');
validate_ok 'toolong', $schema, E('/', '/allOf/1 String is too long: 7/5.');
+
+$schema = {
+ allOf =>
+ [{type => 'string', maxLength => 5}, {type => 'string', minLength => 3}],
+ anyOf => [{pattern => '^[0-9]+$'}, {pattern => '^[a-z]+$'}],
+ oneOf => [{pattern => '^[0-9]+$'}, {pattern => '^[a-z]+$', maxLength => 4}],
+};
+
+validate_ok '123', $schema;
+validate_ok 'aaaa', $schema;
+validate_ok 'aaaaa', $schema,
+ E('/', '/oneOf/0 String does not match ^[0-9]+$.'),
+ E('/', '/oneOf/1 String is too long: 5/4.');
+
+validate_ok 'he110th3re', $schema,
+ E('/', '/allOf/0 String is too long: 10/5.'),
+ E('/', '/anyOf/0 String does not match ^[0-9]+$.'),
+ E('/', '/anyOf/1 String does not match ^[a-z]+$.'),
+ E('/', '/oneOf/0 String does not match ^[0-9]+$.'),
+ E('/', '/oneOf/1 String is too long: 10/4.'),
+ E('/', '/oneOf/1 String does not match ^[a-z]+$.');
+
done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/t/jv-if-then-else.t
new/JSON-Validator-3.22/t/jv-if-then-else.t
--- old/JSON-Validator-3.21/t/jv-if-then-else.t 1970-01-01 01:00:00.000000000
+0100
+++ new/JSON-Validator-3.22/t/jv-if-then-else.t 2020-02-15 00:33:29.000000000
+0100
@@ -0,0 +1,30 @@
+use lib '.';
+use t::Helper;
+
+my $schema;
+
+$schema = {
+ if => {properties => {ifx => {type => 'string'}}},
+ then => {properties => {ifx => {maxLength => 3}}},
+ else => {properties => {ifx => {type => 'number'}}},
+};
+
+validate_ok {ifx => 'foo'}, $schema;
+validate_ok {ifx => 'foobar'}, $schema, E('/ifx', 'String is too long: 6/3.');
+validate_ok {ifx => 42}, $schema;
+validate_ok {ifx => []}, $schema, E('/ifx', 'Expected number - got array.');
+
+$schema = {
+ type => 'array',
+ if => {maxItems => 5},
+ then => {items => {pattern => '^[0-9]$'}},
+ else => {items => {pattern => '^[a-z]$'}},
+};
+
+validate_ok [qw(2 4 7)], $schema;
+validate_ok [qw(a 1)], $schema, E('/0', 'String does not match ^[0-9]$.');
+validate_ok [qw(6 q a b 8 z)], $schema,
+ E('/0', 'String does not match ^[a-z]$.'),
+ E('/4', 'String does not match ^[a-z]$.');
+
+done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/JSON-Validator-3.21/t/jv-object.t
new/JSON-Validator-3.22/t/jv-object.t
--- old/JSON-Validator-3.21/t/jv-object.t 2020-02-12 01:17:35.000000000
+0100
+++ new/JSON-Validator-3.22/t/jv-object.t 2020-02-15 00:33:29.000000000
+0100
@@ -82,7 +82,6 @@
}
{
- local $TODO = 'Add support for dependencies';
$schema = {
type => 'object',
properties => {
@@ -94,8 +93,28 @@
dependencies => {credit_card => ['billing_address']}
};
+ validate_ok {name => 'John Doe'}, $schema;
+ validate_ok {name => 'John Doe', billing_address => '123 Main St'}, $schema;
validate_ok {name => 'John Doe', credit_card => 5555555555555555}, $schema,
- E('/credit_card', 'Missing billing_address.', 'credit_card');
+ E('/billing_address', 'Missing property. Dependee: credit_card.');
+
+ $schema = {
+ type => 'object',
+ properties =>
+ {name => {type => 'string'}, credit_card => {type => 'number'}},
+ required => ['name'],
+ dependencies => {
+ credit_card => {
+ properties => {billing_address => {type => 'string'}},
+ required => ['billing_address'],
+ },
+ },
+ };
+
+ validate_ok {name => 'John Doe'}, $schema;
+ validate_ok {name => 'John Doe', billing_address => '123 Main St'}, $schema;
+ validate_ok {name => 'John Doe', credit_card => 5555555555555555}, $schema,
+ E('/billing_address', 'Missing property.');
}
{
@@ -113,19 +132,6 @@
validate_ok {name => 'John', surname => 'Doe'}, $schema;
}
-{
- my $schema = {
- if => {properties => {ifx => {type => 'string'}}},
- then => {properties => {ifx => {maxLength => 3}}},
- else => {properties => {ifx => {type => 'number'}}},
- };
-
- validate_ok {ifx => 'foo'}, $schema;
- validate_ok {ifx => 'foobar'}, $schema, E('/ifx', 'String is too long:
6/3.');
- validate_ok {ifx => 42}, $schema;
- validate_ok {ifx => []}, $schema, E('/ifx', 'Expected number - got array.');
-}
-
sub TO_JSON { return {age => shift->{age}} }
my $obj = bless {age => 'not_a_string'}, 'main';
validate_ok $obj, {properties => {age => {type => 'integer'}}},