line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSV::Keyword::Draft4::Items; |
2
|
|
|
|
|
|
|
|
3
|
47
|
|
|
47
|
|
37449
|
use strict; |
|
47
|
|
|
|
|
98
|
|
|
47
|
|
|
|
|
1265
|
|
4
|
47
|
|
|
47
|
|
3957
|
use warnings; |
|
47
|
|
|
|
|
110
|
|
|
47
|
|
|
|
|
1357
|
|
5
|
47
|
|
|
47
|
|
237
|
use parent qw(JSV::Keyword); |
|
47
|
|
|
|
|
82
|
|
|
47
|
|
|
|
|
277
|
|
6
|
|
|
|
|
|
|
|
7
|
47
|
|
|
47
|
|
2479
|
use JSON; |
|
47
|
|
|
|
|
104
|
|
|
47
|
|
|
|
|
288
|
|
8
|
|
|
|
|
|
|
|
9
|
47
|
|
|
47
|
|
5219
|
use JSV::Keyword qw(:constants); |
|
47
|
|
|
|
|
159
|
|
|
47
|
|
|
|
|
5966
|
|
10
|
47
|
|
|
47
|
|
269
|
use JSV::Util::Type qw(detect_instance_type escape_json_pointer); |
|
47
|
|
|
|
|
105
|
|
|
47
|
|
|
|
|
22585
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub instance_type() { INSTANCE_TYPE_ARRAY(); } |
13
|
|
|
|
|
|
|
sub keyword() { "items" } |
14
|
|
|
|
|
|
|
sub keyword_priority() { 10; } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub validate { |
17
|
57
|
|
|
57
|
0
|
119
|
my ($class, $context, $schema, $instance) = @_; |
18
|
|
|
|
|
|
|
|
19
|
57
|
|
|
|
|
218
|
my $items = $class->keyword_value($schema); |
20
|
57
|
|
|
|
|
190
|
my $additional_items = $class->keyword_value($schema, "additionalItems"); |
21
|
|
|
|
|
|
|
|
22
|
57
|
|
|
|
|
167
|
my $items_type = detect_instance_type($items); |
23
|
57
|
|
|
|
|
184
|
my $additional_items_type = detect_instance_type($additional_items); |
24
|
|
|
|
|
|
|
|
25
|
57
|
100
|
|
|
|
221
|
if ($items_type eq "object") { ### items as schema |
|
|
50
|
|
|
|
|
|
26
|
21
|
|
|
|
|
117
|
local $context->{current_schema_pointer} = $context->{current_schema_pointer} . "/" . $class->keyword; |
27
|
21
|
|
|
|
|
102
|
for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { |
28
|
49
|
|
|
|
|
166
|
local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; |
29
|
49
|
|
|
|
|
206
|
$context->validate($items, $instance->[$i]); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ($items_type eq "array") { ### items as schema array |
33
|
36
|
|
|
|
|
137
|
for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { |
34
|
112
|
|
|
|
|
431
|
local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; |
35
|
|
|
|
|
|
|
|
36
|
112
|
100
|
66
|
|
|
380
|
if (defined $items->[$i]) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
37
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
38
|
89
|
|
|
|
|
432
|
$context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i; |
39
|
89
|
|
|
|
|
334
|
$context->validate($items->[$i], $instance->[$i]); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($additional_items_type eq "object") { |
42
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
43
|
13
|
|
|
|
|
46
|
$context->{current_schema_pointer} . "/additionalItems"; |
44
|
13
|
|
|
|
|
50
|
$context->validate($additional_items, $instance->[$i]); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($additional_items_type eq "boolean" && $additional_items == JSON::false) { |
47
|
4
|
|
|
|
|
67
|
$context->log_error("additionalItems are not allowed"); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { ### wrong schema |
52
|
0
|
|
|
|
|
|
$context->log_error("Wrong schema definition"); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |