Hello community, here is the log from the commit of package perl-JSON-Validator for openSUSE:Factory checked in at 2019-08-13 13:19:11 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-JSON-Validator (Old) and /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.9556 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-JSON-Validator" Tue Aug 13 13:19:11 2019 rev:7 rq:722200 version:3.14 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-JSON-Validator/perl-JSON-Validator.changes 2019-05-13 14:51:40.850961162 +0200 +++ /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.9556/perl-JSON-Validator.changes 2019-08-13 13:20:17.505433742 +0200 @@ -1,0 +2,25 @@ +Sat Aug 10 05:12:29 UTC 2019 - Stephan Kulow <co...@suse.com> + +- updated to 3.14 + see /usr/share/doc/packages/perl-JSON-Validator/Changes + + 3.14 2019-08-09T23:52:24+0200 + - Fix failing tests #169 + +------------------------------------------------------------------- +Fri Aug 9 05:10:48 UTC 2019 - Stephan Kulow <co...@suse.com> + +- updated to 3.13 + see /usr/share/doc/packages/perl-JSON-Validator/Changes + + 3.13 2019-08-08T16:27:29+0200 + - Fix extend() should not mutate the source objects #167 + + 3.12 2019-08-08T12:02:14+0200 + - Fix bug: Joi->extend(...) will also merge "required" #166 + - Fix deprecation warning from $joi->validate #165 + Contributor: Mattias Päivärinta + - Fix loading Time::Local in the correct module #163 + Contributor: Bernhard Graf + +------------------------------------------------------------------- Old: ---- JSON-Validator-3.11.tar.gz New: ---- JSON-Validator-3.14.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-JSON-Validator.spec ++++++ --- /var/tmp/diff_new_pack.bz2MYj/_old 2019-08-13 13:20:19.157433307 +0200 +++ /var/tmp/diff_new_pack.bz2MYj/_new 2019-08-13 13:20:19.189433299 +0200 @@ -17,7 +17,7 @@ Name: perl-JSON-Validator -Version: 3.11 +Version: 3.14 Release: 0 %define cpan_name JSON-Validator Summary: Validate data against a JSON schema @@ -31,6 +31,7 @@ BuildRequires: perl BuildRequires: perl-macros BuildRequires: perl(Mojolicious) >= 7.28 +BuildRequires: perl(Test::Deep) BuildRequires: perl(Test::More) >= 1.30 Requires: perl(Mojolicious) >= 7.28 %{perl_requires} ++++++ JSON-Validator-3.11.tar.gz -> JSON-Validator-3.14.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/Changes new/JSON-Validator-3.14/Changes --- old/JSON-Validator-3.11/Changes 2019-05-07 16:53:16.000000000 +0200 +++ new/JSON-Validator-3.14/Changes 2019-08-09 23:52:24.000000000 +0200 @@ -1,5 +1,18 @@ Revision history for perl distribution JSON-Validator +3.14 2019-08-09T23:52:24+0200 + - Fix failing tests #169 + +3.13 2019-08-08T16:27:29+0200 + - Fix extend() should not mutate the source objects #167 + +3.12 2019-08-08T12:02:14+0200 + - Fix bug: Joi->extend(...) will also merge "required" #166 + - Fix deprecation warning from $joi->validate #165 + Contributor: Mattias Päivärinta + - Fix loading Time::Local in the correct module #163 + Contributor: Bernhard Graf + 3.11 2019-05-07T21:53:16+0700 - Bundle https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json #157 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/MANIFEST new/JSON-Validator-3.14/MANIFEST --- old/JSON-Validator-3.11/MANIFEST 2019-05-07 16:53:17.000000000 +0200 +++ new/JSON-Validator-3.14/MANIFEST 2019-08-09 23:52:25.000000000 +0200 @@ -59,6 +59,7 @@ t/draft4-tests/required.json t/draft4-tests/type.json t/draft4-tests/uniqueItems.json +t/formats.t t/get.t t/Helper.pm t/id-keyword-draft4.t @@ -90,6 +91,7 @@ t/load-http.t t/load-json.t t/load-yaml.t +t/more-bundle.t t/random-errors.t t/relative-ref.t t/remotes/folder/folderInteger.json @@ -99,6 +101,8 @@ t/spec/bundle-no-leaking-filename.json t/spec/bundlecheck.json t/spec/missing-ref.json +t/spec/more-bundle.yaml +t/spec/more-bundle2.yaml t/spec/person.json t/spec/petstore.json 't/spec/space bundle.json' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/META.json new/JSON-Validator-3.14/META.json --- old/JSON-Validator-3.11/META.json 2019-05-07 16:53:17.000000000 +0200 +++ new/JSON-Validator-3.14/META.json 2019-08-09 23:52:25.000000000 +0200 @@ -40,6 +40,7 @@ }, "test" : { "requires" : { + "Test::Deep" : "0", "Test::More" : "1.30" } } @@ -60,6 +61,6 @@ }, "x_IRC" : "irc://irc.freenode.net/#mojo" }, - "version" : "3.11", + "version" : "3.14", "x_serialization_backend" : "JSON::PP version 2.97001" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/META.yml new/JSON-Validator-3.14/META.yml --- old/JSON-Validator-3.11/META.yml 2019-05-07 16:53:17.000000000 +0200 +++ new/JSON-Validator-3.14/META.yml 2019-08-09 23:52:25.000000000 +0200 @@ -4,6 +4,7 @@ - 'Jan Henning Thorsen <jhthor...@cpan.org>' build_requires: ExtUtils::MakeMaker: '0' + Test::Deep: '0' Test::More: '1.30' configure_requires: ExtUtils::MakeMaker: '0' @@ -29,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.11' +version: '3.14' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/Makefile.PL new/JSON-Validator-3.14/Makefile.PL --- old/JSON-Validator-3.11/Makefile.PL 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.14/Makefile.PL 2019-06-27 08:48:01.000000000 +0200 @@ -31,7 +31,10 @@ }, }, PREREQ_PM => {'Mojolicious' => '7.28'}, - TEST_REQUIRES => {'Test::More' => '1.30'}, + TEST_REQUIRES => { + 'Test::More' => '1.30', + 'Test::Deep' => '0', + }, test => {TESTS => (-e 'META.yml' ? 't/*.t' : 't/*.t xt/*.t')}, ); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/lib/JSON/Validator/Formats.pm new/JSON-Validator-3.14/lib/JSON/Validator/Formats.pm --- old/JSON-Validator-3.11/lib/JSON/Validator/Formats.pm 2019-01-21 22:55:39.000000000 +0100 +++ new/JSON-Validator-3.14/lib/JSON/Validator/Formats.pm 2019-06-27 08:48:01.000000000 +0200 @@ -1,6 +1,8 @@ package JSON::Validator::Formats; use Mojo::Base -strict; +require Time::Local; + use constant DATA_VALIDATE_DOMAIN => eval 'require Data::Validate::Domain;1'; use constant DATA_VALIDATE_IP => eval 'require Data::Validate::IP;1'; use constant NET_IDN_ENCODE => eval 'require Net::IDN::Encode;1'; @@ -193,7 +195,7 @@ =head1 NAME -JSON::Validator::Formats - Functions for valiating JSON schema formats +JSON::Validator::Formats - Functions for validating JSON schema formats =head1 SYNOPSIS @@ -217,6 +219,7 @@ L<JSON::Validator::Formats> is a module with utility functions used by L<JSON::Validator/formats> to match JSON Schema formats. +All functions return C<undef> for success or an error message for failure. =head1 FUNCTIONS diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/lib/JSON/Validator/Joi.pm new/JSON-Validator-3.14/lib/JSON/Validator/Joi.pm --- old/JSON-Validator-3.11/lib/JSON/Validator/Joi.pm 2019-04-06 10:12:25.000000000 +0200 +++ new/JSON-Validator-3.14/lib/JSON/Validator/Joi.pm 2019-08-09 23:51:59.000000000 +0200 @@ -3,13 +3,14 @@ use Mojo::JSON qw(false true); use Mojo::Util; +use Storable 'dclone'; # Avoid "Subroutine redefined" warnings require JSON::Validator; -has enum => sub { +[] }; +has enum => sub { +[] }; has [qw(format max min multiple_of regex)] => undef; -has type => 'object'; +has type => 'object'; for my $attr (qw(required strict unique)) { Mojo::Util::monkey_patch(__PACKAGE__, @@ -40,11 +41,22 @@ die "Cannot extend joi '@{[$self->type]}' by '@{[$by->type]}'" unless $self->type eq $by->type; - my $clone = shift->new(%$self, %$by); + my $clone = shift->new(dclone($self)); - if ($self->type eq 'object') { - $clone->{properties}{$_} ||= $self->{properties}{$_} - for keys %{$self->{properties} || {}}; + for my $key (keys %$by) { + my $ref = ref $by->{$key}; + $clone->{$key} = $by->{$key} unless $ref eq 'ARRAY' or $ref eq 'HASH'; + } + + if ($self->type eq 'array') { + $clone->{items} = dclone($by->{items}) if $by->{items}; + } + elsif ($self->type eq 'object') { + $clone->{required} + = [JSON::Validator::_uniq(@{$clone->{required}}, @{$by->{required}})] + if ref $by->{required} eq 'ARRAY'; + $clone->{properties}{$_} = dclone($by->{properties}{$_}) + for keys %{$by->{properties} || {}}; } return $clone; @@ -81,7 +93,8 @@ sub validate { my ($self, $data) = @_; - state $jv = JSON::Validator->new->coerce(1); + state $jv + = JSON::Validator->new->coerce({booleans => 1, numbers => 1, strings => 1}); return $jv->validate($data, $self->compile); } @@ -321,9 +334,10 @@ =head2 extend - my $new_joi = $joi->extend($joi); + my $new_joi = $joi->extend($other_joi_object); -Will extend C<$joi> with the definitions in C<$joi> and return a new object. +Will extend C<$joi> with the definitions in C<$other_joi_object> and return a +new object. =head2 iso_date diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/lib/JSON/Validator.pm new/JSON-Validator-3.14/lib/JSON/Validator.pm --- old/JSON-Validator-3.11/lib/JSON/Validator.pm 2019-05-07 16:53:16.000000000 +0200 +++ new/JSON-Validator-3.14/lib/JSON/Validator.pm 2019-08-09 23:52:24.000000000 +0200 @@ -15,7 +15,6 @@ use Mojo::URL; use Mojo::Util qw(url_unescape sha1_sum); use Scalar::Util qw(blessed refaddr); -use Time::Local (); use constant CASE_TOLERANT => File::Spec->case_tolerant; use constant COLORS => eval { require Term::ANSIColor }; @@ -25,7 +24,7 @@ use constant SPECIFICATION_URL => 'http://json-schema.org/draft-04/schema#'; our $DEFINITIONS = 'definitions'; -our $VERSION = '3.11'; +our $VERSION = '3.14'; our $YAML_LOADER = eval q[use YAML::XS 0.67; YAML::XS->can('Load')]; # internal our @EXPORT_OK = qw(joi validate_json); @@ -596,7 +595,7 @@ } elsif ($type) { my $method = sprintf '_validate_type_%s', $type; - $self->_report_schema($path || '/', $type, $schema); + $self->_report_schema($path || '/', $type, $schema) if REPORT; @errors = $self->$method($to_json ? $$to_json : $_[1], $path, $schema); $self->_report_errors($path, $type, \@errors) if REPORT; return @errors if @errors; @@ -1029,9 +1028,9 @@ } sub _cmp { - return undef if !defined $_[0] or !defined $_[1]; + return undef if !defined $_[0] or !defined $_[1]; return "$_[3]=" if $_[2] and $_[0] >= $_[1]; - return $_[3] if $_[0] > $_[1]; + return $_[3] if $_[0] > $_[1]; return ""; } @@ -1045,9 +1044,9 @@ sub _guess_data_type { my $ref = ref $_[0]; my $blessed = blessed $_[0]; - return 'object' if $ref eq 'HASH'; - return lc $ref if $ref and !$blessed; - return 'null' if !defined $_[0]; + return 'object' if $ref eq 'HASH'; + return lc $ref if $ref and !$blessed; + return 'null' if !defined $_[0]; return 'boolean' if $blessed and ("$_[0]" eq "1" or !"$_[0]"); if (_is_number($_[0])) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/t/booleans.t new/JSON-Validator-3.14/t/booleans.t --- old/JSON-Validator-3.11/t/booleans.t 2019-04-06 10:12:25.000000000 +0200 +++ new/JSON-Validator-3.14/t/booleans.t 2019-08-09 23:48:57.000000000 +0200 @@ -23,8 +23,7 @@ validate_ok {v => ''}, $schema, E('/v', 'Expected boolean - got string.'); SKIP: { - skip 'YAML::XS is not installed', 1 - unless eval q[require YAML::XS;YAML::XS->VERSION('0.67');1]; + skip 'YAML::XS is not installed', 1 unless $JSON::Validator::YAML_LOADER; my $data = jv->_load_schema_from_text(\"---\nv: true\n"); isa_ok($data->{v}, 'JSON::PP::Boolean'); validate_ok $data, $schema; @@ -37,8 +36,7 @@ } SKIP: { - skip 'Cpanel::JSON::XS not installed', 2 - unless eval 'require Cpanel::JSON::XS;1'; + skip 'Cpanel::JSON::XS not installed', 2 unless $JSON::Validator::YAML_LOADER; validate_ok {disabled => Mojo::JSON->true}, {properties => {disabled => {type => 'boolean'}}}; validate_ok {disabled => Mojo::JSON->false}, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/t/formats.t new/JSON-Validator-3.14/t/formats.t --- old/JSON-Validator-3.11/t/formats.t 1970-01-01 01:00:00.000000000 +0100 +++ new/JSON-Validator-3.14/t/formats.t 2019-06-27 08:48:01.000000000 +0200 @@ -0,0 +1,10 @@ +use strict; +use Test::More; + +BEGIN { use_ok ('JSON::Validator::Formats'); } + +ok !JSON::Validator::Formats::check_date('2019-06-11'); +ok !JSON::Validator::Formats::check_email('d...@example.org'); +ok !JSON::Validator::Formats::check_time('08:22:54'); + +done_testing; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/t/joi.t new/JSON-Validator-3.14/t/joi.t --- old/JSON-Validator-3.11/t/joi.t 2019-01-20 23:31:14.000000000 +0100 +++ new/JSON-Validator-3.14/t/joi.t 2019-08-08 14:45:54.000000000 +0200 @@ -1,6 +1,8 @@ use lib '.'; use t::Helper; use JSON::Validator 'joi'; +use Storable 'dclone'; +use Test::Deep; use Test::More; is_deeply( @@ -94,23 +96,31 @@ like $@, qr{Cannot extend joi 'number' by 'integer'}, 'need to extend same type'; -is_deeply( - edj(joi->array->min(0)->max(10)->extend(joi->array->min(5))), +test_extend( + joi->array->min(0)->max(10), + joi->array->min(5), {type => 'array', minItems => 5, maxItems => 10}, 'extended array', ); -is_deeply( - edj(joi->integer->min(0)->max(10)->extend(joi->integer->min(5))), +test_extend( + joi->array->items([joi->integer]), + joi->array->items([joi->number]), + {type => 'array', items => [{type => 'number'}]}, + 'extended items in an array', +); + +test_extend( + joi->integer->min(0)->max(10), + joi->integer->min(5), {type => 'integer', minimum => 5, maximum => 10}, 'extended integer', + 'extended integer', ); -is_deeply( - edj( - joi->object->props(x => joi->integer, y => joi->integer) - ->extend(joi->object->props(x => joi->number)) - ), +test_extend( + joi->object->props(x => joi->integer, y => joi->integer), + joi->object->props(x => joi->number), { type => 'object', properties => {x => {type => 'number'}, y => {type => 'integer'}} @@ -133,4 +143,34 @@ 'null or string', ); +test_extend( + joi->object->props(a => joi->integer, b => joi->integer->required), + joi->object->props( + b => joi->integer->required, + x => joi->string->required, + y => joi->string->required + ), + { + type => 'object', + required => bag(qw(b x y)), + properties => { + a => {type => 'integer'}, + b => {type => 'integer'}, + x => {type => 'string'}, + y => {type => 'string'}, + }, + }, + 'extended object with required', +); + done_testing; + +sub test_extend { + my ($joi, $by, $expected, $description) = @_; + my $joi_clone = dclone $joi; + my $by_clone = dclone $by; + + cmp_deeply(edj($joi->extend($by)), $expected, $description); + cmp_deeply $joi, $joi_clone, "$description did not mutate \$joi"; + cmp_deeply $by, $by_clone, "$description did not mutate \$by"; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/t/more-bundle.t new/JSON-Validator-3.14/t/more-bundle.t --- old/JSON-Validator-3.11/t/more-bundle.t 1970-01-01 01:00:00.000000000 +0100 +++ new/JSON-Validator-3.14/t/more-bundle.t 2019-08-09 23:48:57.000000000 +0200 @@ -0,0 +1,239 @@ +use Mojo::Base -strict; + +use Test::More; +use Test::Deep; +use JSON::Validator; + +plan skip_all => 'YAML::XS is not installed' + unless $JSON::Validator::YAML_LOADER; + +# these are triples: +# - schema name to extract from schema file(s) with bundle() +# - expected result +# - test name. +my @tests = ( + [ + 'i_have_nested_refs', + { + definitions => { + ref1 => {type => 'array', items => {'$ref' => '#/definitions/ref2'}}, + ref2 => {type => 'string', minLength => 1}, + }, + + # begin i_have_nested_refs definition + type => 'object', + properties => { + my_key1 => {'$ref' => '#/definitions/ref1'}, + my_key2 => {'$ref' => '#/definitions/ref1'}, + }, + }, + 'find and resolve nested $refs; main schema is at the top level', + ], + + [ + 'i_have_a_recursive_ref', + { + definitions => { + i_have_a_recursive_ref => { + type => 'object', + properties => { + name => {type => 'string'}, + children => { + type => 'array', + items => {'$ref' => '#/definitions/i_have_a_recursive_ref'}, + default => [], + }, + }, + }, + }, + + # begin i_have_a_recursive_ref definition + # it is duplicated with the above, but there is no other way, + # because $ref cannot be combined with other sibling keys + type => 'object', + properties => { + name => {type => 'string'}, + children => { + type => 'array', + items => {'$ref' => '#/definitions/i_have_a_recursive_ref'}, + default => [], + }, + }, + }, + 'find and resolve recursive $refs', + ], + + [ + 'i_have_a_ref_to_another_file', + { + definitions => { + my_name => {type => 'string', minLength => 2}, + my_address => { + type => 'object', + properties => { + street => {type => 'string'}, + city => {'$ref' => '#/definitions/my_name'}, + }, + }, + ref1 => {type => 'array', items => {'$ref' => '#/definitions/ref2'}}, + ref2 => {type => 'string', minLength => 1}, + }, + + # begin i_have_a_ref_to_another_file definition + type => 'object', + properties => { + + # these ref targets are rewritten + name => {'$ref' => '#/definitions/my_name'}, + address => {'$ref' => '#/definitions/my_address'}, + secrets => {'$ref' => '#/definitions/ref1'}, + }, + }, + 'find and resolve references to other local files', + ], + + [ + 'i_am_a_ref', + { + definitions => {ref2 => {type => 'string', minLength => 1}}, + + # begin i_am_a_ref definition - which is actually ref1 + type => 'array', + items => {'$ref' => '#/definitions/ref2'}, + }, + 'find and resolve references where the definition itself is a ref', + ], + + [ + 'i_am_a_ref_level_1', + { + # begin i_am_a_ref definition - which is actually (eventually) ref3 + type => 'integer', + }, + 'find and resolve references where the definition itself is a ref, multiple times over', + ], + + [ + 'i_have_refs_with_the_same_name', + { + definitions => {i_am_a_ref_with_the_same_name => {type => 'string'}}, + + # begin i_have_a_ref_with_the_same_name definition + type => 'object', + properties => + {me => {'$ref' => '#/definitions/i_am_a_ref_with_the_same_name'}}, + }, + '$refs which are simply $refs themselves are traversed automatically during resolution', + ], + + [ + 'i_am_a_ref_with_the_same_name', + { + # begin i_am_a_ref_with_the_same_name definition + # - pulled from secondary file + type => 'string', + }, + '$refs which are simply $refs themselves are traversed automatically during resolution, at the top level too', + ], + + [ + 'i_contain_refs_to_same_named_definitions', + { + definitions => code(sub { + my $got = shift; + return (0, 'expected hash with 2 keys') + unless ref($got) eq 'HASH' and keys %$got == 2; + return (0, 'missing "dupe_name" key') if not exists $got->{dupe_name}; + + # we don't know which ref will keep its name and which will be renamed + my ($other_key) = grep $_ ne 'dupe_name', keys %$got; + return 1 + if (eq_deeply($got->{dupe_name}, {type => 'integer'}) + and eq_deeply($got->{$other_key}, {type => 'string'}) + and eq_deeply($other_key, re(qr/-more-bundle2_yaml$/))) + or (( + eq_deeply($got->{dupe_name}, {type => 'string'}) + and eq_deeply($got->{$other_key}, {type => 'integer'}) + and eq_deeply($other_key, re(qr/-more-bundle_yaml$/)) + )); + return (0, 'uh oh, got: ' . (Test::More::explain($got))[0]); + }), + + # begin i_contain_refs_to_same_named_definitions definition + type => 'object', + properties => { + foo => { + '$ref' => re(qr/^#\/definitions\/(dupe_name|\w+-more-bundle_yaml)$/) + }, + bar => { + '$ref' => re(qr/^#\/definitions\/(dupe_name|\w+-more-bundle2_yaml)/) + }, + }, + }, + 'when encountering references that have the same root name, one is renamed', + ], + + [ + 'i_have_a_ref_with_the_same_name', + { + definitions => {i_have_a_ref_with_the_same_name => {type => 'string'}}, + + # begin i_have_a_ref_with_the_same_name definition + type => 'object', + properties => { + name => {type => 'string'}, + children => { + type => 'array', + items => {'$ref' => '#/definitions/i_have_a_ref_with_the_same_name'}, + default => [], + }, + }, + }, + 'we can handle pulling in references that have the same root name as the top level name', + ], + + [ + 'i_am_a_ref_to_another_file', + { + definitions => {ref3 => {type => 'integer'}}, + + # begin i_am_a_ref_to_another_file definition - which is actually + # i_have_a_ref_to_the_first_filename + type => 'object', + properties => {gotcha => {'$ref' => '#/definitions/ref3'}}, + }, + 'find and resolve a reference that immediately leaps to another file', + ], +); + +my $draft7_validator = JSON::Validator->new; +$draft7_validator->schema('http://json-schema.org/draft-07/schema#'); + +my $bundler_validator = JSON::Validator->new; +$bundler_validator->load_and_validate_schema('t/spec/more-bundle.yaml', + {schema => 'http://json-schema.org/draft-07/schema#'}); + +subtest $_->[2] => sub { + my ($schema_name, $expected_output, $test_name) = @$_; + + my $got = $bundler_validator->bundle( + {schema => $bundler_validator->get('/definitions/' . $schema_name)}); + + cmp_deeply($got, $expected_output, 'extracted schema for ' . $schema_name) + or diag 'got: ', explain($got); + + my @errors = $draft7_validator->validate($got); + ok(!@errors, 'bundled schema conforms to the draft 7 spec'); + + my $fresh_draft7_validator = JSON::Validator->new; + $fresh_draft7_validator->load_and_validate_schema($got, + {schema => 'http://json-schema.org/draft-07/schema#'}); + cmp_deeply( + $fresh_draft7_validator->schema->data, + $expected_output, + 'our generated schema does not lose any data when parsed again by a new validator', + ); + } + for @tests; + +done_testing; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/t/spec/more-bundle.yaml new/JSON-Validator-3.14/t/spec/more-bundle.yaml --- old/JSON-Validator-3.11/t/spec/more-bundle.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/JSON-Validator-3.14/t/spec/more-bundle.yaml 2019-06-27 08:48:01.000000000 +0200 @@ -0,0 +1,73 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +definitions: + ref1: + type: array + items: + $ref: /definitions/ref2 + ref2: + type: string + minLength: 1 + ref3: + type: integer + dupe_name: + type: integer + i_have_nested_refs: + type: object + properties: + my_key1: + $ref: /definitions/ref1 + my_key2: + $ref: /definitions/ref1 + # actually a person, as in https://json-schema.org/understanding-json-schema/structuring.html + i_have_a_recursive_ref: + type: object + properties: + name: + type: string + children: + type: array + items: + $ref: /definitions/i_have_a_recursive_ref + default: [] + i_have_a_ref_to_another_file: + type: object + properties: + name: + $ref: more-bundle2.yaml#/definitions/my_name + address: + $ref: more-bundle2.yaml#/definitions/my_address + secrets: + $ref: /definitions/ref1 + i_am_a_ref: + $ref: /definitions/ref1 + i_am_a_ref_level_1: + $ref: /definitions/i_am_a_ref_level_2 + i_am_a_ref_level_2: + $ref: /definitions/ref3 + i_am_a_ref_to_another_file: + $ref: more-bundle2.yaml#/definitions/i_have_a_ref_to_the_first_filename + i_am_a_ref_with_the_same_name: + $ref: more-bundle2.yaml#/definitions/i_am_a_ref_with_the_same_name + i_have_refs_with_the_same_name: + type: object + properties: + me: + $ref: /definitions/i_am_a_ref_with_the_same_name + i_contain_refs_to_same_named_definitions: + type: object + properties: + foo: + $ref: /definitions/dupe_name + bar: + $ref: more-bundle2.yaml#/definitions/dupe_name + i_have_a_ref_with_the_same_name: + type: object + properties: + name: + type: string + children: + type: array + items: + $ref: more-bundle2.yaml#/definitions/i_have_a_ref_with_the_same_name + default: [] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.11/t/spec/more-bundle2.yaml new/JSON-Validator-3.14/t/spec/more-bundle2.yaml --- old/JSON-Validator-3.11/t/spec/more-bundle2.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/JSON-Validator-3.14/t/spec/more-bundle2.yaml 2019-06-27 08:48:01.000000000 +0200 @@ -0,0 +1,25 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +definitions: + my_name: + type: string + minLength: 2 + my_address: + type: object + properties: + street: + type: string + city: + # this is a local ref in a secondary file - resolution is extra tricky + $ref: /definitions/my_name + dupe_name: + type: string + i_am_a_ref_with_the_same_name: + type: string + i_have_a_ref_to_the_first_filename: + type: object + properties: + gotcha: + $ref: more-bundle.yaml#/definitions/ref3 + i_have_a_ref_with_the_same_name: + type: string