| 1 | package JSON::Validator::Schema::Draft6; | ||||||||||||||||||||||||||||
| 2 | 22 | ▶ | use Mojo::Base 'JSON::Validator::Schema'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 22 | ▶ | use JSON::Validator::Schema::Draft4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 22 | ▶ | use JSON::Validator::URI qw(uri); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 22 | ▶ | use JSON::Validator::Util qw(E data_type is_type prefix_errors); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | has id => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 9 | 1 | my $data = shift->data; | |||||||||||||||||||||||||||
| 10 | 1 | ▶ | return is_type($data, 'HASH') ? $data->{'$id'} || '' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$data->{"\$id"} or ""
MC/DC0%0/1
$data->{"\$id"} or ""
$data->{"\$id"}
Truth table50%1/2
A
A= $data->{"\$id"}
| |||||||||||||||||||||||||||||
| 11 | 22 | }; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 22 | has specification => 'http://json-schema.org/draft-06/schema#'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub _build_formats { | ||||||||||||||||||||||||||
|
Subroutine
_build_formats: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 16 | return { | ||||||||||||||||||||||||||||
| 17 | 0 | 'date-time' => JSON::Validator::Formats->can('check_date_time'), | |||||||||||||||||||||||||||
| 18 | 'email' => JSON::Validator::Formats->can('check_email'), | ||||||||||||||||||||||||||||
| 19 | 'hostname' => JSON::Validator::Formats->can('check_hostname'), | ||||||||||||||||||||||||||||
| 20 | 'ipv4' => JSON::Validator::Formats->can('check_ipv4'), | ||||||||||||||||||||||||||||
| 21 | 'ipv6' => JSON::Validator::Formats->can('check_ipv6'), | ||||||||||||||||||||||||||||
| 22 | 'json-pointer' => JSON::Validator::Formats->can('check_json_pointer'), | ||||||||||||||||||||||||||||
| 23 | 'regex' => JSON::Validator::Formats->can('check_regex'), | ||||||||||||||||||||||||||||
| 24 | 'relative-json-pointer' => JSON::Validator::Formats->can('check_relative_json_pointer'), | ||||||||||||||||||||||||||||
| 25 | 'uri' => JSON::Validator::Formats->can('check_uri'), | ||||||||||||||||||||||||||||
| 26 | 'uri-reference' => JSON::Validator::Formats->can('check_uri_reference'), | ||||||||||||||||||||||||||||
| 27 | 'uri-template' => JSON::Validator::Formats->can('check_uri_template'), | ||||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1382 | ▶ | sub _resolve_object { | ||||||||||||||||||||||||||
|
Subroutine
_resolve_object: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 32 | 1382 | my ($self, $state, $schema, $refs, $found) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1382 | ▶ | if ($schema->{'$id'} and !ref $schema->{'$id'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$schema->{"\$id"} and not ref $schema->{"\$id"}
MC/DC100%2/2
$schema->{"\$id"} and not ref $schema->{"\$id"}
$schema->{"\$id"}
not ref $schema->{"\$id"}
Truth table100%3/3
A and not(B)
A= $schema->{"\$id"}B= not ref $schema->{"\$id"}
| |||||||||||||||||||||||||||||
| 35 | 18 | my $id = uri $schema->{'$id'}, $state->{base_url}; | |||||||||||||||||||||||||||
| 36 | 18 | $self->store->add($id => $schema); | |||||||||||||||||||||||||||
| 37 | 18 | $state = {%$state, base_url => $id->fragment(undef)->to_string}; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1382 | ▶ | if ($found->{'$ref'} = $schema->{'$ref'} && !ref $schema->{'$ref'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$schema->{'$ref'} && !ref($schema->{'$ref'})
MC/DC100%2/2
$schema->{'$ref'} && !ref($schema->{'$ref'})
$schema->{'$ref'}
!ref($schema->{'$ref'})
Truth table100%3/3
A && not(B)
A= $schema->{'$ref'}B= !ref($schema->{'$ref'})
| |||||||||||||||||||||||||||||
| 41 | 500 | push @$refs, [$schema, $state]; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1382 | return $state; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 112 | ▶ | sub _validate_number_max { | ||||||||||||||||||||||||||
|
Subroutine
_validate_number_max: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 48 | 112 | my ($self, $value, $state, $expected) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 112 | my $cmp_with = $state->{schema}{maximum}; | |||||||||||||||||||||||||||
| 51 | 112 | ▶ | return E $state->{path}, [$expected => maximum => $value, $cmp_with] if defined $cmp_with and $value > $cmp_with; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cmp_with and $value > $cmp_with
MC/DC100%2/2
defined $cmp_with and $value > $cmp_with
defined $cmp_with
$value > $cmp_with
Truth table100%3/3
A and B
A= defined $cmp_withB= $value > $cmp_with
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 109 | $cmp_with = $state->{schema}{exclusiveMaximum}; | |||||||||||||||||||||||||||
| 54 | 109 | ▶ | return E $state->{path}, [$expected => ex_maximum => $value, $cmp_with] if defined $cmp_with and $value >= $cmp_with; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cmp_with and $value >= $cmp_with
MC/DC50%1/2
defined $cmp_with and $value >= $cmp_with
defined $cmp_with
$value >= $cmp_with
Truth table66%2/3
A and B
A= defined $cmp_withB= $value >= $cmp_with
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 105 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 112 | ▶ | sub _validate_number_min { | ||||||||||||||||||||||||||
|
Subroutine
_validate_number_min: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 60 | 112 | my ($self, $value, $state, $expected) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 112 | my $cmp_with = $state->{schema}{minimum}; | |||||||||||||||||||||||||||
| 63 | 112 | ▶ | return E $state->{path}, [$expected => minimum => $value, $cmp_with] if defined $cmp_with and $value < $cmp_with; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cmp_with and $value < $cmp_with
MC/DC100%2/2
defined $cmp_with and $value < $cmp_with
defined $cmp_with
$value < $cmp_with
Truth table100%3/3
A and B
A= defined $cmp_withB= $value < $cmp_with
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 108 | $cmp_with = $state->{schema}{exclusiveMinimum}; | |||||||||||||||||||||||||||
| 66 | 108 | ▶ | return E $state->{path}, [$expected => ex_minimum => $value, $cmp_with] if defined $cmp_with and $value <= $cmp_with; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cmp_with and $value <= $cmp_with
MC/DC50%1/2
defined $cmp_with and $value <= $cmp_with
defined $cmp_with
$value <= $cmp_with
Truth table66%2/3
A and B
A= defined $cmp_withB= $value <= $cmp_with
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 104 | return; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 86 | ▶ | sub _validate_type_array { | ||||||||||||||||||||||||||
|
Subroutine
_validate_type_array: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 72 | 86 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||
| 73 | 86 | ▶ | return E $state->{path}, [array => type => data_type $data] if ref $data ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | return ( | ||||||||||||||||||||||||||||
| 76 | 83 | $self->_validate_type_array_min_max($_[1], $state), | |||||||||||||||||||||||||||
| 77 | $self->_validate_type_array_unique($_[1], $state), | ||||||||||||||||||||||||||||
| 78 | $self->_validate_type_array_contains($_[1], $state), | ||||||||||||||||||||||||||||
| 79 | $self->_validate_type_array_items($_[1], $state), | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 20 | ▶ | sub _validate_type_array_contains { | ||||||||||||||||||||||||||
|
Subroutine
_validate_type_array_contains: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 84 | 20 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||
| 85 | 20 | ▶ | return unless exists $state->{schema}{contains}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | my (@e, @errors); | |||||||||||||||||||||||||||
| 88 | 4 | for my $i (0 .. @$data - 1) { | |||||||||||||||||||||||||||
| 89 | my @tmp = $self->_validate($data->[$i], | ||||||||||||||||||||||||||||
| 90 | 8 | $self->_state($state, path => [@{$state->{path}}, $i], schema => $state->{schema}{contains})); | |||||||||||||||||||||||||||
| 91 | 8 | ▶ | push @e, \@tmp if @tmp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 4 | ▶ | push @errors, map {@$_} @e if @e >= @$data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 4 | ▶ | push @errors, E $state->{path}, [array => 'contains'] if not @$data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 4 | return @errors; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 10884 | ▶ | sub _validate_type_object { | ||||||||||||||||||||||||||
|
Subroutine
_validate_type_object: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 100 | 10884 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||
| 101 | 10884 | ▶ | return E $state->{path}, [object => type => data_type $data] if ref $data ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | return ( | ||||||||||||||||||||||||||||
| 104 | 10873 | $self->_validate_type_object_min_max($_[1], $state), | |||||||||||||||||||||||||||
| 105 | $self->_validate_type_object_names($_[1], $state), | ||||||||||||||||||||||||||||
| 106 | $self->_validate_type_object_properties($_[1], $state), | ||||||||||||||||||||||||||||
| 107 | $self->_validate_type_object_dependencies($_[1], $state), | ||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 10873 | ▶ | sub _validate_type_object_names { | ||||||||||||||||||||||||||
|
Subroutine
_validate_type_object_names: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 112 | 10873 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||
| 113 | 10873 | ▶ | return unless exists $state->{schema}{propertyNames}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 12 | my @errors; | |||||||||||||||||||||||||||
| 116 | 12 | for my $name (keys %$data) { | |||||||||||||||||||||||||||
| 117 | 18 | ▶ | next unless my @e = $self->_validate($name, $self->_state($state, schema => $state->{schema}{propertyNames})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 6 | push @errors, prefix_errors propertyName => map [$name, $_], @e; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 12 | return @errors; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 22 | *_validate_type_array_items = \&JSON::Validator::Schema::Draft4::_validate_type_array_items; | |||||||||||||||||||||||||||
| 125 | 22 | *_validate_type_array_min_max = \&JSON::Validator::Schema::Draft4::_validate_type_array_min_max; | |||||||||||||||||||||||||||
| 126 | 22 | *_validate_type_array_unique = \&JSON::Validator::Schema::Draft4::_validate_type_array_unique; | |||||||||||||||||||||||||||
| 127 | 22 | *_validate_type_object_dependencies = \&JSON::Validator::Schema::Draft4::_validate_type_object_dependencies; | |||||||||||||||||||||||||||
| 128 | 22 | *_validate_type_object_min_max = \&JSON::Validator::Schema::Draft4::_validate_type_object_min_max; | |||||||||||||||||||||||||||
| 129 | 22 | *_validate_type_object_properties = \&JSON::Validator::Schema::Draft4::_validate_type_object_properties; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 22 | 1; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =encoding utf8 | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head1 NAME | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | JSON::Validator::Schema::Draft6 - JSON-Schema Draft 6 | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | See L<JSON::Validator::Schema/SYNOPSIS>. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | This class represents | ||||||||||||||||||||||||||||
| 146 | L<https://json-schema.org/specification-links.html#draft-6>. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head2 specification | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | my $str = $schema->specification; | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | Defaults to "L<http://json-schema.org/draft-06/schema#>". | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | L<JSON::Validator::Schema>. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||