line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
31
|
|
|
31
|
|
16939
|
use strict; |
|
31
|
|
|
|
|
115
|
|
|
31
|
|
|
|
|
1151
|
|
2
|
31
|
|
|
31
|
|
264
|
use warnings; |
|
31
|
|
|
|
|
109
|
|
|
31
|
|
|
|
|
2092
|
|
3
|
|
|
|
|
|
|
package JSON::Schema::Modern::Vocabulary::Content; |
4
|
|
|
|
|
|
|
# vim: set ts=8 sts=2 sw=2 tw=100 et : |
5
|
|
|
|
|
|
|
# ABSTRACT: Implementation of the JSON Schema Content vocabulary |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.571'; |
8
|
|
|
|
|
|
|
|
9
|
31
|
|
|
31
|
|
664
|
use 5.020; |
|
31
|
|
|
|
|
143
|
|
10
|
31
|
|
|
31
|
|
218
|
use Moo; |
|
31
|
|
|
|
|
118
|
|
|
31
|
|
|
|
|
231
|
|
11
|
31
|
|
|
31
|
|
12231
|
use strictures 2; |
|
31
|
|
|
|
|
263
|
|
|
31
|
|
|
|
|
1296
|
|
12
|
31
|
|
|
31
|
|
5912
|
use stable 0.031 'postderef'; |
|
31
|
|
|
|
|
545
|
|
|
31
|
|
|
|
|
198
|
|
13
|
31
|
|
|
31
|
|
4499
|
use experimental 'signatures'; |
|
31
|
|
|
|
|
141
|
|
|
31
|
|
|
|
|
216
|
|
14
|
31
|
|
|
31
|
|
2750
|
use if "$]" >= 5.022, experimental => 're_strict'; |
|
31
|
|
|
|
|
142
|
|
|
31
|
|
|
|
|
290
|
|
15
|
31
|
|
|
31
|
|
3290
|
no if "$]" >= 5.031009, feature => 'indirect'; |
|
31
|
|
|
|
|
138
|
|
|
31
|
|
|
|
|
244
|
|
16
|
31
|
|
|
31
|
|
1914
|
no if "$]" >= 5.033001, feature => 'multidimensional'; |
|
31
|
|
|
|
|
124
|
|
|
31
|
|
|
|
|
263
|
|
17
|
31
|
|
|
31
|
|
1646
|
no if "$]" >= 5.033006, feature => 'bareword_filehandles'; |
|
31
|
|
|
|
|
88
|
|
|
31
|
|
|
|
|
309
|
|
18
|
31
|
|
|
31
|
|
1546
|
use Storable 'dclone'; |
|
31
|
|
|
|
|
125
|
|
|
31
|
|
|
|
|
2203
|
|
19
|
31
|
|
|
31
|
|
331
|
use Feature::Compat::Try; |
|
31
|
|
|
|
|
164
|
|
|
31
|
|
|
|
|
302
|
|
20
|
31
|
|
|
31
|
|
4333
|
use JSON::Schema::Modern::Utilities qw(is_type A assert_keyword_type E abort); |
|
31
|
|
|
|
|
133
|
|
|
31
|
|
|
|
|
2476
|
|
21
|
31
|
|
|
31
|
|
267
|
use namespace::clean; |
|
31
|
|
|
|
|
102
|
|
|
31
|
|
|
|
|
279
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
with 'JSON::Schema::Modern::Vocabulary'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub vocabulary { |
26
|
15
|
|
|
15
|
0
|
72
|
'https://json-schema.org/draft/2019-09/vocab/content' => 'draft2019-09', |
27
|
|
|
|
|
|
|
'https://json-schema.org/draft/2020-12/vocab/content' => 'draft2020-12'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
0
|
0
|
sub evaluation_order { 4 } |
31
|
|
|
|
|
|
|
|
32
|
91
|
|
|
91
|
0
|
262
|
sub keywords ($self, $spec_version) { |
|
91
|
|
|
|
|
203
|
|
|
91
|
|
|
|
|
176
|
|
|
91
|
|
|
|
|
167
|
|
33
|
|
|
|
|
|
|
return ( |
34
|
91
|
100
|
|
|
|
1527
|
qw(contentEncoding contentMediaType), |
35
|
|
|
|
|
|
|
$spec_version ne 'draft7' ? 'contentSchema' : (), |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
171
|
|
|
171
|
|
310
|
sub _traverse_keyword_contentEncoding ($self, $schema, $state) { |
|
171
|
|
|
|
|
289
|
|
|
171
|
|
|
|
|
506
|
|
|
171
|
|
|
|
|
261
|
|
|
171
|
|
|
|
|
248
|
|
40
|
171
|
50
|
|
|
|
485
|
return if not assert_keyword_type($state, $schema, 'string'); |
41
|
171
|
|
|
|
|
500
|
return 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
85
|
|
|
85
|
|
152
|
sub _eval_keyword_contentEncoding ($self, $data, $schema, $state) { |
|
85
|
|
|
|
|
151
|
|
|
85
|
|
|
|
|
157
|
|
|
85
|
|
|
|
|
155
|
|
|
85
|
|
|
|
|
133
|
|
|
85
|
|
|
|
|
170
|
|
45
|
85
|
100
|
|
|
|
271
|
return 1 if not is_type('string', $data); |
46
|
|
|
|
|
|
|
|
47
|
69
|
|
|
|
|
343
|
A($state, $schema->{$state->{keyword}}); |
48
|
|
|
|
|
|
|
|
49
|
69
|
100
|
|
|
|
194
|
if ($state->{validate_content_schemas}) { |
50
|
19
|
|
|
|
|
463
|
my $decoder = $state->{evaluator}->get_encoding($schema->{contentEncoding}); |
51
|
|
|
|
|
|
|
abort($state, 'cannot find decoder for contentEncoding "%s"', $schema->{contentEncoding}) |
52
|
19
|
100
|
|
|
|
1808
|
if not $decoder; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# decode the data now, so we can report errors for the right keyword |
55
|
|
|
|
|
|
|
try { |
56
|
|
|
|
|
|
|
$state->{_content_ref} = $decoder->(\$data); |
57
|
|
|
|
|
|
|
} |
58
|
18
|
|
|
|
|
52
|
catch ($e) { |
59
|
|
|
|
|
|
|
chomp $e; |
60
|
|
|
|
|
|
|
return E($state, 'could not decode %s string: %s', $schema->{contentEncoding}, $e); |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
62
|
|
|
|
|
233
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
86
|
|
|
86
|
|
351
|
sub _traverse_keyword_contentMediaType { goto \&_traverse_keyword_contentEncoding } |
68
|
|
|
|
|
|
|
|
69
|
84
|
|
|
84
|
|
211
|
sub _eval_keyword_contentMediaType ($self, $data, $schema, $state) { |
|
84
|
|
|
|
|
167
|
|
|
84
|
|
|
|
|
156
|
|
|
84
|
|
|
|
|
134
|
|
|
84
|
|
|
|
|
122
|
|
|
84
|
|
|
|
|
146
|
|
70
|
84
|
100
|
|
|
|
563
|
return 1 if not is_type('string', $data); |
71
|
|
|
|
|
|
|
|
72
|
68
|
|
|
|
|
295
|
A($state, $schema->{$state->{keyword}}); |
73
|
|
|
|
|
|
|
|
74
|
68
|
100
|
|
|
|
184
|
if ($state->{validate_content_schemas}) { |
75
|
18
|
|
|
|
|
473
|
my $decoder = $state->{evaluator}->get_media_type($schema->{contentMediaType}); |
76
|
|
|
|
|
|
|
abort($state, 'cannot find decoder for contentMediaType "%s"', $schema->{contentMediaType}) |
77
|
18
|
100
|
|
|
|
158
|
if not $decoder; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# contentEncoding failed to decode the content |
80
|
17
|
100
|
100
|
|
|
110
|
return 1 if exists $schema->{contentEncoding} and not exists $state->{_content_ref}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# decode the data now, so we can report errors for the right keyword |
83
|
|
|
|
|
|
|
try { |
84
|
|
|
|
|
|
|
$state->{_content_ref} = $decoder->($state->{_content_ref} // \$data); |
85
|
|
|
|
|
|
|
} |
86
|
14
|
|
|
|
|
44
|
catch ($e) { |
87
|
|
|
|
|
|
|
chomp $e; |
88
|
|
|
|
|
|
|
delete $state->{_content_ref}; |
89
|
|
|
|
|
|
|
return E($state, 'could not decode %s string: %s', $schema->{contentMediaType}, $e); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
58
|
|
|
|
|
505
|
return 1; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
41
|
|
|
41
|
|
81
|
sub _traverse_keyword_contentSchema ($self, $schema, $state) { |
|
41
|
|
|
|
|
79
|
|
|
41
|
|
|
|
|
71
|
|
|
41
|
|
|
|
|
69
|
|
|
41
|
|
|
|
|
58
|
|
97
|
|
|
|
|
|
|
# since contentSchema should never be assumed to be evaluated in the context of the containing |
98
|
|
|
|
|
|
|
# schema, it is not appropriate to gather identifiers found therein -- but we can still validate |
99
|
|
|
|
|
|
|
# the subschema. |
100
|
41
|
|
|
|
|
563
|
$self->traverse_subschema($schema, +{ %$state, identifiers => [] }); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
39
|
|
|
39
|
|
70
|
sub _eval_keyword_contentSchema ($self, $data, $schema, $state) { |
|
39
|
|
|
|
|
69
|
|
|
39
|
|
|
|
|
64
|
|
|
39
|
|
|
|
|
73
|
|
|
39
|
|
|
|
|
66
|
|
|
39
|
|
|
|
|
63
|
|
104
|
39
|
50
|
|
|
|
114
|
return 1 if not exists $schema->{contentMediaType}; |
105
|
39
|
100
|
|
|
|
100
|
return 1 if not is_type('string', $data); |
106
|
|
|
|
|
|
|
|
107
|
35
|
|
|
|
|
2416
|
A($state, dclone($schema->{contentSchema})); |
108
|
35
|
100
|
|
|
|
209
|
return 1 if not $state->{validate_content_schemas}; |
109
|
|
|
|
|
|
|
|
110
|
5
|
100
|
|
|
|
23
|
return 1 if not exists $state->{_content_ref}; # contentMediaType failed to decode the content |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return 1 if $self->eval($state->{_content_ref}->$*, $schema->{contentSchema}, |
113
|
3
|
100
|
|
|
|
58
|
{ %$state, schema_path => $state->{schema_path}.'/contentSchema' }); |
114
|
2
|
|
|
|
|
22
|
return E($state, 'subschema is not valid'); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=pod |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=encoding UTF-8 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 NAME |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
JSON::Schema::Modern::Vocabulary::Content - Implementation of the JSON Schema Content vocabulary |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 VERSION |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
version 0.571 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 DESCRIPTION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=for Pod::Coverage vocabulary evaluation_order keywords |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=for stopwords metaschema |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Implementation of the JSON Schema Draft 2020-12 "Content" vocabulary, indicated in metaschemas |
140
|
|
|
|
|
|
|
with the URI C<https://json-schema.org/draft/2020-12/vocab/content> and formally specified in |
141
|
|
|
|
|
|
|
L<https://json-schema.org/draft/2020-12/json-schema-validation.html#section-8>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Support is also provided for |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=over 4 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
the equivalent Draft 2019-09 keywords, indicated in metaschemas with the URI C<https://json-schema.org/draft/2019-09/vocab/content> and formally specified in L<https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-02#section-8>. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
the equivalent Draft 7 keywords that correspond to this vocabulary and are formally specified in L<https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-8>. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Assertion behaviour can be enabled by toggling the L<JSON::Schema::Modern/validate_content_schemas> |
158
|
|
|
|
|
|
|
option. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
New handlers for C<contentEncoding> and C<contentMediaType> can be done through |
161
|
|
|
|
|
|
|
L<JSON::Schema::Modern/add_encoding> and L<JSON::Schema::Modern/add_media_type>. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=for stopwords OpenAPI |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SUPPORT |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Bugs may be submitted through L<https://github.com/karenetheridge/JSON-Schema-Modern/issues>. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
I am also usually active on irc, as 'ether' at C<irc.perl.org> and C<irc.libera.chat>. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
You can also find me on the L<JSON Schema Slack server|https://json-schema.slack.com> and L<OpenAPI Slack |
172
|
|
|
|
|
|
|
server|https://open-api.slack.com>, which are also great resources for finding help. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 AUTHOR |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Karen Etheridge. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
183
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |