line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSV::Keyword::Draft4::Items; |
2
|
|
|
|
|
|
|
|
3
|
44
|
|
|
44
|
|
30682
|
use strict; |
|
44
|
|
|
|
|
97
|
|
|
44
|
|
|
|
|
1085
|
|
4
|
44
|
|
|
44
|
|
3695
|
use warnings; |
|
44
|
|
|
|
|
100
|
|
|
44
|
|
|
|
|
1081
|
|
5
|
44
|
|
|
44
|
|
190
|
use parent qw(JSV::Keyword); |
|
44
|
|
|
|
|
70
|
|
|
44
|
|
|
|
|
211
|
|
6
|
|
|
|
|
|
|
|
7
|
44
|
|
|
44
|
|
1995
|
use JSON; |
|
44
|
|
|
|
|
83
|
|
|
44
|
|
|
|
|
240
|
|
8
|
|
|
|
|
|
|
|
9
|
44
|
|
|
44
|
|
4171
|
use JSV::Keyword qw(:constants); |
|
44
|
|
|
|
|
85
|
|
|
44
|
|
|
|
|
4740
|
|
10
|
44
|
|
|
44
|
|
219
|
use JSV::Util::Type qw(detect_instance_type escape_json_pointer); |
|
44
|
|
|
|
|
92
|
|
|
44
|
|
|
|
|
18833
|
|
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
|
105
|
my ($class, $context, $schema, $instance) = @_; |
18
|
|
|
|
|
|
|
|
19
|
57
|
|
|
|
|
262
|
my $items = $class->keyword_value($schema); |
20
|
57
|
|
|
|
|
159
|
my $additional_items = $class->keyword_value($schema, "additionalItems"); |
21
|
|
|
|
|
|
|
|
22
|
57
|
|
|
|
|
142
|
my $items_type = detect_instance_type($items); |
23
|
57
|
|
|
|
|
143
|
my $additional_items_type = detect_instance_type($additional_items); |
24
|
|
|
|
|
|
|
|
25
|
57
|
100
|
|
|
|
179
|
if ($items_type eq "object") { ### items as schema |
|
|
50
|
|
|
|
|
|
26
|
21
|
|
|
|
|
91
|
local $context->{current_schema_pointer} = $context->{current_schema_pointer} . "/" . $class->keyword; |
27
|
21
|
|
|
|
|
83
|
for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { |
28
|
49
|
|
|
|
|
142
|
local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; |
29
|
49
|
|
|
|
|
178
|
$context->validate($items, $instance->[$i]); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ($items_type eq "array") { ### items as schema array |
33
|
36
|
|
|
|
|
132
|
for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) { |
34
|
112
|
|
|
|
|
348
|
local $context->{current_pointer} = $context->{current_pointer} . "/" . $i; |
35
|
|
|
|
|
|
|
|
36
|
112
|
100
|
66
|
|
|
299
|
if (defined $items->[$i]) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
37
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
38
|
89
|
|
|
|
|
341
|
$context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i; |
39
|
89
|
|
|
|
|
256
|
$context->validate($items->[$i], $instance->[$i]); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($additional_items_type eq "object") { |
42
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
43
|
13
|
|
|
|
|
32
|
$context->{current_schema_pointer} . "/additionalItems"; |
44
|
13
|
|
|
|
|
34
|
$context->validate($additional_items, $instance->[$i]); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($additional_items_type eq "boolean" && $additional_items == JSON::false) { |
47
|
4
|
|
|
|
|
51
|
$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; |