line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSONSchema::Validator::Constraints::Draft6; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: JSON Schema Draft6 specification constraints |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
36
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
148
|
|
6
|
6
|
|
|
6
|
|
26
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
153
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
32
|
use JSONSchema::Validator::JSONPointer 'json_pointer'; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
260
|
|
9
|
6
|
|
|
6
|
|
32
|
use JSONSchema::Validator::Error 'error'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
270
|
|
10
|
6
|
|
|
6
|
|
36
|
use JSONSchema::Validator::Util qw(is_type serialize unbool); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
279
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
33
|
use parent 'JSONSchema::Validator::Constraints::Draft4'; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
41
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# params: $self, $value, $type, $strict |
15
|
|
|
|
|
|
|
sub check_type { |
16
|
1219
|
100
|
|
1219
|
0
|
2046
|
if ($_[2] eq 'integer') { |
17
|
11
|
|
66
|
|
|
39
|
return is_type($_[1], 'number', $_[3] // $_[0]->strict) && int($_[1]) == $_[1]; |
18
|
|
|
|
|
|
|
} |
19
|
1208
|
|
66
|
|
|
2623
|
return is_type($_[1], $_[2], $_[3] // $_[0]->strict); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub exclusiveMaximum { |
23
|
7
|
|
|
7
|
0
|
17
|
my ($self, $instance, $exclusiveMaximum, $schema, $instance_path, $schema_path, $data) = @_; |
24
|
7
|
50
|
|
|
|
14
|
return 1 unless $self->check_type($instance, 'number'); |
25
|
|
|
|
|
|
|
|
26
|
7
|
100
|
|
|
|
20
|
return 1 if $instance < $exclusiveMaximum; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
7
|
push @{$data->{errors}}, error( |
|
5
|
|
|
|
|
42
|
|
29
|
|
|
|
|
|
|
message => "${instance} is equal or greater than ${exclusiveMaximum}", |
30
|
|
|
|
|
|
|
instance_path => $instance_path, |
31
|
|
|
|
|
|
|
schema_path => $schema_path |
32
|
|
|
|
|
|
|
); |
33
|
5
|
|
|
|
|
13
|
return 0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub exclusiveMinimum { |
37
|
3
|
|
|
3
|
0
|
9
|
my ($self, $instance, $exclusiveMinimum, $schema, $instance_path, $schema_path, $data) = @_; |
38
|
3
|
50
|
|
|
|
9
|
return 1 unless $self->check_type($instance, 'number'); |
39
|
|
|
|
|
|
|
|
40
|
3
|
100
|
|
|
|
13
|
return 1 if $instance > $exclusiveMinimum; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
4
|
push @{$data->{errors}}, error( |
|
2
|
|
|
|
|
19
|
|
43
|
|
|
|
|
|
|
message => "${instance} is equal or less than ${exclusiveMinimum}", |
44
|
|
|
|
|
|
|
instance_path => $instance_path, |
45
|
|
|
|
|
|
|
schema_path => $schema_path |
46
|
|
|
|
|
|
|
); |
47
|
2
|
|
|
|
|
7
|
return 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub propertyNames { |
51
|
2
|
|
|
2
|
0
|
7
|
my ($self, $instance, $propertyNames, $schema, $instance_path, $schema_path, $data) = @_; |
52
|
2
|
50
|
|
|
|
5
|
return 1 unless $self->check_type($instance, 'object'); |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
4
|
my $result = 1; |
55
|
2
|
|
|
|
|
8
|
for my $p (keys %$instance) { |
56
|
4
|
|
|
|
|
10
|
my $ipath = json_pointer->append($instance_path, $p); |
57
|
4
|
|
|
|
|
22
|
my $r = $self->validator->_validate_schema($p, $propertyNames, $ipath, $schema_path, $data); |
58
|
4
|
100
|
|
|
|
12
|
$result = 0 unless $r; |
59
|
|
|
|
|
|
|
} |
60
|
2
|
|
|
|
|
5
|
return $result; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub contains { |
64
|
6
|
|
|
6
|
0
|
30
|
my ($self, $instance, $contains, $schema, $instance_path, $schema_path, $data) = @_; |
65
|
6
|
50
|
|
|
|
18
|
return 1 unless $self->check_type($instance, 'array'); |
66
|
|
|
|
|
|
|
|
67
|
6
|
|
|
|
|
16
|
my $errors = $data->{errors}; |
68
|
6
|
|
|
|
|
27
|
my $local_errors = []; |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
11
|
my $result = 0; |
71
|
6
|
|
|
|
|
11
|
for my $idx (0 .. $#{$instance}) { |
|
6
|
|
|
|
|
18
|
|
72
|
20
|
|
|
|
|
32
|
$data->{errors} = []; |
73
|
20
|
|
|
|
|
45
|
my $ipath = json_pointer->append($instance_path, $idx); |
74
|
20
|
|
|
|
|
56
|
$result = $self->validator->_validate_schema($instance->[$idx], $contains, $ipath, $schema_path, $data); |
75
|
20
|
100
|
|
|
|
68
|
unless ($result) { |
76
|
17
|
|
|
|
|
63
|
push @{$local_errors}, error( |
77
|
|
|
|
|
|
|
message => qq'${idx} part of "contains" has errors', |
78
|
|
|
|
|
|
|
context => $data->{errors}, |
79
|
17
|
|
|
|
|
27
|
instance_path => $ipath, |
80
|
|
|
|
|
|
|
schema_path => $schema_path |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
20
|
100
|
|
|
|
52
|
last if $result; |
84
|
|
|
|
|
|
|
} |
85
|
6
|
|
|
|
|
13
|
$data->{errors} = $errors; |
86
|
6
|
100
|
|
|
|
23
|
return 1 if $result; |
87
|
|
|
|
|
|
|
|
88
|
3
|
|
|
|
|
7
|
push @{$data->{errors}}, error( |
|
3
|
|
|
|
|
13
|
|
89
|
|
|
|
|
|
|
message => 'No elems of instance satisfy schema of "contains"', |
90
|
|
|
|
|
|
|
context => $local_errors, |
91
|
|
|
|
|
|
|
instance_path => $instance_path, |
92
|
|
|
|
|
|
|
schema_path => $schema_path |
93
|
|
|
|
|
|
|
); |
94
|
3
|
|
|
|
|
9
|
return 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub const { |
98
|
10
|
|
|
10
|
0
|
25
|
my ($self, $instance, $const, $schema, $instance_path, $schema_path, $data) = @_; |
99
|
|
|
|
|
|
|
|
100
|
10
|
|
|
|
|
18
|
my $result = 0; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# schema must have strict check |
103
|
10
|
50
|
66
|
|
|
25
|
if ($self->check_type($const, 'boolean', 1)) { |
|
|
100
|
33
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
0
|
$result = $self->check_type($instance, 'boolean') |
105
|
|
|
|
|
|
|
? unbool($instance) eq unbool($const) |
106
|
|
|
|
|
|
|
: 0 |
107
|
|
|
|
|
|
|
} elsif ($self->check_type($const, 'object', 1) || $self->check_type($const, 'array', 1)) { |
108
|
2
|
50
|
33
|
|
|
13
|
$result = $self->check_type($instance, 'object') || |
109
|
|
|
|
|
|
|
$self->check_type($instance, 'array') |
110
|
|
|
|
|
|
|
? serialize($instance) eq serialize($const) |
111
|
|
|
|
|
|
|
: 0; |
112
|
|
|
|
|
|
|
} elsif ($self->check_type($const, 'number', 1)) { |
113
|
4
|
50
|
|
|
|
12
|
$result = $self->check_type($instance, 'number') |
114
|
|
|
|
|
|
|
? $const == $instance |
115
|
|
|
|
|
|
|
: 0; |
116
|
|
|
|
|
|
|
} elsif (defined $const && defined $instance) { |
117
|
4
|
|
|
|
|
8
|
$result = $const eq $instance; |
118
|
|
|
|
|
|
|
} elsif (!defined $const && !defined $instance) { |
119
|
0
|
|
|
|
|
0
|
$result = 1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
10
|
100
|
|
|
|
37
|
return 1 if $result; |
123
|
|
|
|
|
|
|
|
124
|
5
|
|
|
|
|
13
|
push @{$data->{errors}}, error( |
|
5
|
|
|
|
|
26
|
|
125
|
|
|
|
|
|
|
message => "instance is not equal const", |
126
|
|
|
|
|
|
|
instance_path => $instance_path, |
127
|
|
|
|
|
|
|
schema_path => $schema_path |
128
|
|
|
|
|
|
|
); |
129
|
5
|
|
|
|
|
14
|
return 0; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |