| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package JSON::Schema::AsType::Draft3; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Role processing draft3 JSON Schema |
|
4
|
|
|
|
|
|
|
$JSON::Schema::AsType::Draft3::VERSION = '0.4.1'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2256
|
use strict; |
|
|
4
|
|
|
|
|
5
|
|
|
|
4
|
|
|
|
|
116
|
|
|
7
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
|
4
|
|
|
|
|
4
|
|
|
|
4
|
|
|
|
|
120
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
19
|
use Moose::Role; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
17553
|
use Type::Utils; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
46
|
|
|
12
|
4
|
|
|
4
|
|
3734
|
use Scalar::Util qw/ looks_like_number /; |
|
|
4
|
|
|
|
|
5
|
|
|
|
4
|
|
|
|
|
264
|
|
|
13
|
4
|
|
|
4
|
|
19
|
use List::Util qw/ reduce pairmap pairs /; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
276
|
|
|
14
|
4
|
|
|
4
|
|
33
|
use List::MoreUtils qw/ any all none uniq zip /; |
|
|
4
|
|
|
|
|
5
|
|
|
|
4
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
2824
|
use JSON::Schema::AsType; |
|
|
4
|
|
|
|
|
5
|
|
|
|
4
|
|
|
|
|
92
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
4
|
|
|
4
|
|
14
|
use JSON; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
23
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
4
|
|
|
4
|
|
1969
|
use JSON::Schema::AsType::Draft3::Types '-all'; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
36
|
|
|
21
|
4
|
|
|
4
|
|
38662
|
use Types::Standard 'Optional'; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
50
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
with 'JSON::Schema::AsType::Draft4' => { |
|
24
|
|
|
|
|
|
|
-excludes => [qw/ _keyword_properties _keyword_required _keyword_type /] |
|
25
|
|
|
|
|
|
|
}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _keyword_properties { |
|
28
|
40
|
|
|
40
|
|
72
|
my( $self, $properties ) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @props = pairmap { { |
|
31
|
150
|
|
|
150
|
|
7744
|
my $schema = $self->sub_schema($b); |
|
|
150
|
|
|
|
|
490
|
|
|
32
|
150
|
|
|
|
|
9996
|
my $p = $schema->type; |
|
33
|
150
|
100
|
|
|
|
1319
|
$p = Optional[$p] unless $b->{required}; |
|
34
|
150
|
|
|
|
|
29945
|
$a => $p |
|
35
|
40
|
|
|
|
|
448
|
}} %$properties; |
|
36
|
|
|
|
|
|
|
|
|
37
|
40
|
|
|
|
|
2494
|
return Properties[@props]; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _keyword_disallow { |
|
41
|
3
|
|
|
3
|
|
13
|
Disallow[ $_[0]->_keyword_type($_[1]) ]; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _keyword_extends { |
|
46
|
3
|
|
|
3
|
|
6
|
my( $self, $extends ) = @_; |
|
47
|
|
|
|
|
|
|
|
|
48
|
3
|
100
|
|
|
|
17
|
my @extends = ref $extends eq 'ARRAY' ? @$extends : ( $extends ); |
|
49
|
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
7
|
return Extends[ map { $self->sub_schema($_)->type } @extends]; |
|
|
4
|
|
|
|
|
109
|
|
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _keyword_type { |
|
54
|
288
|
|
|
288
|
|
418
|
my( $self, $struct_type ) = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my %type_map = map { |
|
57
|
288
|
|
|
|
|
893
|
lc $_->name => $_ |
|
|
2016
|
|
|
|
|
10382
|
|
|
58
|
|
|
|
|
|
|
} Integer, Boolean, Number, String, Null, Object, Array; |
|
59
|
|
|
|
|
|
|
|
|
60
|
288
|
100
|
|
|
|
8795
|
unless( $self->strict_string ) { |
|
61
|
9
|
|
|
|
|
44
|
$type_map{number} = LaxNumber; |
|
62
|
9
|
|
|
|
|
36
|
$type_map{integer} = LaxInteger; |
|
63
|
9
|
|
|
|
|
41
|
$type_map{string} = LaxString; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
288
|
100
|
|
|
|
1832
|
return if $struct_type eq 'any'; |
|
68
|
|
|
|
|
|
|
|
|
69
|
283
|
100
|
|
|
|
993
|
return $type_map{$struct_type} if $type_map{$struct_type}; |
|
70
|
|
|
|
|
|
|
|
|
71
|
44
|
50
|
|
|
|
80
|
if( my @types = eval { @$struct_type } ) { |
|
|
44
|
|
|
|
|
202
|
|
|
72
|
44
|
100
|
|
47
|
|
361
|
return reduce { $a | $b } map { ref $_ ? $self->sub_schema($_)->type : $self->_keyword_type($_) } @types; |
|
|
47
|
|
|
|
|
1731
|
|
|
|
91
|
|
|
|
|
1142
|
|
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
die "unknown type '$struct_type'"; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _keyword_divisibleBy { |
|
79
|
3
|
|
|
3
|
|
5
|
my( $self, $divisibleBy ) = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
15
|
DivisibleBy[$divisibleBy]; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _keyword_dependencies { |
|
85
|
7
|
|
|
7
|
|
17
|
my( $self, $dependencies ) = @_; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return Dependencies[ |
|
88
|
7
|
100
|
|
11
|
|
88
|
pairmap { $a => ref $b eq 'HASH' ? $self->sub_schema($b)->type : $b } %$dependencies |
|
|
11
|
|
|
|
|
83
|
|
|
89
|
|
|
|
|
|
|
]; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
JSON::Schema::AsType->new( |
|
94
|
|
|
|
|
|
|
draft_version => '3', |
|
95
|
|
|
|
|
|
|
uri => 'http://json-schema.org/draft-03/schema', |
|
96
|
|
|
|
|
|
|
schema => from_json <<'END_JSON' )->type; |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
|
|
|
|
|
|
"$schema": "http://json-schema.org/draft-03/schema#", |
|
99
|
|
|
|
|
|
|
"id": "http://json-schema.org/draft-03/schema#", |
|
100
|
|
|
|
|
|
|
"type": "object", |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
"properties": { |
|
103
|
|
|
|
|
|
|
"type": { |
|
104
|
|
|
|
|
|
|
"type": [ "string", "array" ], |
|
105
|
|
|
|
|
|
|
"items": { |
|
106
|
|
|
|
|
|
|
"type": [ "string", { "$ref": "#" } ] |
|
107
|
|
|
|
|
|
|
}, |
|
108
|
|
|
|
|
|
|
"uniqueItems": true, |
|
109
|
|
|
|
|
|
|
"default": "any" |
|
110
|
|
|
|
|
|
|
}, |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
"properties": { |
|
113
|
|
|
|
|
|
|
"type": "object", |
|
114
|
|
|
|
|
|
|
"additionalProperties": { "$ref": "#" }, |
|
115
|
|
|
|
|
|
|
"default": {} |
|
116
|
|
|
|
|
|
|
}, |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
"patternProperties": { |
|
119
|
|
|
|
|
|
|
"type": "object", |
|
120
|
|
|
|
|
|
|
"additionalProperties": { "$ref": "#" }, |
|
121
|
|
|
|
|
|
|
"default": {} |
|
122
|
|
|
|
|
|
|
}, |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
"additionalProperties": { |
|
125
|
|
|
|
|
|
|
"type": [ { "$ref": "#" }, "boolean" ], |
|
126
|
|
|
|
|
|
|
"default": {} |
|
127
|
|
|
|
|
|
|
}, |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
"items": { |
|
130
|
|
|
|
|
|
|
"type": [ { "$ref": "#" }, "array" ], |
|
131
|
|
|
|
|
|
|
"items": { "$ref": "#" }, |
|
132
|
|
|
|
|
|
|
"default": {} |
|
133
|
|
|
|
|
|
|
}, |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
"additionalItems": { |
|
136
|
|
|
|
|
|
|
"type": [ { "$ref": "#" }, "boolean" ], |
|
137
|
|
|
|
|
|
|
"default": {} |
|
138
|
|
|
|
|
|
|
}, |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
"required": { |
|
141
|
|
|
|
|
|
|
"type": "boolean", |
|
142
|
|
|
|
|
|
|
"default": false |
|
143
|
|
|
|
|
|
|
}, |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
"dependencies": { |
|
146
|
|
|
|
|
|
|
"type": "object", |
|
147
|
|
|
|
|
|
|
"additionalProperties": { |
|
148
|
|
|
|
|
|
|
"type": [ "string", "array", { "$ref": "#" } ], |
|
149
|
|
|
|
|
|
|
"items": { |
|
150
|
|
|
|
|
|
|
"type": "string" |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
}, |
|
153
|
|
|
|
|
|
|
"default": {} |
|
154
|
|
|
|
|
|
|
}, |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
"minimum": { |
|
157
|
|
|
|
|
|
|
"type": "number" |
|
158
|
|
|
|
|
|
|
}, |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
"maximum": { |
|
161
|
|
|
|
|
|
|
"type": "number" |
|
162
|
|
|
|
|
|
|
}, |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
"exclusiveMinimum": { |
|
165
|
|
|
|
|
|
|
"type": "boolean", |
|
166
|
|
|
|
|
|
|
"default": false |
|
167
|
|
|
|
|
|
|
}, |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
"exclusiveMaximum": { |
|
170
|
|
|
|
|
|
|
"type": "boolean", |
|
171
|
|
|
|
|
|
|
"default": false |
|
172
|
|
|
|
|
|
|
}, |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
"minItems": { |
|
175
|
|
|
|
|
|
|
"type": "integer", |
|
176
|
|
|
|
|
|
|
"minimum": 0, |
|
177
|
|
|
|
|
|
|
"default": 0 |
|
178
|
|
|
|
|
|
|
}, |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
"maxItems": { |
|
181
|
|
|
|
|
|
|
"type": "integer", |
|
182
|
|
|
|
|
|
|
"minimum": 0 |
|
183
|
|
|
|
|
|
|
}, |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
"uniqueItems": { |
|
186
|
|
|
|
|
|
|
"type": "boolean", |
|
187
|
|
|
|
|
|
|
"default": false |
|
188
|
|
|
|
|
|
|
}, |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
"pattern": { |
|
191
|
|
|
|
|
|
|
"type": "string", |
|
192
|
|
|
|
|
|
|
"format": "regex" |
|
193
|
|
|
|
|
|
|
}, |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
"minLength": { |
|
196
|
|
|
|
|
|
|
"type": "integer", |
|
197
|
|
|
|
|
|
|
"minimum": 0, |
|
198
|
|
|
|
|
|
|
"default": 0 |
|
199
|
|
|
|
|
|
|
}, |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
"maxLength": { |
|
202
|
|
|
|
|
|
|
"type": "integer" |
|
203
|
|
|
|
|
|
|
}, |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
"enum": { |
|
206
|
|
|
|
|
|
|
"type": "array", |
|
207
|
|
|
|
|
|
|
"minItems": 1, |
|
208
|
|
|
|
|
|
|
"uniqueItems": true |
|
209
|
|
|
|
|
|
|
}, |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
"default": { |
|
212
|
|
|
|
|
|
|
"type": "any" |
|
213
|
|
|
|
|
|
|
}, |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
"title": { |
|
216
|
|
|
|
|
|
|
"type": "string" |
|
217
|
|
|
|
|
|
|
}, |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
"description": { |
|
220
|
|
|
|
|
|
|
"type": "string" |
|
221
|
|
|
|
|
|
|
}, |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
"format": { |
|
224
|
|
|
|
|
|
|
"type": "string" |
|
225
|
|
|
|
|
|
|
}, |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
"divisibleBy": { |
|
228
|
|
|
|
|
|
|
"type": "number", |
|
229
|
|
|
|
|
|
|
"minimum": 0, |
|
230
|
|
|
|
|
|
|
"exclusiveMinimum": true, |
|
231
|
|
|
|
|
|
|
"default": 1 |
|
232
|
|
|
|
|
|
|
}, |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
"disallow": { |
|
235
|
|
|
|
|
|
|
"type": [ "string", "array" ], |
|
236
|
|
|
|
|
|
|
"items": { |
|
237
|
|
|
|
|
|
|
"type": [ "string", { "$ref": "#" } ] |
|
238
|
|
|
|
|
|
|
}, |
|
239
|
|
|
|
|
|
|
"uniqueItems": true |
|
240
|
|
|
|
|
|
|
}, |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
"extends": { |
|
243
|
|
|
|
|
|
|
"type": [ { "$ref": "#" }, "array" ], |
|
244
|
|
|
|
|
|
|
"items": { "$ref": "#" }, |
|
245
|
|
|
|
|
|
|
"default": {} |
|
246
|
|
|
|
|
|
|
}, |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
"id": { |
|
249
|
|
|
|
|
|
|
"type": "string", |
|
250
|
|
|
|
|
|
|
"format": "uri" |
|
251
|
|
|
|
|
|
|
}, |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
"$ref": { |
|
254
|
|
|
|
|
|
|
"type": "string", |
|
255
|
|
|
|
|
|
|
"format": "uri" |
|
256
|
|
|
|
|
|
|
}, |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
"$schema": { |
|
259
|
|
|
|
|
|
|
"type": "string", |
|
260
|
|
|
|
|
|
|
"format": "uri" |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
}, |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
"dependencies": { |
|
265
|
|
|
|
|
|
|
"exclusiveMinimum": "minimum", |
|
266
|
|
|
|
|
|
|
"exclusiveMaximum": "maximum" |
|
267
|
|
|
|
|
|
|
}, |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
"default": {} |
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
END_JSON |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
__END__ |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=pod |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=encoding UTF-8 |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 NAME |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
JSON::Schema::AsType::Draft3 - Role processing draft3 JSON Schema |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 VERSION |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
version 0.4.1 |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
This role is not intended to be used directly. It is used internally |
|
290
|
|
|
|
|
|
|
by L<JSON::Schema::AsType> objects. |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
Importing this module auto-populate the Draft3 schema in the |
|
293
|
|
|
|
|
|
|
L<JSON::Schema::AsType> schema cache. |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 AUTHOR |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Yanick Champoux <yanick@babyl.dyndns.org> |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Yanick Champoux. |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
304
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=cut |