| 1 | package JSON::Validator::Schema::Draft4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 38 | ▶ | use Mojo::Base 'JSON::Validator::Schema'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 38 | ▶ | use JSON::Validator::Util qw(E data_checksum data_type is_type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 38 | ▶ | use List::Util 'uniq'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 31 | ▶ | has id => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 31 | my $data = shift->data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 31 | ▶ | return is_type($data, 'HASH') ? $data->{id} || '' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$data->{"id"} or ""
MC/DC100%1/1
$data->{"id"} or ""
$data->{"id"}
Truth table100%2/2
A
A= $data->{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 38 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 38 | has specification => 'http://json-schema.org/draft-04/schema#'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | sub _build_formats { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_formats: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | 'date-time' => JSON::Validator::Formats->can('check_date_time'), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 'email' => JSON::Validator::Formats->can('check_email'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'hostname' => JSON::Validator::Formats->can('check_hostname'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 'ipv4' => JSON::Validator::Formats->can('check_ipv4'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'ipv6' => JSON::Validator::Formats->can('check_ipv6'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'regex' => JSON::Validator::Formats->can('check_regex'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'uri' => JSON::Validator::Formats->can('check_uri'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 47 | ▶ | sub _validate_number_max { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_number_max: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 47 | my ($self, $value, $state, $expected) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 47 | ▶ | return unless defined(my $cmp_with = $state->{schema}{maximum}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | my $key = $state->{schema}{exclusiveMaximum} ? 'ex_maximum' : 'maximum'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | return if $key eq 'maximum' ? $value <= $cmp_with : $value < $cmp_with; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | return E $state->{path}, [$expected => $key => $value, $cmp_with]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 47 | ▶ | sub _validate_number_min { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_number_min: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 47 | my ($self, $value, $state, $expected) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 47 | ▶ | return unless defined(my $cmp_with = $state->{schema}{minimum}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | my $key = $state->{schema}{exclusiveMinimum} ? 'ex_minimum' : 'minimum'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | ▶ | return if $key eq 'minimum' ? $value >= $cmp_with : $value > $cmp_with; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | return E $state->{path}, [$expected => $key => $value, $cmp_with]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 158 | ▶ | sub _validate_type_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_array: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 158 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 158 | ▶ | return E $state->{path}, [array => type => data_type $data] if ref $data ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 157 | $self->_validate_type_array_min_max($_[1], $state), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $self->_validate_type_array_unique($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $self->_validate_type_array_items($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 240 | ▶ | sub _validate_type_array_items { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_array_items: called CC=10 SCAR=36.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 240 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 240 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 240 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 240 | ▶ | if (ref $schema->{items} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $additional_items = $schema->{additionalItems} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$schema->{"additionalItems"} // {}
MC/DC0%0/1
$schema->{"additionalItems"} // {}
$schema->{"additionalItems"}
Truth table0%0/2
A
A= $schema->{"additionalItems"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my @rules = @{$schema->{items}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($additional_items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | push @rules, $additional_items while @rules < @$data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (@rules >= @$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | for my $i (0 .. @$data - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | push @errors, $self->_validate($data->[$i], $self->_state($state, path => [@$path, $i], schema => $rules[$i])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | elsif (!$additional_items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | push @errors, E $path, [array => additionalItems => int(@$data), int(@rules)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | elsif (exists $schema->{items}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 211 | for my $i (0 .. @$data - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | push @errors, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 182 | $self->_validate($data->[$i], $self->_state($state, path => [@$path, $i], schema => $schema->{items})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 240 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 240 | ▶ | sub _validate_type_array_min_max { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_array_min_max: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 240 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 240 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 240 | ▶ | if (defined $state->{schema}{minItems} and $state->{schema}{minItems} > @$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $state->{"schema"}{"minItems"} and $state->{"schema"}{"minItems"} > @$data
MC/DC100%2/2
defined $state->{"schema"}{"minItems"} and $state->{"schema"}{"minItems"} > @$data
defined $state->{"schema"}{"minItems"}
$state->{"schema"}{"minItems"} > @$data
Truth table100%3/3
A and B
A= defined $state->{"schema"}{"minItems"}B= $state->{"schema"}{"minItems"} > @$data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 9 | push @errors, E $state->{path}, [array => minItems => int(@$data), $state->{schema}{minItems}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 240 | ▶ | if (defined $state->{schema}{maxItems} and $state->{schema}{maxItems} < @$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $state->{"schema"}{"maxItems"} and $state->{"schema"}{"maxItems"} < @$data
MC/DC100%2/2
defined $state->{"schema"}{"maxItems"} and $state->{"schema"}{"maxItems"} < @$data
defined $state->{"schema"}{"maxItems"}
$state->{"schema"}{"maxItems"} < @$data
Truth table100%3/3
A and B
A= defined $state->{"schema"}{"maxItems"}B= $state->{"schema"}{"maxItems"} < @$data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | push @errors, E $state->{path}, [array => maxItems => int(@$data), $state->{schema}{maxItems}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 240 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 240 | ▶ | sub _validate_type_array_unique { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_array_unique: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 240 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 240 | ▶ | return unless $state->{schema}{uniqueItems}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 39 | my (@errors, %uniq); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 39 | for (@$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 56 | ▶ | next if !$uniq{data_checksum($_)}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | push @errors, E $state->{path}, [array => 'uniqueItems']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 39 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 298 | ▶ | sub _validate_type_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 298 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 298 | ▶ | return E $state->{path}, [object => type => data_type $data] if ref $data ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 295 | $self->_validate_type_object_min_max($_[1], $state), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $self->_validate_type_object_dependencies($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | $self->_validate_type_object_properties($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 11263 | ▶ | sub _validate_type_object_min_max { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object_min_max: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 11263 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 11263 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 11263 | my @dkeys = keys %$data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 11263 | ▶ | if (defined $state->{schema}{maxProperties} and $state->{schema}{maxProperties} < @dkeys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $state->{"schema"}{"maxProperties"} and $state->{"schema"}{"maxProperties"} < @dkeys
MC/DC100%2/2
defined $state->{"schema"}{"maxProperties"} and $state->{"schema"}{"maxProperties"} < @dkeys
defined $state->{"schema"}{"maxProperties"}
$state->{"schema"}{"maxProperties"} < @dkeys
Truth table100%3/3
A and B
A= defined $state->{"schema"}{"maxProperties"}B= $state->{"schema"}{"maxProperties"} < @dkeys
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | push @errors, E $state->{path}, [object => maxProperties => int(@dkeys), $state->{schema}{maxProperties}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 11263 | ▶ | if (defined $state->{schema}{minProperties} and $state->{schema}{minProperties} > @dkeys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $state->{"schema"}{"minProperties"} and $state->{"schema"}{"minProperties"} > @dkeys
MC/DC100%2/2
defined $state->{"schema"}{"minProperties"} and $state->{"schema"}{"minProperties"} > @dkeys
defined $state->{"schema"}{"minProperties"}
$state->{"schema"}{"minProperties"} > @dkeys
Truth table100%3/3
A and B
A= defined $state->{"schema"}{"minProperties"}B= $state->{"schema"}{"minProperties"} > @dkeys
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | push @errors, E $state->{path}, [object => minProperties => int(@dkeys), $state->{schema}{minProperties}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 11263 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 588 | ▶ | sub _validate_type_object_dependencies { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object_dependencies: called CC=5 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 588 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 588 | ▶ | my $dependencies = $state->{schema}{dependencies} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$state->{'schema'}{'dependencies'} || {}
MC/DC100%1/1
$state->{'schema'}{'dependencies'} || {}
$state->{'schema'}{'dependencies'}
Truth table100%2/2
A
A= $state->{'schema'}{'dependencies'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 588 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 588 | for my $k (keys %$dependencies) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 30 | ▶ | next if not exists $data->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if (ref $dependencies->{$k} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | push @errors, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | map { E [@{$state->{path}}, $_], [object => dependencies => $k] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | grep { !exists $data->{$_} } @{$dependencies->{$k}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | push @errors, $self->_validate($data, $self->_state($state, schema => $dependencies->{$k})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 588 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 11263 | ▶ | sub _validate_type_object_properties { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object_properties: called CC=31 SCAR=34.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 11263 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 11263 | my ($path, $schema, @errors, %rules) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 11263 | my $defaults = $self->{coerce}{defaults}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 11263 | my @dkeys = keys %$data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 11263 | ▶ | if (my $properties = $schema->{properties}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 7294 | ▶ | if ($defaults) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | push @{$rules{$_}}, $properties->{$_} for keys %$properties; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 7292 | ▶ | defined $properties->{$_} && push @{$rules{$_}}, $properties->{$_} for @dkeys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 11263 | ▶ | for my $p (keys %{$schema->{patternProperties} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'patternProperties'} || {}
MC/DC100%1/1
$schema->{'patternProperties'} || {}
$schema->{'patternProperties'}
Truth table100%2/2
A
A= $schema->{'patternProperties'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2561 | my $r = $schema->{patternProperties}{$p}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2561 | push @{$rules{$_}}, $r for grep /$p/, @dkeys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 11263 | ▶ | my $additional = exists $schema->{additionalProperties} ? $schema->{additionalProperties} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 11263 | ▶ | if ($additional) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 10830 | ▶ | $additional = {} unless is_type $additional, 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 10830 | ▶ | $rules{$_} ||= [$additional] for @dkeys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rules{$_} ||= [$additional]
MC/DC100%1/1
$rules{$_} ||= [$additional]
$rules{$_}
Truth table100%2/2
A
A= $rules{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 946 | elsif (my @k = grep { !$rules{$_} } @dkeys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 137 | local $" = ', '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 137 | return E $path, [object => additionalProperties => join ', ', sort @k]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 11126 | ▶ | for my $k (uniq @{$schema->{required} || []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'required'} || []
MC/DC100%1/1
$schema->{'required'} || []
$schema->{'required'}
Truth table100%2/2
A
A= $schema->{'required'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 8589 | ▶ | next if exists $data->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 2289 | push @errors, E [@$path, $k], [object => 'required']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2289 | delete $rules{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 11126 | for my $k (keys %rules) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 35900 | for my $r (@{$rules{$k}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 35900 | ▶ | next if !exists $data->{$k} and !$defaults; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $data->{$k} or $defaults
MC/DC0%0/2
exists $data->{$k} or $defaults
exists $data->{$k}
$defaults
Truth table66%2/3
A or B
A= exists $data->{$k}B= $defaults
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 35900 | my $s2 = $self->_state($state, path => [@$path, $k], schema => $r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 35900 | ▶ | if ($defaults and ref $s2->{schema} eq 'HASH' and exists $s2->{schema}{default} and !exists $data->{$k}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$defaults and ref $s2->{"schema"} eq "HASH" and exists $s2->{"schema"}{"default"} and not exists $data->{$k}
$defaults and ref $s2->{"schema"} eq "HASH" and exists $s2->{"schema"}{"default"}
$defaults and ref $s2->{"schema"} eq "HASH"
MC/DC50%2/4
$defaults and ref $s2->{"schema"} eq "HASH" and exists $s2->{"schema"}{"default"} and not exists $data->{$k}
$defaults
ref $s2->{"schema"} eq "HASH"
exists $s2->{"schema"}{"default"}
not exists $data->{$k}
Truth table60%3/5
A and B and C and not(D)
A= $defaultsB= ref $s2->{"schema"} eq "HASH"C= exists $s2->{"schema"}{"default"}D= not exists $data->{$k}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | $data->{$k} = $s2->{schema}{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 35900 | ▶ | next if !exists $data->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 35900 | my @e = $self->_validate($data->{$k}, $s2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 35900 | push @errors, @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 35900 | ▶ | next if @e or !is_type $r, 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@e or not is_type($r, "HASH")
MC/DC100%2/2
@e or not is_type($r, "HASH")
@e
not is_type($r, "HASH")
Truth table100%3/3
A or not(B)
A= @eB= not is_type($r, "HASH")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 34324 | ▶ | push @errors, $self->_validate_type_enum($data->{$k}, $s2) if $r->{enum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 34324 | ▶ | push @errors, $self->_validate_type_const($data->{$k}, $s2) if $r->{const}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 11126 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 38 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | JSON::Validator::Schema::Draft4 - JSON-Schema Draft 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | See L<JSON::Validator::Schema/SYNOPSIS>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | This class represents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | L<https://json-schema.org/specification-links.html#draft-4>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | =head2 specification | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | my $str = $schema->specification; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | my $schema = $schema->specification($str); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | Defaults to "L<http://json-schema.org/draft-04/schema#>". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | L<JSON::Validator::Schema>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||