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