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
|
|
40
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
187
|
|
6
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
152
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
30
|
use JSONSchema::Validator::JSONPointer 'json_pointer'; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
308
|
|
9
|
6
|
|
|
6
|
|
39
|
use JSONSchema::Validator::Error 'error'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
269
|
|
10
|
6
|
|
|
6
|
|
37
|
use JSONSchema::Validator::Util qw(is_type serialize unbool); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
320
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
40
|
use parent 'JSONSchema::Validator::Constraints::Draft4'; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
38
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# params: $self, $value, $type, $strict |
15
|
|
|
|
|
|
|
sub check_type { |
16
|
1219
|
100
|
|
1219
|
0
|
2477
|
if ($_[2] eq 'integer') { |
17
|
11
|
|
66
|
|
|
51
|
return is_type($_[1], 'number', $_[3] // $_[0]->strict) && int($_[1]) == $_[1]; |
18
|
|
|
|
|
|
|
} |
19
|
1208
|
|
66
|
|
|
3217
|
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
|
|
|
|
18
|
return 1 unless $self->check_type($instance, 'number'); |
25
|
|
|
|
|
|
|
|
26
|
7
|
100
|
|
|
|
22
|
return 1 if $instance < $exclusiveMaximum; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
11
|
push @{$data->{errors}}, error( |
|
5
|
|
|
|
|
36
|
|
29
|
|
|
|
|
|
|
message => "${instance} is equal or greater than ${exclusiveMaximum}", |
30
|
|
|
|
|
|
|
instance_path => $instance_path, |
31
|
|
|
|
|
|
|
schema_path => $schema_path |
32
|
|
|
|
|
|
|
); |
33
|
5
|
|
|
|
|
17
|
return 0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub exclusiveMinimum { |
37
|
3
|
|
|
3
|
0
|
10
|
my ($self, $instance, $exclusiveMinimum, $schema, $instance_path, $schema_path, $data) = @_; |
38
|
3
|
50
|
|
|
|
8
|
return 1 unless $self->check_type($instance, 'number'); |
39
|
|
|
|
|
|
|
|
40
|
3
|
100
|
|
|
|
14
|
return 1 if $instance > $exclusiveMinimum; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
5
|
push @{$data->{errors}}, error( |
|
2
|
|
|
|
|
24
|
|
43
|
|
|
|
|
|
|
message => "${instance} is equal or less than ${exclusiveMinimum}", |
44
|
|
|
|
|
|
|
instance_path => $instance_path, |
45
|
|
|
|
|
|
|
schema_path => $schema_path |
46
|
|
|
|
|
|
|
); |
47
|
2
|
|
|
|
|
9
|
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
|
|
|
|
7
|
return 1 unless $self->check_type($instance, 'object'); |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
5
|
my $result = 1; |
55
|
2
|
|
|
|
|
9
|
for my $p (keys %$instance) { |
56
|
4
|
|
|
|
|
11
|
my $ipath = json_pointer->append($instance_path, $p); |
57
|
4
|
|
|
|
|
19
|
my $r = $self->validator->_validate_schema($p, $propertyNames, $ipath, $schema_path, $data); |
58
|
4
|
100
|
|
|
|
16
|
$result = 0 unless $r; |
59
|
|
|
|
|
|
|
} |
60
|
2
|
|
|
|
|
5
|
return $result; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub contains { |
64
|
6
|
|
|
6
|
0
|
19
|
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
|
|
|
|
|
15
|
my $errors = $data->{errors}; |
68
|
6
|
|
|
|
|
13
|
my $local_errors = []; |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
11
|
my $result = 0; |
71
|
6
|
|
|
|
|
14
|
for my $idx (0 .. $#{$instance}) { |
|
6
|
|
|
|
|
19
|
|
72
|
20
|
|
|
|
|
50
|
$data->{errors} = []; |
73
|
20
|
|
|
|
|
53
|
my $ipath = json_pointer->append($instance_path, $idx); |
74
|
20
|
|
|
|
|
61
|
$result = $self->validator->_validate_schema($instance->[$idx], $contains, $ipath, $schema_path, $data); |
75
|
20
|
100
|
|
|
|
50
|
unless ($result) { |
76
|
17
|
|
|
|
|
72
|
push @{$local_errors}, error( |
77
|
|
|
|
|
|
|
message => qq'${idx} part of "contains" has errors', |
78
|
|
|
|
|
|
|
context => $data->{errors}, |
79
|
17
|
|
|
|
|
40
|
instance_path => $ipath, |
80
|
|
|
|
|
|
|
schema_path => $schema_path |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
20
|
100
|
|
|
|
77
|
last if $result; |
84
|
|
|
|
|
|
|
} |
85
|
6
|
|
|
|
|
13
|
$data->{errors} = $errors; |
86
|
6
|
100
|
|
|
|
28
|
return 1 if $result; |
87
|
|
|
|
|
|
|
|
88
|
3
|
|
|
|
|
6
|
push @{$data->{errors}}, error( |
|
3
|
|
|
|
|
14
|
|
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
|
29
|
my ($self, $instance, $const, $schema, $instance_path, $schema_path, $data) = @_; |
99
|
|
|
|
|
|
|
|
100
|
10
|
|
|
|
|
19
|
my $result = 0; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# schema must have strict check |
103
|
10
|
50
|
66
|
|
|
26
|
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
|
|
|
7
|
$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
|
|
|
|
11
|
$result = $self->check_type($instance, 'number') |
114
|
|
|
|
|
|
|
? $const == $instance |
115
|
|
|
|
|
|
|
: 0; |
116
|
|
|
|
|
|
|
} elsif (defined $const && defined $instance) { |
117
|
4
|
|
|
|
|
11
|
$result = $const eq $instance; |
118
|
|
|
|
|
|
|
} elsif (!defined $const && !defined $instance) { |
119
|
0
|
|
|
|
|
0
|
$result = 1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
10
|
100
|
|
|
|
42
|
return 1 if $result; |
123
|
|
|
|
|
|
|
|
124
|
5
|
|
|
|
|
14
|
push @{$data->{errors}}, error( |
|
5
|
|
|
|
|
23
|
|
125
|
|
|
|
|
|
|
message => "instance is not equal const", |
126
|
|
|
|
|
|
|
instance_path => $instance_path, |
127
|
|
|
|
|
|
|
schema_path => $schema_path |
128
|
|
|
|
|
|
|
); |
129
|
5
|
|
|
|
|
18
|
return 0; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |