Hello community, here is the log from the commit of package perl-JSON-Validator for openSUSE:Factory checked in at 2019-04-05 12:05:17 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-JSON-Validator (Old) and /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.3908 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-JSON-Validator" Fri Apr 5 12:05:17 2019 rev:2 rq:691644 version:3.07 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-JSON-Validator/perl-JSON-Validator.changes 2019-03-01 16:47:02.549807793 +0100 +++ /work/SRC/openSUSE:Factory/.perl-JSON-Validator.new.3908/perl-JSON-Validator.changes 2019-04-05 12:06:53.386578610 +0200 @@ -1,0 +2,9 @@ +Fri Apr 5 05:11:55 UTC 2019 - Stephan Kulow <co...@suse.com> + +- updated to 3.07 + see /usr/share/doc/packages/perl-JSON-Validator/Changes + + 3.07 2019-04-04T23:43:55+0700 + - Fix not leaking file names with bundle() + +------------------------------------------------------------------- Old: ---- JSON-Validator-3.06.tar.gz New: ---- JSON-Validator-3.07.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-JSON-Validator.spec ++++++ --- /var/tmp/diff_new_pack.DXjJZJ/_old 2019-04-05 12:06:53.970578836 +0200 +++ /var/tmp/diff_new_pack.DXjJZJ/_new 2019-04-05 12:06:53.970578836 +0200 @@ -17,7 +17,7 @@ Name: perl-JSON-Validator -Version: 3.06 +Version: 3.07 Release: 0 %define cpan_name JSON-Validator Summary: Validate data against a JSON schema ++++++ JSON-Validator-3.06.tar.gz -> JSON-Validator-3.07.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/Changes new/JSON-Validator-3.07/Changes --- old/JSON-Validator-3.06/Changes 2019-02-14 18:24:29.000000000 +0100 +++ new/JSON-Validator-3.07/Changes 2019-04-04 18:43:55.000000000 +0200 @@ -1,5 +1,8 @@ Revision history for perl distribution JSON-Validator +3.07 2019-04-04T23:43:55+0700 + - Fix not leaking file names with bundle() + 3.06 2019-02-14T18:24:29+0100 - Fix coercing integers and numbers #147 - Changed recursion guard to not keeping tracking of plain scalars #147 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/MANIFEST new/JSON-Validator-3.07/MANIFEST --- old/JSON-Validator-3.06/MANIFEST 2019-02-14 18:24:30.000000000 +0100 +++ new/JSON-Validator-3.07/MANIFEST 2019-04-04 18:43:56.000000000 +0200 @@ -100,6 +100,7 @@ t/remotes/integer.json t/remotes/subSchemas.json t/schema-as-attr.t +t/spec/bundle-no-leaking-filename.json t/spec/bundlecheck.json t/spec/missing-ref.json t/spec/person.json diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/META.json new/JSON-Validator-3.07/META.json --- old/JSON-Validator-3.06/META.json 2019-02-14 18:24:30.000000000 +0100 +++ new/JSON-Validator-3.07/META.json 2019-04-04 18:43:56.000000000 +0200 @@ -60,6 +60,6 @@ }, "x_IRC" : "irc://irc.freenode.net/#mojo" }, - "version" : "3.06", + "version" : "3.07", "x_serialization_backend" : "JSON::PP version 2.97001" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/META.yml new/JSON-Validator-3.07/META.yml --- old/JSON-Validator-3.06/META.yml 2019-02-14 18:24:30.000000000 +0100 +++ new/JSON-Validator-3.07/META.yml 2019-04-04 18:43:56.000000000 +0200 @@ -29,5 +29,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.06' +version: '3.07' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/lib/JSON/Validator/Joi.pm new/JSON-Validator-3.07/lib/JSON/Validator/Joi.pm --- old/JSON-Validator-3.06/lib/JSON/Validator/Joi.pm 2019-01-20 23:31:14.000000000 +0100 +++ new/JSON-Validator-3.07/lib/JSON/Validator/Joi.pm 2019-04-04 18:41:08.000000000 +0200 @@ -62,7 +62,7 @@ sub positive { shift->number->min(0) } sub props { - my $self = shift->type('object'); + my $self = shift->type('object'); my %properties = ref $_[0] ? %{$_[0]} : @_; while (my ($name, $property) = each %properties) { @@ -80,8 +80,8 @@ sub validate { my ($self, $data) = @_; - state $validator = JSON::Validator->new->coerce(1); - return $validator->validate($data, $self->compile); + state $jv = JSON::Validator->new->coerce(1); + return $jv->validate($data, $self->compile); } sub _compile_array { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/lib/JSON/Validator.pm new/JSON-Validator-3.07/lib/JSON/Validator.pm --- old/JSON-Validator-3.06/lib/JSON/Validator.pm 2019-02-14 18:24:29.000000000 +0100 +++ new/JSON-Validator-3.07/lib/JSON/Validator.pm 2019-04-04 18:43:55.000000000 +0200 @@ -10,7 +10,7 @@ use JSON::Validator::Ref; use Mojo::File 'path'; use Mojo::JSON::Pointer; -use Mojo::JSON; +use Mojo::JSON qw(false true); use Mojo::Loader; use Mojo::URL; use Mojo::Util qw(url_unescape sha1_sum); @@ -24,9 +24,12 @@ use constant RECURSION_LIMIT => $ENV{JSON_VALIDATOR_RECURSION_LIMIT} || 100; use constant SPECIFICATION_URL => 'http://json-schema.org/draft-04/schema#'; -our $VERSION = '3.06'; +our $VERSION = '3.07'; our @EXPORT_OK = qw(joi validate_json); +# $YAML_LOADER should be considered internal +our $YAML_LOADER = eval q[use YAML::XS 0.67; YAML::XS->can('Load')]; + my $BUNDLED_CACHE_DIR = path(path(__FILE__)->dirname, qw(Validator cache)); my $HTTP_SCHEME_RE = qr{^https?:}; @@ -82,12 +85,13 @@ my $ref = ref $from; if ($ref eq 'HASH' and my $tied = tied %$from) { - my $ref_name = $tied->fqn; + my $ref_name = $tied->fqn; + my $file_name = (split '#', $ref_name)[0]; return $from if $ref_name =~ m!^\Q$self->{root_schema_url}\E\#!; - if (-e $ref_name) { + if (-e $file_name) { $ref_name = sprintf '%s-%s', substr(sha1_sum($ref_name), 0, 10), - path($ref_name)->basename; + path($file_name)->basename; } else { $ref_name =~ s![^\w-]!_!g; @@ -133,18 +137,10 @@ } sub get { - my ($self, $pointer) = @_; - $pointer - = [ - ref $pointer ? @$pointer - : length $pointer ? split('/', $pointer, -1) - : $pointer - ]; - shift @$pointer - if @$pointer - and defined $pointer->[0] - and !length $pointer->[0]; - $self->_get($self->schema->data, $pointer, ''); + my ($self, $p) = @_; + $p = [ref $p ? @$p : length $p ? split('/', $p, -1) : $p]; + shift @$p if @$p and defined $p->[0] and !length $p->[0]; + $self->_get($self->schema->data, $p, ''); } sub joi { @@ -172,7 +168,7 @@ return $self; } -sub singleton { state $validator = shift->new } +sub singleton { state $jv = shift->new } sub validate { my ($self, $data, $schema) = @_; @@ -315,13 +311,15 @@ unless $v->{type} and $v->{type} eq 'boolean' and exists $v->{default}; - %$v - = (%$v, default => $v->{default} ? Mojo::JSON->true : Mojo::JSON->false); + %$v = (%$v, default => $v->{default} ? true : false); return $v; }; + die "[JSON::Validator] YAML::XS 0.67 is missing or could not be loaded." + unless $YAML_LOADER; + local $YAML::XS::Boolean = 'JSON::PP'; - return $visit->($self->_yaml_module->can('Load')->($$text)); + return $visit->($YAML_LOADER->($$text)); } sub _load_schema_from_url { @@ -792,7 +790,7 @@ or $value =~ /^(true|false)$/) ) { - $_[1] = $value ? Mojo::JSON->true : Mojo::JSON->false; + $_[1] = $value ? true : false; return; } @@ -1072,14 +1070,6 @@ grep { !$uniq{$_}++ } @_; } -# Please report if you need to manually monkey patch this function -# https://github.com/jhthorsen/json-validator/issues -sub _yaml_module { - state $yaml_module = eval qq[use YAML::XS 0.67; "YAML::XS"] - || die - "[JSON::Validator] The optional YAML::XS module is missing or could not be loaded: $@"; -} - 1; =encoding utf8 @@ -1091,11 +1081,11 @@ =head1 SYNOPSIS use JSON::Validator; - my $validator = JSON::Validator->new; + my $jv = JSON::Validator->new; # Define a schema - http://json-schema.org/learn/miscellaneous-examples.html # You can also load schema from disk or web - $validator->schema({ + $jv->schema({ type => "object", required => ["firstName", "lastName"], properties => { @@ -1106,7 +1096,7 @@ }); # Validate your data - my @errors = $validator->validate({firstName => "Jan Henning", lastName => "Thorsen", age => -42}); + my @errors = $jv->validate({firstName => "Jan Henning", lastName => "Thorsen", age => -42}); # Do something if any errors was found die "@errors" if @errors; @@ -1114,7 +1104,7 @@ # Use joi() to build the schema use JSON::Validator 'joi'; - $validator->schema(joi->object->props({ + $jv->schema(joi->object->props({ firstName => joi->string->required, lastName => joi->string->required, age => joi->integer->min(0), @@ -1241,8 +1231,8 @@ =head2 cache_paths - my $validator = $validator->cache_paths(\@paths); - my $array_ref = $validator->cache_paths; + my $jv = $jv->cache_paths(\@paths); + my $array_ref = $jv->cache_paths; A list of directories to where cached specifications are stored. Defaults to C<JSON_VALIDATOR_CACHE_PATH> environment variable and the specs that is bundled @@ -1254,8 +1244,8 @@ =head2 formats - my $hash_ref = $validator->formats; - my $validator = $validator->formats(\%hash); + my $hash_ref = $jv->formats; + my $jv = $jv->formats(\%hash); Holds a hash-ref, where the keys are supported JSON type "formats", and the values holds a code block which can validate a given format. A code @@ -1267,8 +1257,8 @@ =head2 ua - my $ua = $validator->ua; - my $validator = $validator->ua(Mojo::UserAgent->new); + my $ua = $jv->ua; + my $jv = $jv->ua(Mojo::UserAgent->new); Holds a L<Mojo::UserAgent> object, used by L</schema> to load a JSON schema from remote location. @@ -1278,8 +1268,8 @@ =head2 version - my $int = $validator->version; - my $validator = $validator->version(7); + my $int = $jv->version; + my $jv = $jv->version(7); Used to set the JSON Schema version to use. Will be set automatically when using L</load_and_validate_schema>, unless already set. @@ -1288,13 +1278,13 @@ =head2 bundle - my $schema = $validator->bundle(\%args); + my $schema = $jv->bundle(\%args); Used to create a new schema, where the C<$ref> are resolved. C<%args> can have: =over 2 -=item * C<{replace => 1}> +=item * C<< {replace => 1} >> Used if you want to replace the C<$ref> inline in the schema. This currently does not work if you have circular references. The default is to move all the @@ -1307,7 +1297,7 @@ {"$ref":"http://example.com#/foo/bar"} => {"$ref":"#/definitions/_http___example_com-_foo_bar"} -=item * C<{schema => {...}}> +=item * C<< {schema => {...}} >> Default is to use the value from the L</schema> attribute. @@ -1315,9 +1305,9 @@ =head2 coerce - my $validator = $validator->coerce(booleans => 1, numbers => 1, strings => 1); - my $validator = $validator->coerce({booleans => 1, numbers => 1, strings => 1}); - my $hash_ref = $validator->coerce; + my $jv = $jv->coerce(booleans => 1, numbers => 1, strings => 1); + my $jv = $jv->coerce({booleans => 1, numbers => 1, strings => 1}); + my $hash_ref = $jv->coerce; Set the given type to coerce. Before enabling coercion this module is very strict when it comes to validating types. Example: The string C<"1"> is not @@ -1329,23 +1319,23 @@ =head2 get - my $sub_schema = $validator->get("/x/y"); - my $sub_schema = $validator->get(["x", "y"]); + my $sub_schema = $jv->get("/x/y"); + my $sub_schema = $jv->get(["x", "y"]); Extract value from L</schema> identified by the given JSON Pointer. Will at the same time resolve C<$ref> if found. Example: - $validator->schema({x => {'$ref' => '#/y'}, y => {'type' => 'string'}}); - $validator->schema->get('/x') == undef - $validator->schema->get('/x')->{'$ref'} == '#/y' - $validator->get('/x') == {type => 'string'} + $jv->schema({x => {'$ref' => '#/y'}, y => {'type' => 'string'}}); + $jv->schema->get('/x') == undef + $jv->schema->get('/x')->{'$ref'} == '#/y' + $jv->get('/x') == {type => 'string'} The argument can also be an array-ref with the different parts of the pointer as each elements. =head2 load_and_validate_schema - my $validator = $validator->load_and_validate_schema($schema, \%args); + my $jv = $jv->load_and_validate_schema($schema, \%args); Will load and validate C<$schema> against the OpenAPI specification. C<$schema> can be anything L<JSON::Validator/schema> accepts. The expanded specification @@ -1366,11 +1356,11 @@ =head2 schema - my $validator = $validator->schema($json_or_yaml_string); - my $validator = $validator->schema($url); - my $validator = $validator->schema(\%schema); - my $validator = $validator->schema(JSON::Validator::Joi->new); - my $schema = $validator->schema; + my $jv = $jv->schema($json_or_yaml_string); + my $jv = $jv->schema($url); + my $jv = $jv->schema(\%schema); + my $jv = $jv->schema(JSON::Validator::Joi->new); + my $schema = $jv->schema; Used to set a schema from either a data structure or a URL. @@ -1410,14 +1400,14 @@ =head2 singleton - my $validator = JSON::Validator->singleton; + my $jv = JSON::Validator->singleton; Returns the L<JSON::Validator> object used by L</validate_json>. =head2 validate - my @errors = $validator->validate($data); - my @errors = $validator->validate($data, $schema); + my @errors = $jv->validate($data); + my @errors = $jv->validate($data, $schema); Validates C<$data> against a given JSON L</schema>. C<@errors> will contain validation error objects or be an empty list on success. @@ -1427,7 +1417,7 @@ C<$schema> is optional, but when specified, it will override schema stored in L</schema>. Example: - $validator->validate({hero => "superwoman"}, {type => "object"}); + $jv->validate({hero => "superwoman"}, {type => "object"}); =head2 SEE ALSO diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/Helper.pm new/JSON-Validator-3.07/t/Helper.pm --- old/JSON-Validator-3.06/t/Helper.pm 2019-01-31 00:44:17.000000000 +0100 +++ new/JSON-Validator-3.07/t/Helper.pm 2019-04-04 18:41:08.000000000 +0200 @@ -8,38 +8,36 @@ $ENV{TEST_VALIDATOR_CLASS} = 'JSON::Validator'; -sub dump_validator { - my $class = shift; - my $jv = shift || $class->validator; - local $Data::Dumper::Indent = 1; - local $jv->{ua} = 'Mojo::UserAgent'; - Test::More::note(Data::Dumper::Dumper($jv)); -} - sub edj { return Mojo::JSON::decode_json(Mojo::JSON::encode_json(@_)); } sub joi_ok { my ($data, $joi, @expected) = @_; - my $description ||= @expected ? "errors: @expected" : "valid: " . encode_json($data); + my $description + ||= @expected ? "errors: @expected" : "valid: " . encode_json($data); my @errors = JSON::Validator::joi($data, $joi); - Test::More::is_deeply([map { $_->TO_JSON } sort { $a->path cmp $b->path } @errors], - [map { $_->TO_JSON } sort { $a->path cmp $b->path } @expected], $description) + Test::More::is_deeply( + [map { $_->TO_JSON } sort { $a->path cmp $b->path } @errors], + [map { $_->TO_JSON } sort { $a->path cmp $b->path } @expected], + $description) or Test::More::diag(encode_json(\@errors)); } +sub jv { state $obj = $ENV{TEST_VALIDATOR_CLASS}->new } + sub validate_ok { my ($data, $schema, @expected) = @_; - my $description ||= @expected ? "errors: @expected" : "valid: " . encode_json($data); - my @errors = validator()->schema($schema)->validate($data); - Test::More::is_deeply([map { $_->TO_JSON } sort { $a->path cmp $b->path } @errors], - [map { $_->TO_JSON } sort { $a->path cmp $b->path } @expected], $description) + my $description + ||= @expected ? "errors: @expected" : "valid: " . encode_json($data); + my @errors = jv()->schema($schema)->validate($data); + Test::More::is_deeply( + [map { $_->TO_JSON } sort { $a->path cmp $b->path } @errors], + [map { $_->TO_JSON } sort { $a->path cmp $b->path } @expected], + $description) or Test::More::diag(encode_json(\@errors)); } -sub validator { state $obj = $ENV{TEST_VALIDATOR_CLASS}->new } - sub import { my $class = shift; my $caller = caller; @@ -48,11 +46,12 @@ warnings->import; monkey_patch $caller => E => \&JSON::Validator::E; monkey_patch $caller => done_testing => \&Test::More::done_testing; - monkey_patch $caller => false => \&Mojo::JSON::false; monkey_patch $caller => edj => \&edj; + monkey_patch $caller => false => \&Mojo::JSON::false; + monkey_patch $caller => joi_ok => \&joi_ok; + monkey_patch $caller => jv => \&jv; monkey_patch $caller => true => \&Mojo::JSON::true; monkey_patch $caller => validate_ok => \&validate_ok; - monkey_patch $caller => joi_ok => \&joi_ok; } 1; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/booleans.t new/JSON-Validator-3.07/t/booleans.t --- old/JSON-Validator-3.06/t/booleans.t 2019-01-31 00:44:26.000000000 +0100 +++ new/JSON-Validator-3.07/t/booleans.t 2019-04-04 18:41:08.000000000 +0200 @@ -11,7 +11,7 @@ validate_ok {v => Mojo::JSON->true}, $schema; validate_ok {v => Mojo::JSON->false}, $schema; -t::Helper->validator->coerce(booleans => 1); +jv->coerce(booleans => 1); validate_ok {v => !!1}, $schema; validate_ok {v => !!0}, $schema; validate_ok {v => 'false'}, $schema; @@ -25,7 +25,7 @@ SKIP: { skip 'YAML::XS is not installed', 1 unless eval q[require YAML::XS;YAML::XS->VERSION('0.67');1]; - my $data = t::Helper->validator->_load_schema_from_text(\"---\nv: true\n"); + my $data = jv->_load_schema_from_text(\"---\nv: true\n"); isa_ok($data->{v}, 'JSON::PP::Boolean'); validate_ok $data, $schema; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/bundle.t new/JSON-Validator-3.07/t/bundle.t --- old/JSON-Validator-3.06/t/bundle.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/bundle.t 2019-04-04 18:43:24.000000000 +0200 @@ -3,21 +3,22 @@ use Test::More; use JSON::Validator; -my $validator = JSON::Validator->new; +my $workdir = path(__FILE__)->to_abs->dirname; +my $jv = JSON::Validator->new; my $bundled; -# Bundle files { + note 'bundle files'; local $ENV{JSON_VALIDATOR_CACHE_ANYWAYS} = 1; - $validator->_load_schema_from_url("http://json-schema.org/draft-04/schema"); - $validator->_load_schema_from_url("http://json-schema.org/draft-06/schema"); - $validator->_load_schema_from_url("http://json-schema.org/draft-07/schema"); + $jv->_load_schema_from_url("http://json-schema.org/draft-04/schema"); + $jv->_load_schema_from_url("http://json-schema.org/draft-06/schema"); + $jv->_load_schema_from_url("http://json-schema.org/draft-07/schema"); } -# Run multiple times to make sure _reset() works +note 'Run multiple times to make sure _reset() works'; for my $n (1 .. 3) { note "[$n] replace=1"; - $bundled = $validator->bundle({ + $bundled = $jv->bundle({ ref_key => 'definitions', replace => 1, schema => { @@ -29,7 +30,7 @@ is $bundled->{name}{type}, 'string', "[$n] replace=1"; note "[$n] replace=0"; - $bundled = $validator->schema({ + $bundled = $jv->schema({ name => {'$ref' => '#/definitions/name'}, age => {'$ref' => 'b.json#/definitions/age'}, definitions => {name => {type => 'string'}}, @@ -39,23 +40,23 @@ "[$n] name still in definitions"; is $bundled->{definitions}{b_json__definitions_age}{type}, 'integer', "[$n] added to definitions"; - isnt $bundled->{age}, $validator->schema->get('/age'), "[$n] new age ref"; - is $bundled->{name}, $validator->schema->get('/name'), "[$n] same name ref"; + isnt $bundled->{age}, $jv->schema->get('/age'), "[$n] new age ref"; + is $bundled->{name}, $jv->schema->get('/name'), "[$n] same name ref"; is $bundled->{age}{'$ref'}, '#/definitions/b_json__definitions_age', "[$n] age \$ref point to /definitions/b_json__definitions_age"; is $bundled->{name}{'$ref'}, '#/definitions/name', "[$n] name \$ref point to /definitions/name"; } -is $validator->get([qw(name type)]), 'string', 'get /name/$ref'; -is $validator->get('/name/type'), 'string', 'get /name/type'; -is $validator->get('/name/$ref'), undef, 'get /name/$ref'; -is $validator->schema->get('/name/type'), 'string', 'schema get /name/type'; -is $validator->schema->get('/name/$ref'), '#/definitions/name', +is $jv->get([qw(name type)]), 'string', 'get /name/$ref'; +is $jv->get('/name/type'), 'string', 'get /name/type'; +is $jv->get('/name/$ref'), undef, 'get /name/$ref'; +is $jv->schema->get('/name/type'), 'string', 'schema get /name/type'; +is $jv->schema->get('/name/$ref'), '#/definitions/name', 'schema get /name/$ref'; -$bundled = $validator->schema('data://main/api.json') - ->bundle({ref_key => 'definitions'}); +$bundled + = $jv->schema('data://main/api.json')->bundle({ref_key => 'definitions'}); is_deeply [sort keys %{$bundled->{definitions}}], ['objtype'], 'no dup definitions'; @@ -64,33 +65,61 @@ ['spec', File::Spec->updir, 'spec', 'with-deep-mixed-ref.json'], ); for my $pathlist (@pathlists) { - my $file = path(path(__FILE__)->dirname, @$pathlist); - $bundled = $validator->schema($file)->bundle({ref_key => 'definitions'}); + my $file = path $workdir, @$pathlist; + $bundled = $jv->schema($file)->bundle({ref_key => 'definitions'}); is_deeply [sort map { s!^[a-z0-9]{10}!SHA!; $_ } - keys %{$bundled->{definitions}}], [ - qw( + keys %{$bundled->{definitions}}], + [qw( SHA-age.json SHA-unit.json SHA-weight.json height - ) - ], + )], 'right definitions in disk spec' or diag explain $bundled->{definitions}; } -# ensure filenames with funny characters not mangled by Mojo::URL -my $file3 = path(__FILE__)->sibling('spec', 'space bundle.json'); -eval { $bundled = $validator->schema($file3)->bundle }; +note 'ensure filenames with funny characters not mangled by Mojo::URL'; +my $file3 = path $workdir, 'spec', 'space bundle.json'; +eval { $bundled = $jv->schema($file3)->bundle }; is $@, '', 'loaded absolute filename with space'; is $bundled->{properties}{age}{description}, 'Age in years', 'right definitions in disk spec' or diag explain $bundled; +note 'extract subset of schema'; +$bundled = $jv->bundle({ + ref_key => 'definitions', + schema => $jv->schema('data://main/api.json')->get([qw(paths /withdots get)]) +}); +is_deeply( + $bundled, + { + definitions => { + data___main_api_json__definitions_objtype => + {properties => {propname => {type => 'string'}}, type => 'object'} + }, + responses => { + 200 => { + schema => + {'$ref' => '#/definitions/data___main_api_json__definitions_objtype'} + } + } + }, + 'subset of schema was bundled' +) or diag explain $bundled; + +note 'no leaking path'; +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'}); +is_deeply [grep { 0 == index $_, $ref_name_prefix } keys %{$bundled->{xyz}}], + [], 'no leaking of path'; + done_testing; __DATA__ - @@ api.json { "definitions" : { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/coerce.t new/JSON-Validator-3.07/t/coerce.t --- old/JSON-Validator-3.06/t/coerce.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/coerce.t 2019-04-04 18:41:08.000000000 +0200 @@ -3,15 +3,11 @@ use Mojo::JSON 'to_json'; use Test::More; -my $validator = JSON::Validator->new; +my $jv = JSON::Validator->new; my %coerce = (booleans => 1); +is_deeply($jv->coerce(%coerce)->coerce, {booleans => 1}, 'hash is accepted'); is_deeply( - $validator->coerce(%coerce)->coerce, - {booleans => 1}, - 'hash is accepted' -); -is_deeply( - $validator->coerce(\%coerce)->coerce, + $jv->coerce(\%coerce)->coerce, {booleans => 1}, 'hash reference is accepted' ); @@ -19,7 +15,7 @@ note 'coerce(1) is here for back compat reasons, even though not documented any more'; is_deeply( - $validator->coerce(1)->coerce, + $jv->coerce(1)->coerce, {%coerce, numbers => 1, strings => 1}, '1 is accepted' ); @@ -29,17 +25,17 @@ for my $i (@items) { for my $schema (schemas($i->[0])) { my $x = $i->[1]; - $validator->validate($x, $schema); + $jv->validate($x, $schema); is to_json($x), $i->[1], sprintf 'no quotes around %s %s', $i->[0], to_json($schema); $x = {v => $i->[1]}; - $validator->validate($x, {type => 'object', properties => {v => $schema}}); + $jv->validate($x, {type => 'object', properties => {v => $schema}}); is to_json($x->{v}), $i->[1], sprintf 'no quotes around %s %s', $i->[0], to_json($schema); $x = [$i->[1]]; - $validator->validate($x, {type => 'array', items => $schema}); + $jv->validate($x, {type => 'array', items => $schema}); is to_json($x->[0]), $i->[1], sprintf 'no quotes around %s %s', $i->[0], to_json($schema); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/deep-mixed-ref.t new/JSON-Validator-3.07/t/deep-mixed-ref.t --- old/JSON-Validator-3.06/t/deep-mixed-ref.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/deep-mixed-ref.t 2019-04-04 18:41:08.000000000 +0200 @@ -3,19 +3,18 @@ use JSON::Validator; use Mojo::File 'path'; -my $workdir = path(__FILE__)->dirname; -my $file = path($workdir, 'spec', 'with-deep-mixed-ref.json'); -my $validator = JSON::Validator->new(cache_paths => [])->schema($file); -my @errors = $validator->validate( +my $workdir = path(__FILE__)->dirname; +my $file = path($workdir, 'spec', 'with-deep-mixed-ref.json'); +my $jv = JSON::Validator->new(cache_paths => [])->schema($file); +my @errors = $jv->validate( {age => 1, weight => {mass => 72, unit => 'kg'}, height => 100}); is int(@errors), 0, 'valid input'; use Mojolicious::Lite; push @{app->static->paths}, $workdir; -$validator->ua(app->ua); -$validator->schema( - app->ua->server->url->clone->path('/spec/with-relative-ref.json')); -@errors = $validator->validate({age => 'not a number'}); +$jv->ua(app->ua); +$jv->schema(app->ua->server->url->clone->path('/spec/with-relative-ref.json')); +@errors = $jv->validate({age => 'not a number'}); is int(@errors), 1, 'invalid age'; done_testing; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/issue-42-cache-control.t new/JSON-Validator-3.07/t/issue-42-cache-control.t --- old/JSON-Validator-3.06/t/issue-42-cache-control.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/issue-42-cache-control.t 2019-04-04 18:41:08.000000000 +0200 @@ -5,23 +5,24 @@ plan skip_all => 'TEST_ONLINE=1' unless $ENV{TEST_ONLINE}; -$ENV{JSON_VALIDATOR_CACHE_DIR} = '/tmp/whatever'; -my $validator = JSON::Validator->new; -my @old_files = get_cached_files($validator); - -is $validator->cache_paths->[0], '/tmp/whatever', 'back compat env'; -shift @{$validator->cache_paths}; - -$validator->schema('https://za.payprop.com/api/docs/api_spec.yaml'); -my @new_files = get_cached_files($validator); +$ENV{JSON_VALIDATOR_CACHE_PATH} = '/tmp/whatever'; +my $jv = JSON::Validator->new; +my @old_files = get_cached_files($jv); + +is $jv->cache_paths->[0], '/tmp/whatever', 'back compat env'; +shift @{$jv->cache_paths}; + +my $spec_url = 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json'; +$jv->schema($spec_url); +my @new_files = get_cached_files($jv); ok @old_files == @new_files, 'remote file not cached in default cache dir'; my $tempdir = tempdir; $ENV{JSON_VALIDATOR_CACHE_PATH} = join ':', $tempdir->dirname, '/tmp/whatever'; -$validator = JSON::Validator->new; -is $validator->cache_paths->[0], $tempdir->dirname, 'env'; -$validator->schema('https://za.payprop.com/api/docs/api_spec.yaml'); -@new_files = get_cached_files($validator); +$jv = JSON::Validator->new; +is $jv->cache_paths->[0], $tempdir->dirname, 'env'; +$jv->schema($spec_url); +@new_files = get_cached_files($jv); ok @new_files > @old_files, 'remote file cached when cache_paths not the default' or diag join "\n", @new_files; @@ -29,6 +30,6 @@ done_testing; sub get_cached_files { - my ($validator) = @_; - return sort map { glob "$_/*" } @{$validator->cache_paths}; + my ($jv) = @_; + return sort map { glob "$_/*" } @{$jv->cache_paths}; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/issue-59-oneof-blessed-booleans.t new/JSON-Validator-3.07/t/issue-59-oneof-blessed-booleans.t --- old/JSON-Validator-3.06/t/issue-59-oneof-blessed-booleans.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/issue-59-oneof-blessed-booleans.t 2019-04-04 18:41:08.000000000 +0200 @@ -3,9 +3,9 @@ use Mojo::JSON; use JSON::Validator; -my $validator = JSON::Validator->new->schema('data://main/spec.json'); -my @errors = $validator->validate( - {prop1 => Mojo::JSON->false, prop2 => Mojo::JSON->false}); +my $jv = JSON::Validator->new->schema('data://main/spec.json'); +my @errors + = $jv->validate({prop1 => Mojo::JSON->false, prop2 => Mojo::JSON->false}); is "@errors", ""; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/jv-boolean.t new/JSON-Validator-3.07/t/jv-boolean.t --- old/JSON-Validator-3.06/t/jv-boolean.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/jv-boolean.t 2019-04-04 18:41:08.000000000 +0200 @@ -22,7 +22,7 @@ E('/', 'Expected boolean - got string.'); validate_ok undef, {properties => {}}, E('/', 'Expected object - got null.'); -t::Helper->validator->coerce(1); +jv->coerce(1); validate_ok {nick => 1000}, $schema; validate_ok {nick => 0.5}, $schema; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/jv-integer.t new/JSON-Validator-3.07/t/jv-integer.t --- old/JSON-Validator-3.06/t/jv-integer.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/jv-integer.t 2019-04-04 18:41:08.000000000 +0200 @@ -18,7 +18,7 @@ $schema->{properties}{mynumber}{multipleOf} = 2; validate_ok {mynumber => 3}, $schema, E('/mynumber', 'Not multiple of 2.'); -t::Helper->validator->coerce(numbers => 1); +jv->coerce(numbers => 1); validate_ok {mynumber => '2'}, $schema; validate_ok {mynumber => '2xyz'}, $schema, E('/mynumber', 'Expected integer - got string.'); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/jv-number.t new/JSON-Validator-3.07/t/jv-number.t --- old/JSON-Validator-3.06/t/jv-number.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/jv-number.t 2019-04-04 18:41:08.000000000 +0200 @@ -11,7 +11,7 @@ validate_ok {mynumber => '2'}, $schema, E('/mynumber', 'Expected number - got string.'); -t::Helper->validator->coerce(numbers => 1); +jv->coerce(numbers => 1); validate_ok {mynumber => '-0.3'}, $schema; validate_ok {mynumber => '0.1e+1'}, $schema; validate_ok {mynumber => '2xyz'}, $schema, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/jv-string.t new/JSON-Validator-3.07/t/jv-string.t --- old/JSON-Validator-3.06/t/jv-string.t 2019-01-20 23:31:14.000000000 +0100 +++ new/JSON-Validator-3.07/t/jv-string.t 2019-04-04 18:41:08.000000000 +0200 @@ -18,13 +18,13 @@ validate_ok {nick => 'aa'}, $schema, E('/nick', 'String is too short: 2/3.'); validate_ok {nick => 'a' x 11}, $schema, E('/nick', 'String is too long: 11/10.'); -like +join('', t::Helper->validator->validate({nick => '[nick]'})), +like +join('', jv->validate({nick => '[nick]'})), qr{/nick: String does not match}, 'String does not match'; delete $schema->{properties}{nick}{pattern}; validate_ok {nick => 'Déjà vu'}, $schema; -t::Helper->validator->coerce(1); +jv->coerce(1); validate_ok {nick => 1000}, $schema; # https://github.com/mojolicious/json-validator/issues/134 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/load-data.t new/JSON-Validator-3.07/t/load-data.t --- old/JSON-Validator-3.06/t/load-data.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/load-data.t 2019-04-04 18:41:08.000000000 +0200 @@ -2,9 +2,9 @@ use Test::More; use JSON::Validator; - my $validator = JSON::Validator->new; - my @errors = $validator->schema('data://main/spec.json') - ->validate({firstName => 'yikes!'}); + my $jv = JSON::Validator->new; + my @errors + = $jv->schema('data://main/spec.json')->validate({firstName => 'yikes!'}); is int(@errors), 1, 'one error'; is $errors[0]->path, '/lastName', 'lastName'; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/load-file.t new/JSON-Validator-3.07/t/load-file.t --- old/JSON-Validator-3.06/t/load-file.t 2019-01-20 23:31:14.000000000 +0100 +++ new/JSON-Validator-3.07/t/load-file.t 2019-04-04 18:41:08.000000000 +0200 @@ -2,12 +2,12 @@ use Test::More; use JSON::Validator; -my $spec = Mojo::File::path(qw(t spec person.json))->to_abs; -my $validator = JSON::Validator->new; +my $spec = Mojo::File::path(qw(t spec person.json))->to_abs; +my $jv = JSON::Validator->new; note "file://$spec"; -ok eval { $validator->schema("file://$spec") }, 'loaded from file://'; -isa_ok($validator->schema, 'Mojo::JSON::Pointer'); -is $validator->schema->get('/title'), 'Example Schema', 'got example schema'; +ok eval { $jv->schema("file://$spec") }, 'loaded from file://'; +isa_ok($jv->schema, 'Mojo::JSON::Pointer'); +is $jv->schema->get('/title'), 'Example Schema', 'got example schema'; done_testing; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/load-http.t new/JSON-Validator-3.07/t/load-http.t --- old/JSON-Validator-3.06/t/load-http.t 2019-01-05 04:56:18.000000000 +0100 +++ new/JSON-Validator-3.07/t/load-http.t 2019-04-04 18:41:08.000000000 +0200 @@ -4,13 +4,13 @@ plan skip_all => 'TEST_ONLINE=1' unless $ENV{TEST_ONLINE}; -my $validator = JSON::Validator->new; +my $jv = JSON::Validator->new; -$validator->schema('http://swagger.io/v2/schema.json'); +$jv->schema('http://swagger.io/v2/schema.json'); -isa_ok($validator->schema, 'Mojo::JSON::Pointer'); -like $validator->schema->get('/title'), qr{swagger}i, 'got swagger spec'; -ok $validator->schema->get('/patternProperties/^x-/description'), +isa_ok($jv->schema, 'Mojo::JSON::Pointer'); +like $jv->schema->get('/title'), qr{swagger}i, 'got swagger spec'; +ok $jv->schema->get('/patternProperties/^x-/description'), 'resolved vendorExtension $ref'; done_testing; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/load-json.t new/JSON-Validator-3.07/t/load-json.t --- old/JSON-Validator-3.06/t/load-json.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/load-json.t 2019-04-04 18:41:08.000000000 +0200 @@ -3,9 +3,9 @@ use JSON::Validator; use Mojo::File 'path'; -my $file = path(path(__FILE__)->dirname, 'spec', 'person.json'); -my $validator = JSON::Validator->new->schema($file); -my @errors = $validator->validate({firstName => 'yikes!'}); +my $file = path(path(__FILE__)->dirname, 'spec', 'person.json'); +my $jv = JSON::Validator->new->schema($file); +my @errors = $jv->validate({firstName => 'yikes!'}); is int(@errors), 1, 'one error'; is $errors[0]->path, '/lastName', 'lastName'; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/load-yaml.t new/JSON-Validator-3.07/t/load-yaml.t --- old/JSON-Validator-3.06/t/load-yaml.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/load-yaml.t 2019-04-04 18:41:08.000000000 +0200 @@ -2,10 +2,10 @@ use Test::More; use JSON::Validator; -plan skip_all => $@ unless eval { JSON::Validator::_yaml_module() }; +plan skip_all => 'YAML::XS required' unless $JSON::Validator::YAML_LOADER; -my $validator = JSON::Validator->new; -my @errors = $validator->schema('data://Some::Module/s_pec-/-ficaTion') +my $jv = JSON::Validator->new; +my @errors = $jv->schema('data://Some::Module/s_pec-/-ficaTion') ->validate({firstName => 'yikes!'}); is int(@errors), 1, 'one error'; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/random-errors.t new/JSON-Validator-3.07/t/random-errors.t --- old/JSON-Validator-3.06/t/random-errors.t 2018-12-15 05:25:31.000000000 +0100 +++ new/JSON-Validator-3.07/t/random-errors.t 2019-04-04 18:41:08.000000000 +0200 @@ -7,7 +7,7 @@ plan skip_all => 'TEST_RANDOM_ITERATIONS=10000' unless my $iterations = $ENV{TEST_RANDOM_ITERATIONS}; -my $validator = JSON::Validator->new->schema({ +my $jv = JSON::Validator->new->schema({ items => { properties => { prop1 => {type => [qw(string null)]}, @@ -28,7 +28,7 @@ my @errors; for (1 .. $iterations) { push @errors, - $validator->validate([{ + $jv->validate([{ prop1 => undef, prop2 => undef, prop3 => undef, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/relative-ref.t new/JSON-Validator-3.07/t/relative-ref.t --- old/JSON-Validator-3.06/t/relative-ref.t 2018-12-15 05:21:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/relative-ref.t 2019-04-04 18:41:08.000000000 +0200 @@ -3,12 +3,12 @@ use Mojo::File 'path'; my $file = path(path(__FILE__)->dirname, 'spec', 'with-relative-ref.json'); -my $validator = t::Helper->validator->cache_paths([]); +my $jv = jv->cache_paths([]); validate_ok {age => -1}, $file, E('/age', '-1 < minimum(0)'); use Mojolicious::Lite; push @{app->static->paths}, path(__FILE__)->dirname; -$validator->ua(app->ua); +$jv->ua(app->ua); validate_ok {age => -2}, app->ua->server->url->clone->path('/spec/with-relative-ref.json'), E('/age', '-2 < minimum(0)'); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/JSON-Validator-3.06/t/spec/bundle-no-leaking-filename.json new/JSON-Validator-3.07/t/spec/bundle-no-leaking-filename.json --- old/JSON-Validator-3.06/t/spec/bundle-no-leaking-filename.json 1970-01-01 01:00:00.000000000 +0100 +++ new/JSON-Validator-3.07/t/spec/bundle-no-leaking-filename.json 2019-04-04 18:41:35.000000000 +0200 @@ -0,0 +1,4 @@ +{ + "type": "object", + "properties": { "$ref": "./with-deep-mixed-ref.json#/properties" } +}