line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSV::Keyword::Draft4::Properties; |
2
|
|
|
|
|
|
|
|
3
|
44
|
|
|
44
|
|
30356
|
use strict; |
|
44
|
|
|
|
|
84
|
|
|
44
|
|
|
|
|
1069
|
|
4
|
44
|
|
|
44
|
|
196
|
use warnings; |
|
44
|
|
|
|
|
108
|
|
|
44
|
|
|
|
|
1053
|
|
5
|
44
|
|
|
44
|
|
193
|
use parent qw(JSV::Keyword); |
|
44
|
|
|
|
|
72
|
|
|
44
|
|
|
|
|
238
|
|
6
|
|
|
|
|
|
|
|
7
|
44
|
|
|
44
|
|
2138
|
use JSV::Keyword qw(:constants); |
|
44
|
|
|
|
|
74
|
|
|
44
|
|
|
|
|
4852
|
|
8
|
44
|
|
|
44
|
|
207
|
use JSV::Util::Type qw(detect_instance_type escape_json_pointer); |
|
44
|
|
|
|
|
78
|
|
|
44
|
|
|
|
|
23992
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub instance_type() { INSTANCE_TYPE_OBJECT(); } |
11
|
|
|
|
|
|
|
sub keyword() { 'properties' } |
12
|
328
|
|
|
328
|
0
|
1116
|
sub additional_keywords() { [qw/additionalProperties patternProperties/]; } |
13
|
|
|
|
|
|
|
sub keyword_priority() { 10; } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub validate { |
16
|
226
|
|
|
226
|
0
|
384
|
my ($class, $context, $schema, $instance) = @_; |
17
|
|
|
|
|
|
|
|
18
|
226
|
|
100
|
|
|
639
|
my $properties = $class->keyword_value($schema) || {}; |
19
|
226
|
|
100
|
|
|
703
|
my $pattern_properties = $class->keyword_value($schema, "patternProperties") || {}; |
20
|
|
|
|
|
|
|
|
21
|
226
|
|
|
|
|
497
|
my @patterns = (); |
22
|
226
|
|
|
|
|
303
|
my @pattern_schemas = (); |
23
|
226
|
|
|
|
|
304
|
my @original_patterns = (); |
24
|
226
|
|
|
|
|
582
|
for my $pattern (keys %$pattern_properties) { |
25
|
49
|
|
|
|
|
438
|
push(@patterns, qr/$pattern/); |
26
|
49
|
|
|
|
|
90
|
push(@pattern_schemas, $pattern_properties->{$pattern}); |
27
|
49
|
|
|
|
|
96
|
push(@original_patterns, $pattern); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
226
|
|
|
|
|
637
|
my $additional_properties = $class->keyword_value($schema, "additionalProperties"); |
31
|
226
|
|
|
|
|
850
|
my $additional_properties_type = detect_instance_type($schema->{additionalProperties}); |
32
|
226
|
|
|
|
|
701
|
my %s = map { $_ => undef } keys %$instance; |
|
403
|
|
|
|
|
1331
|
|
33
|
|
|
|
|
|
|
|
34
|
226
|
|
|
|
|
575
|
for my $property (keys %$instance) { |
35
|
403
|
|
|
|
|
1222
|
local $context->{current_pointer} = $context->{current_pointer} . "/" . escape_json_pointer( $property ); |
36
|
|
|
|
|
|
|
|
37
|
403
|
100
|
|
|
|
993
|
if (exists $properties->{$property}) { |
38
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
39
|
283
|
|
|
|
|
765
|
$context->{current_schema_pointer} . "/properties/" . escape_json_pointer( $property ); |
40
|
283
|
|
|
|
|
1203
|
$context->validate($properties->{$property}, $instance->{$property}); |
41
|
283
|
|
|
|
|
654
|
delete $s{$property}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
403
|
|
|
|
|
1137
|
for (my $i = 0, my $l = scalar(@patterns); $i < $l; $i++) { |
45
|
49
|
100
|
|
|
|
276
|
next unless ($property =~ m/$patterns[$i]/); |
46
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
47
|
19
|
|
|
|
|
71
|
$context->{current_schema_pointer} . "/patternProperties/" . escape_json_pointer( $original_patterns[$i] ); |
48
|
19
|
|
|
|
|
60
|
$context->validate($pattern_schemas[$i], $instance->{$property}); |
49
|
19
|
|
|
|
|
74
|
delete $s{$property}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
403
|
100
|
100
|
|
|
1745
|
if (exists $s{$property} && $additional_properties_type eq "object") { |
53
|
|
|
|
|
|
|
local $context->{current_schema_pointer} = |
54
|
13
|
|
|
|
|
35
|
$context->{current_schema_pointer} . "/additionalProperties"; |
55
|
13
|
|
|
|
|
47
|
$context->validate($additional_properties, $instance->{$property}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
226
|
100
|
66
|
|
|
1439
|
if ($additional_properties_type eq "boolean" && !$additional_properties) { |
60
|
16
|
100
|
|
|
|
165
|
if (keys %s > 0) { |
61
|
|
|
|
|
|
|
# TODO: provide pointer for each extra property |
62
|
|
|
|
|
|
|
# (to avoid parsing error message and don't depend on its format) |
63
|
6
|
|
|
|
|
49
|
$context->log_error(sprintf("Not allowed properties exist (properties: %s)", join(", ", keys %s))); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |