Hello community, here is the log from the commit of package perl-JSON-Validator for openSUSE:Factory checked in at 2019-10-30 14:47:45 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-JSON-Validator (Old) and /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.2990 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-JSON-Validator" Wed Oct 30 14:47:45 2019 rev:9 rq:743960 version:3.16 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-JSON-Validator/perl-JSON-Validator.changes 2019-09-30 16:01:43.768844493 +0200 +++ /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.2990/perl-JSON-Validator.changes 2019-10-30 14:47:47.870180960 +0100 @@ -1,0 +2,10 @@ +Tue Oct 29 09:41:31 UTC 2019 - <timueller+p...@suse.de> + +- updated to 3.16 + see /usr/share/doc/packages/perl-JSON-Validator/Changes + + 3.16 2019-10-28T13:59:47+0900 + - Add generate_definitions_path() #175 #177 + Contributor: Henrik Andersen, Jan Henning Thorsen + +------------------------------------------------------------------- Old: ---- JSON-Validator-3.15.tar.gz New: ---- JSON-Validator-3.16.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-JSON-Validator.spec ++++++ --- /var/tmp/diff_new_pack.zS2Wmg/_old 2019-10-30 14:47:48.418181542 +0100 +++ /var/tmp/diff_new_pack.zS2Wmg/_new 2019-10-30 14:47:48.422181547 +0100 @@ -17,7 +17,7 @@ Name: perl-JSON-Validator -Version: 3.15 +Version: 3.16 Release: 0 %define cpan_name JSON-Validator Summary: Validate data against a JSON schema ++++++ JSON-Validator-3.15.tar.gz -> JSON-Validator-3.16.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.15/Changes new/JSON-Validator-3.16/Changes --- old/JSON-Validator-3.15/Changes 2019-09-27 02:28:32.000000000 +0200 +++ new/JSON-Validator-3.16/Changes 2019-10-28 05:59:47.000000000 +0100 @@ -1,5 +1,9 @@ Revision history for perl distribution JSON-Validator +3.16 2019-10-28T13:59:47+0900 + - Add generate_definitions_path() #175 #177 + Contributor: Henrik Andersen, Jan Henning Thorsen + 3.15 2019-09-27T09:28:32+0900 - Add JSON::Validator::Error->details() #133 - Reversed the checksum and nice name for generated definitions #173 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.15/META.json new/JSON-Validator-3.16/META.json --- old/JSON-Validator-3.15/META.json 2019-09-27 02:28:34.000000000 +0200 +++ new/JSON-Validator-3.16/META.json 2019-10-28 05:59:50.000000000 +0100 @@ -61,6 +61,6 @@ }, "x_IRC" : "irc://irc.freenode.net/#mojo" }, - "version" : "3.15", + "version" : "3.16", "x_serialization_backend" : "JSON::PP version 4.02" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.15/META.yml new/JSON-Validator-3.16/META.yml --- old/JSON-Validator-3.15/META.yml 2019-09-27 02:28:33.000000000 +0200 +++ new/JSON-Validator-3.16/META.yml 2019-10-28 05:59:49.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.15' +version: '3.16' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.15/lib/JSON/Validator.pm new/JSON-Validator-3.16/lib/JSON/Validator.pm --- old/JSON-Validator-3.15/lib/JSON/Validator.pm 2019-09-27 02:28:32.000000000 +0200 +++ new/JSON-Validator-3.16/lib/JSON/Validator.pm 2019-10-28 05:59:47.000000000 +0100 @@ -23,7 +23,7 @@ use constant RECURSION_LIMIT => $ENV{JSON_VALIDATOR_RECURSION_LIMIT} || 100; use constant SPECIFICATION_URL => 'http://json-schema.org/draft-04/schema#'; -our $VERSION = '3.15'; +our $VERSION = '3.16'; our $YAML_LOADER = eval q[use YAML::XS 0.67; YAML::XS->can('Load')]; # internal our @EXPORT_OK = qw(joi validate_json); @@ -47,6 +47,13 @@ }; has formats => sub { shift->_build_formats }; + +has generate_definitions_path => sub { + my $self = shift; + Scalar::Util::weaken($self); + return sub { [$self->{definitions_key} || 'definitions'] }; +}; + has version => 4; has ua => sub { @@ -91,14 +98,15 @@ if !$args->{schema} and $tied->fqn =~ m!^\Q$self->{root_schema_url}\E\#!; - my $p = $self->_definitions_path($bundle, $tied); - unless ($self->{bundled_refs}{$tied->fqn}) { - $self->{bundled_refs}{$tied->fqn} = $tied; - push @topics, [$schema->{$p->[0]} || {}, $bundle->{$p->[0]} ||= {}]; - push @topics, [$tied->schema, $bundle->{$p->[0]}{$p->[1]} ||= {}]; + my $path = $self->_definitions_path($bundle, $tied); + unless ($self->{bundled_refs}{$tied->fqn}++) { + push @topics, + [_node($schema, $path, 1, 0) || {}, _node($bundle, $path, 1, 1)]; + push @topics, [$tied->schema, _node($bundle, $path, 0, 1)]; } - tie my %ref, 'JSON::Validator::Ref', $tied->schema, "#/$p->[0]/$p->[1]"; + $path = join '/', '#', @$path; + tie my %ref, 'JSON::Validator::Ref', $tied->schema, $path; return \%ref; }; } @@ -229,17 +237,20 @@ sub _definitions_path { my ($self, $bundle, $ref) = @_; - my $definitions_key = $self->{definitions_key} || 'definitions'; + my $path = $self->generate_definitions_path->($ref); # No need to rewrite, if it already has a nice name - if ($ref->fqn =~ m!#/$definitions_key/([^/]+)$!) { + my $node = _node($bundle, $path, 2, 0); + my $prefix = join '/', @$path; + if ($ref->fqn =~ m!#/$prefix/([^/]+)$!) { my $key = $1; if ( $self->{bundled_refs}{$ref->fqn} - or !$bundle->{$definitions_key}{$key} - or D($ref->schema) eq D($bundle->{$definitions_key}{$key})) + or !$node + or !$node->{$key} + or D($ref->schema) eq D($node->{$key})) { - return [$definitions_key, $key]; + return [@$path, $key]; } } @@ -253,8 +264,7 @@ # Fallback or nicer path name $key =~ s![^\w-]!_!g; - - return [$definitions_key, $key]; + return [@$path, $key]; } sub _get { @@ -399,6 +409,19 @@ return $self->_load_schema_from_text(\$tx->res->body); } +sub _node { + my ($node, $path, $offset, $create) = @_; + + my $n = 0; + while ($path->[$n]) { + $node->{$path->[$n]} ||= {} if $create; + return undef unless $node = $node->{$path->[$n]}; + last if (++$n) + $offset >= @$path; + } + + return $node; +} + sub _ref_to_schema { my ($self, $schema) = @_; @@ -1297,6 +1320,18 @@ See L<JSON::Validator::Formats> for a list of supported formats. +=head2 generate_definitions_path + + my $cb = $self->generate_definitions_path; + my $jv = $self->generate_definitions_path(sub { my $ref = shift; return ["definitions"] }); + +Holds a callback that is used by L</bundle> to figure out where to place +references. The default location is under "definitions", but this can be +changed to whatever you want. The input C<$ref> variable passed on is a +L<JSON::Validator::Ref> object. + +This attribute is EXPERIMENTAL and might change without warning. + =head2 ua my $ua = $jv->ua; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.15/t/bundle.t new/JSON-Validator-3.16/t/bundle.t --- old/JSON-Validator-3.15/t/bundle.t 2019-09-27 02:18:23.000000000 +0200 +++ new/JSON-Validator-3.16/t/bundle.t 2019-10-28 05:54:12.000000000 +0100 @@ -107,12 +107,24 @@ my $ref_name_prefix = $workdir; $ref_name_prefix =~ s![^\w-]!_!g; $jv->schema(path $workdir, 'spec', 'bundle-no-leaking-filename.json'); -$bundled = $jv->bundle({ref_key => 'xyz'}); -my @definitions = keys %{$bundled->{xyz}}; -ok @definitions, 'definitions are present'; -is_deeply [grep { 0 == index $_, $ref_name_prefix } @definitions], [], +$jv->generate_definitions_path( + sub { [shift->fqn =~ /with-deep-mixed/ ? 'deep' : 'other'] }); +$bundled = $jv->bundle; +my @deep = keys %{$bundled->{deep}}; +my @other = keys %{$bundled->{other}}; +is @deep, 2, 'deep present' or diag join ', ', @deep; +is @other, 3, 'other present' or diag join ', ', @other; +is_deeply [grep { 0 == index $_, $ref_name_prefix } @deep, @other], [], 'no leaking of path'; +$jv->generate_definitions_path( + sub { shift->fqn =~ /with-deep-mixed/ ? ['even', 'deeper'] : ['other'] }); +$bundled = $jv->bundle; +@deep = keys %{$bundled->{even}{deeper}}; +@other = keys %{$bundled->{other}}; +is @deep, 2, 'even deeper present' or diag join ', ', @deep; +is @other, 3, 'other present' or diag join ', ', @other; + done_testing; __DATA__