| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
45
|
|
|
45
|
|
338
|
use strict; |
|
|
45
|
|
|
|
|
106
|
|
|
|
45
|
|
|
|
|
2225
|
|
|
2
|
45
|
|
|
45
|
|
277
|
use warnings; |
|
|
45
|
|
|
|
|
99
|
|
|
|
45
|
|
|
|
|
4329
|
|
|
3
|
|
|
|
|
|
|
package JSON::Schema::Modern::Document; |
|
4
|
|
|
|
|
|
|
# vim: set ts=8 sts=2 sw=2 tw=100 et : |
|
5
|
|
|
|
|
|
|
# ABSTRACT: One JSON Schema document |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.634'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
45
|
|
|
45
|
|
979
|
use 5.020; |
|
|
45
|
|
|
|
|
198
|
|
|
10
|
45
|
|
|
45
|
|
368
|
use Moo; |
|
|
45
|
|
|
|
|
108
|
|
|
|
45
|
|
|
|
|
375
|
|
|
11
|
45
|
|
|
45
|
|
21739
|
use strictures 2; |
|
|
45
|
|
|
|
|
520
|
|
|
|
45
|
|
|
|
|
2344
|
|
|
12
|
45
|
|
|
45
|
|
25353
|
use stable 0.031 'postderef'; |
|
|
45
|
|
|
|
|
966
|
|
|
|
45
|
|
|
|
|
388
|
|
|
13
|
45
|
|
|
45
|
|
11299
|
use experimental 'signatures'; |
|
|
45
|
|
|
|
|
177
|
|
|
|
45
|
|
|
|
|
255
|
|
|
14
|
45
|
|
|
45
|
|
3445
|
no autovivification warn => qw(fetch store exists delete); |
|
|
45
|
|
|
|
|
151
|
|
|
|
45
|
|
|
|
|
457
|
|
|
15
|
45
|
|
|
45
|
|
4778
|
use if "$]" >= 5.022, experimental => 're_strict'; |
|
|
45
|
|
|
|
|
183
|
|
|
|
45
|
|
|
|
|
1549
|
|
|
16
|
45
|
|
|
45
|
|
4896
|
no if "$]" >= 5.031009, feature => 'indirect'; |
|
|
45
|
|
|
|
|
122
|
|
|
|
45
|
|
|
|
|
4214
|
|
|
17
|
45
|
|
|
45
|
|
387
|
no if "$]" >= 5.033001, feature => 'multidimensional'; |
|
|
45
|
|
|
|
|
120
|
|
|
|
45
|
|
|
|
|
3446
|
|
|
18
|
45
|
|
|
45
|
|
352
|
no if "$]" >= 5.033006, feature => 'bareword_filehandles'; |
|
|
45
|
|
|
|
|
116
|
|
|
|
45
|
|
|
|
|
3788
|
|
|
19
|
45
|
|
|
45
|
|
368
|
no if "$]" >= 5.041009, feature => 'smartmatch'; |
|
|
45
|
|
|
|
|
158
|
|
|
|
45
|
|
|
|
|
2796
|
|
|
20
|
45
|
|
|
45
|
|
322
|
no feature 'switch'; |
|
|
45
|
|
|
|
|
95
|
|
|
|
45
|
|
|
|
|
2183
|
|
|
21
|
45
|
|
|
45
|
|
292
|
use Mojo::URL; |
|
|
45
|
|
|
|
|
215
|
|
|
|
45
|
|
|
|
|
638
|
|
|
22
|
45
|
|
|
45
|
|
2138
|
use Carp 'croak'; |
|
|
45
|
|
|
|
|
176
|
|
|
|
45
|
|
|
|
|
4865
|
|
|
23
|
45
|
|
|
45
|
|
385
|
use List::Util 1.29 'pairs'; |
|
|
45
|
|
|
|
|
1235
|
|
|
|
45
|
|
|
|
|
4390
|
|
|
24
|
45
|
|
|
45
|
|
476
|
use builtin::compat qw(refaddr blessed); |
|
|
45
|
|
|
|
|
111
|
|
|
|
45
|
|
|
|
|
559
|
|
|
25
|
45
|
|
|
45
|
|
10346
|
use Safe::Isa 1.000008; |
|
|
45
|
|
|
|
|
1339
|
|
|
|
45
|
|
|
|
|
7898
|
|
|
26
|
45
|
|
|
45
|
|
437
|
use MooX::TypeTiny; |
|
|
45
|
|
|
|
|
105
|
|
|
|
45
|
|
|
|
|
435
|
|
|
27
|
45
|
|
|
45
|
|
49009
|
use Types::Standard 1.016003 qw(InstanceOf HashRef Str Map Dict ArrayRef Enum ClassName Undef Slurpy Optional Bool); |
|
|
45
|
|
|
|
|
931
|
|
|
|
45
|
|
|
|
|
477
|
|
|
28
|
45
|
|
|
45
|
|
176850
|
use Types::Common::Numeric 'PositiveOrZeroInt'; |
|
|
45
|
|
|
|
|
124
|
|
|
|
45
|
|
|
|
|
489
|
|
|
29
|
45
|
|
|
45
|
|
47497
|
use JSON::Schema::Modern::Utilities qw(json_pointer_type canonical_uri_type E); |
|
|
45
|
|
|
|
|
124
|
|
|
|
45
|
|
|
|
|
3617
|
|
|
30
|
45
|
|
|
45
|
|
333
|
use namespace::clean; |
|
|
45
|
|
|
|
|
110
|
|
|
|
45
|
|
|
|
|
320
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
extends 'Mojo::JSON::Pointer'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has schema => ( |
|
35
|
|
|
|
|
|
|
is => 'ro', |
|
36
|
|
|
|
|
|
|
required => 1, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has canonical_uri => ( |
|
40
|
|
|
|
|
|
|
is => 'rwp', |
|
41
|
|
|
|
|
|
|
isa => (InstanceOf['Mojo::URL'])->where(q{not defined $_->fragment}), |
|
42
|
|
|
|
|
|
|
lazy => 1, |
|
43
|
|
|
|
|
|
|
default => sub { Mojo::URL->new }, |
|
44
|
|
|
|
|
|
|
coerce => sub { $_[0]->$_isa('Mojo::URL') ? $_[0] : Mojo::URL->new($_[0]) }, |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# this is also known as the retrieval uri in the OpenAPI specification |
|
48
|
|
|
|
|
|
|
has original_uri => ( |
|
49
|
|
|
|
|
|
|
is => 'rwp', |
|
50
|
|
|
|
|
|
|
isa => (InstanceOf['Mojo::URL'])->where(q{not defined $_->fragment}), |
|
51
|
|
|
|
|
|
|
init_arg => undef, |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
*retrieval_uri = \&original_uri; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has metaschema_uri => ( |
|
56
|
|
|
|
|
|
|
is => 'rwp', |
|
57
|
|
|
|
|
|
|
isa => InstanceOf['Mojo::URL'], |
|
58
|
|
|
|
|
|
|
coerce => sub { $_[0]->$_isa('Mojo::URL') ? $_[0] : Mojo::URL->new($_[0]) }, |
|
59
|
|
|
|
|
|
|
predicate => '_has_metaschema_uri', |
|
60
|
|
|
|
|
|
|
# default not defined here, but might be defined in a subclass |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# "A JSON Schema resource is a schema which is canonically identified by an absolute URI." |
|
64
|
|
|
|
|
|
|
# https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.4.3.5 |
|
65
|
|
|
|
|
|
|
has resource_index => ( |
|
66
|
|
|
|
|
|
|
is => 'bare', |
|
67
|
|
|
|
|
|
|
isa => Map[my $resource_key_type = Str->where('!/#/'), my $resource_type = Dict[ |
|
68
|
|
|
|
|
|
|
canonical_uri => (InstanceOf['Mojo::URL'])->where(q{not defined $_->fragment}), |
|
69
|
|
|
|
|
|
|
path => json_pointer_type, # JSON pointer relative to the document root |
|
70
|
|
|
|
|
|
|
specification_version => Enum[qw(draft4 draft6 draft7 draft2019-09 draft2020-12)], |
|
71
|
|
|
|
|
|
|
# the vocabularies used when evaluating instance data against schema |
|
72
|
|
|
|
|
|
|
vocabularies => ArrayRef[ClassName->where(q{$_->DOES('JSON::Schema::Modern::Vocabulary')})], |
|
73
|
|
|
|
|
|
|
anchors => Optional[HashRef[Dict[ |
|
74
|
|
|
|
|
|
|
canonical_uri => canonical_uri_type, # equivalent uri with json pointer fragment |
|
75
|
|
|
|
|
|
|
path => json_pointer_type, # JSON pointer relative to the document root |
|
76
|
|
|
|
|
|
|
dynamic => Optional[Bool], |
|
77
|
|
|
|
|
|
|
]]], |
|
78
|
|
|
|
|
|
|
Slurpy[HashRef[Undef]], # no other fields allowed |
|
79
|
|
|
|
|
|
|
]], |
|
80
|
|
|
|
|
|
|
init_arg => undef, |
|
81
|
|
|
|
|
|
|
default => sub { {} }, |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
|
|
84
|
52
|
|
|
52
|
1
|
111879
|
sub resource_index { $_[0]->{resource_index}->%* } |
|
85
|
18124
|
|
|
18124
|
0
|
313815
|
sub resource_pairs { pairs $_[0]->{resource_index}->%* } |
|
86
|
3113
|
|
|
3113
|
|
512015
|
sub _get_resource { $_[0]->{resource_index}{$_[1]} } |
|
87
|
0
|
|
|
0
|
|
0
|
sub _canonical_resources { values $_[0]->{resource_index}->%* } |
|
88
|
|
|
|
|
|
|
sub _add_resource { |
|
89
|
18652
|
100
|
|
18652
|
|
3307478
|
croak 'uri "'.$_[1].'" conflicts with an existing schema resource' if $_[0]->{resource_index}{$_[1]}; |
|
90
|
18651
|
|
|
|
|
606232
|
$_[0]->{resource_index}{$resource_key_type->($_[1])} = $resource_type->($_[2]); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# for internal use only |
|
94
|
|
|
|
|
|
|
has _checksum => ( |
|
95
|
|
|
|
|
|
|
is => 'rw', |
|
96
|
|
|
|
|
|
|
isa => Str, |
|
97
|
|
|
|
|
|
|
init_arg => undef, |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
has errors => ( |
|
101
|
|
|
|
|
|
|
is => 'bare', |
|
102
|
|
|
|
|
|
|
writer => '_set_errors', |
|
103
|
|
|
|
|
|
|
isa => ArrayRef[InstanceOf['JSON::Schema::Modern::Error']], |
|
104
|
|
|
|
|
|
|
lazy => 1, |
|
105
|
|
|
|
|
|
|
default => sub { [] }, |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
200
|
|
100
|
200
|
1
|
13777
|
sub errors { ($_[0]->{errors}//[])->@* } |
|
109
|
18269
|
|
100
|
18269
|
0
|
178976
|
sub has_errors { scalar(($_[0]->{errors}//[])->@*) } |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# json pointer => entity name (indexed by integer) |
|
112
|
|
|
|
|
|
|
has _entities => ( |
|
113
|
|
|
|
|
|
|
is => 'ro', |
|
114
|
|
|
|
|
|
|
isa => Map[json_pointer_type, PositiveOrZeroInt], |
|
115
|
|
|
|
|
|
|
lazy => 1, |
|
116
|
|
|
|
|
|
|
default => sub { {} }, |
|
117
|
|
|
|
|
|
|
); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# in this class, the only entity type is 'schema', but subclasses add more |
|
120
|
108602
|
|
|
108602
|
|
337123
|
sub __entities ($) { qw(schema) } |
|
|
108602
|
|
|
|
|
162274
|
|
|
|
108602
|
|
|
|
|
506429
|
|
|
121
|
42098
|
|
|
42098
|
|
118437
|
sub __entity_type { Enum[$_[0]->__entities] } |
|
122
|
42098
|
|
|
42098
|
|
4807627
|
sub __entity_index ($self, $entity) { |
|
|
42098
|
|
|
|
|
105710
|
|
|
|
42098
|
|
|
|
|
90194
|
|
|
|
42098
|
|
|
|
|
74755
|
|
|
123
|
42098
|
|
|
|
|
132762
|
my @e = $self->__entities; |
|
124
|
42098
|
50
|
|
|
|
158366
|
foreach my $i (0..$#e) { return $i if $e[$i] eq $entity; } |
|
|
42098
|
|
|
|
|
1375029
|
|
|
125
|
0
|
|
|
|
|
0
|
return undef; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
42097
|
|
|
42097
|
|
509696
|
sub _add_entity_location ($self, $location, $entity) { |
|
|
42097
|
|
|
|
|
80625
|
|
|
|
42097
|
|
|
|
|
83986
|
|
|
|
42097
|
|
|
|
|
76247
|
|
|
|
42097
|
|
|
|
|
67481
|
|
|
129
|
42097
|
|
|
|
|
126654
|
$self->__entity_type->($entity); # verify string |
|
130
|
42097
|
|
|
|
|
62025158
|
$self->_entities->{$location} = $self->__entity_index($entity); # store integer-mapped value |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
24460
|
|
|
24460
|
0
|
93600
|
sub get_entity_at_location ($self, $location) { |
|
|
24460
|
|
|
|
|
47008
|
|
|
|
24460
|
|
|
|
|
54323
|
|
|
|
24460
|
|
|
|
|
39220
|
|
|
134
|
24460
|
100
|
|
|
|
819487
|
return '' if not exists $self->_entities->{$location}; |
|
135
|
24406
|
|
33
|
|
|
767358
|
($self->__entities)[ $self->_entities->{$location} ] // croak "missing mapping for ", $self->_entities->{$location}; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# note: not sorted |
|
139
|
1
|
|
|
1
|
0
|
3
|
sub get_entity_locations ($self, $entity) { |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
2
|
|
|
140
|
1
|
|
|
|
|
5
|
$self->__entity_type->($entity); # verify string |
|
141
|
1
|
|
|
|
|
2168
|
my $index = $self->__entity_index($entity); |
|
142
|
1
|
|
|
|
|
27
|
grep $self->{_entities}{$_} == $index, keys $self->{_entities}->%*; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# shims for Mojo::JSON::Pointer |
|
146
|
26803
|
|
|
26803
|
1
|
383371
|
sub data { shift->schema(@_) } |
|
147
|
17911
|
|
|
17911
|
0
|
2037479
|
sub FOREIGNBUILDARGS { () } |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# for JSON serializers |
|
150
|
0
|
|
|
0
|
1
|
0
|
sub TO_JSON { shift->schema } |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# note that this is always called, even in subclasses |
|
153
|
17910
|
|
|
17910
|
0
|
558783
|
sub BUILD ($self, $args) { |
|
|
17910
|
|
|
|
|
41117
|
|
|
|
17910
|
|
|
|
|
40148
|
|
|
|
17910
|
|
|
|
|
49368
|
|
|
154
|
|
|
|
|
|
|
# note! not a clone! Please don't change canonical_uri in-place. |
|
155
|
17910
|
|
|
|
|
424674
|
$self->_set_original_uri($self->canonical_uri); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# this should extract all identifiers, references, and entities, and set canonical_uri, |
|
158
|
|
|
|
|
|
|
# metaschema_uri |
|
159
|
|
|
|
|
|
|
my $state = $self->traverse( |
|
160
|
|
|
|
|
|
|
$args->{evaluator} // JSON::Schema::Modern->new, |
|
161
|
|
|
|
|
|
|
{ |
|
162
|
|
|
|
|
|
|
$args->{specification_version} ? $args->%{specification_version} : (), |
|
163
|
17910
|
100
|
66
|
|
|
2577339
|
$args->{skip_ref_checks} ? $args->%{skip_ref_checks} : (), |
|
|
|
100
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
}, |
|
165
|
|
|
|
|
|
|
); |
|
166
|
|
|
|
|
|
|
|
|
167
|
17910
|
100
|
|
|
|
137656
|
if ($state->{errors}->@*) { |
|
168
|
149
|
|
|
|
|
4375
|
$self->_set_errors($state->{errors}); |
|
169
|
149
|
|
|
|
|
5174
|
return; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
17761
|
|
|
|
|
38776
|
my $seen_root; |
|
173
|
17761
|
|
|
|
|
95570
|
foreach my $key (keys $state->{identifiers}->%*) { |
|
174
|
2077
|
|
|
|
|
10122
|
my $value = $state->{identifiers}{$key}; |
|
175
|
2077
|
|
|
|
|
10074
|
$self->_add_resource($key => $value); |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# we're adding a non-anchor entry for the document root |
|
178
|
2077
|
100
|
|
|
|
1145617
|
++$seen_root if $value->{path} eq ''; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# we only index the original uri if nothing in the schema itself identified a root resource: |
|
182
|
|
|
|
|
|
|
# otherwise the top of the document would be unreferenceable. |
|
183
|
|
|
|
|
|
|
$self->_add_resource($self->original_uri.'' => { |
|
184
|
|
|
|
|
|
|
path => '', |
|
185
|
|
|
|
|
|
|
canonical_uri => $self->canonical_uri, |
|
186
|
17761
|
100
|
|
|
|
165726
|
$state->%{qw(specification_version vocabularies)}, |
|
187
|
|
|
|
|
|
|
}) |
|
188
|
|
|
|
|
|
|
if not $seen_root; |
|
189
|
|
|
|
|
|
|
|
|
190
|
17760
|
|
100
|
|
|
8221678
|
foreach my $ref (($state->{references}//[])->@*) { |
|
191
|
3112
|
|
|
|
|
13553
|
my ($keyword, $path_location, $abs_target, $expected_entity) = @$ref; |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# look for resource locally; fall back to the evaluator's index |
|
194
|
3112
|
|
|
|
|
17442
|
my $resource = $self->_get_resource(my $uri = $abs_target->clone->fragment(undef)); |
|
195
|
3112
|
|
|
|
|
656705
|
my $document = $self; |
|
196
|
|
|
|
|
|
|
|
|
197
|
3112
|
100
|
|
|
|
11084
|
if (not $resource) { |
|
198
|
521
|
50
|
|
|
|
5961
|
$resource = $args->{evaluator}->_get_resource($uri) if $args->{evaluator}; |
|
199
|
521
|
100
|
|
|
|
115539
|
next if not $resource; |
|
200
|
352
|
|
|
|
|
2006
|
$document = $resource->{document}; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
|
|
203
|
2943
|
|
|
|
|
8960
|
my $fragment = $abs_target->fragment; |
|
204
|
2943
|
|
|
|
|
14810
|
my $target_path; |
|
205
|
2943
|
100
|
100
|
|
|
23365
|
if (not length $fragment or $fragment =~ m{^/}) { |
|
|
|
100
|
50
|
|
|
|
|
|
206
|
|
|
|
|
|
|
()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, |
|
207
|
|
|
|
|
|
|
'%s target "%s" is a non-existent location', $keyword, $abs_target), next |
|
208
|
2628
|
100
|
100
|
|
|
27518
|
if not $document->contains($target_path = $resource->{path}.($fragment//'')); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
elsif (my $subresource = ($resource->{anchors}//{})->{$fragment}) { |
|
211
|
311
|
|
|
|
|
1242
|
$target_path = $subresource->{path}; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
else { |
|
214
|
4
|
|
|
|
|
43
|
()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, |
|
215
|
|
|
|
|
|
|
'%s target "%s" is a non-existent location', $keyword, $abs_target); |
|
216
|
4
|
|
|
|
|
38
|
next; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
2935
|
|
|
|
|
85307
|
my $entity = $document->get_entity_at_location($target_path); |
|
220
|
2935
|
100
|
|
|
|
10374
|
()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, |
|
221
|
|
|
|
|
|
|
'%s target "%s" is not a referenceable location', $keyword, $abs_target), next |
|
222
|
|
|
|
|
|
|
if not $entity; |
|
223
|
|
|
|
|
|
|
|
|
224
|
2889
|
50
|
|
|
|
35648
|
()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, |
|
225
|
|
|
|
|
|
|
'%s target "%s" is the wrong object type (%s, expecting %s)', |
|
226
|
|
|
|
|
|
|
$keyword, $abs_target, $entity, $expected_entity), next |
|
227
|
|
|
|
|
|
|
if $entity ne $expected_entity; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
17760
|
100
|
|
|
|
354168
|
$self->_set_errors($state->{errors}) if $state->{errors}->@*; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# a subclass's method will override this one |
|
234
|
17909
|
|
|
17909
|
0
|
42753
|
sub traverse ($self, $evaluator, $config_override = {}) { |
|
|
17909
|
|
|
|
|
37323
|
|
|
|
17909
|
|
|
|
|
36246
|
|
|
|
17909
|
|
|
|
|
43268
|
|
|
|
17909
|
|
|
|
|
36223
|
|
|
235
|
|
|
|
|
|
|
die 'wrong class - use JSON::Schema::Modern::Document::OpenAPI instead' |
|
236
|
17909
|
50
|
66
|
|
|
208410
|
if ref $self->schema eq 'HASH' and exists $self->schema->{openapi}; |
|
237
|
|
|
|
|
|
|
|
|
238
|
17909
|
|
|
|
|
58745
|
my $original_uri = $self->original_uri; |
|
239
|
|
|
|
|
|
|
|
|
240
|
17909
|
100
|
|
|
|
211823
|
my $state = $evaluator->traverse($self->schema, |
|
241
|
|
|
|
|
|
|
{ |
|
242
|
|
|
|
|
|
|
initial_schema_uri => $original_uri, |
|
243
|
|
|
|
|
|
|
$self->_has_metaschema_uri ? (metaschema_uri => $self->metaschema_uri) : (), |
|
244
|
|
|
|
|
|
|
%$config_override, |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
); |
|
247
|
|
|
|
|
|
|
|
|
248
|
17909
|
50
|
33
|
|
|
168896
|
die 'original_uri has changed' if $self->original_uri ne $original_uri |
|
249
|
|
|
|
|
|
|
or refaddr($self->original_uri) != refaddr($original_uri); |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# if the document identified a canonical uri for itself via '$id', or metaschema uri via '$schema', |
|
252
|
|
|
|
|
|
|
# they overrides the initial values |
|
253
|
|
|
|
|
|
|
# Note that subclasses of this class may choose to identify these values in a different way |
|
254
|
|
|
|
|
|
|
# (e.g. "$self" in OpenAPI) |
|
255
|
17909
|
|
|
|
|
5460474
|
$self->_set_canonical_uri($state->{initial_schema_uri}); |
|
256
|
17909
|
|
|
|
|
1815575
|
$self->_set_metaschema_uri($state->{metaschema_uri}); |
|
257
|
|
|
|
|
|
|
|
|
258
|
17909
|
|
|
|
|
2751816
|
$self->_add_entity_location($_, 'schema') foreach $state->{subschemas}->@*; |
|
259
|
|
|
|
|
|
|
|
|
260
|
17909
|
|
|
|
|
380510
|
return $state; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
|
|
263
|
3
|
|
|
3
|
1
|
5497
|
sub validate ($class, @args) { |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
8
|
|
|
264
|
3
|
50
|
|
|
|
16
|
croak 'bad argument list' if blessed($args[0]); |
|
265
|
|
|
|
|
|
|
|
|
266
|
3
|
|
|
|
|
24
|
my $args = $class->Moo::Object::BUILDARGS(@args); |
|
267
|
3
|
50
|
|
|
|
36
|
my $document = blessed($class) ? $class : $class->new($args); |
|
268
|
|
|
|
|
|
|
|
|
269
|
3
|
|
|
|
|
13
|
my $doc_result = JSON::Schema::Modern::Result->new(errors => [ $document->errors ]); |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# ideally, the traverse phase run during document construction should have found all errors that a |
|
272
|
|
|
|
|
|
|
# simple metaschema evaluation would reveal, but we'll do both just to make sure. |
|
273
|
3
|
|
66
|
|
|
76
|
my $evaluator = $args->{evaluator} // JSON::Schema::Modern->new(validate_formats => 1); |
|
274
|
3
|
|
|
|
|
100
|
my $eval_result = $evaluator->evaluate($document->schema, $document->metaschema_uri); |
|
275
|
|
|
|
|
|
|
|
|
276
|
3
|
100
|
|
|
|
18
|
if (my ($missing_resource) = grep $_->error =~ /EXCEPTION: unable to find resource/, $eval_result->errors) { |
|
277
|
1
|
|
|
|
|
24
|
$missing_resource->{error} .= ' (did you forget to provide "evaluator" to ->validate?)'; |
|
278
|
|
|
|
|
|
|
} |
|
279
|
|
|
|
|
|
|
|
|
280
|
3
|
|
|
|
|
54
|
return $doc_result & $eval_result; |
|
281
|
|
|
|
|
|
|
} |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# callback hook for Sereal::Encoder |
|
284
|
7
|
|
|
7
|
0
|
53
|
sub FREEZE ($self, $serializer) { +{ %$self } } |
|
|
7
|
|
|
|
|
16
|
|
|
|
7
|
|
|
|
|
17
|
|
|
|
7
|
|
|
|
|
10
|
|
|
|
7
|
|
|
|
|
512
|
|
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
# callback hook for Sereal::Decoder |
|
287
|
10
|
|
|
10
|
0
|
753512
|
sub THAW ($class, $serializer, $data) { |
|
|
10
|
|
|
|
|
26
|
|
|
|
10
|
|
|
|
|
21
|
|
|
|
10
|
|
|
|
|
17
|
|
|
|
10
|
|
|
|
|
19
|
|
|
288
|
10
|
|
|
|
|
37
|
delete $data->{evaluator}; |
|
289
|
|
|
|
|
|
|
|
|
290
|
10
|
|
|
|
|
24
|
my $self = bless($data, $class); |
|
291
|
|
|
|
|
|
|
|
|
292
|
10
|
|
|
|
|
25
|
foreach my $attr (qw(schema _entities)) { |
|
293
|
|
|
|
|
|
|
croak "serialization missing attribute '$attr' on document for identifier '$self->{canonical_uri}': perhaps your serialized data was produced for an older version of $class?" |
|
294
|
20
|
50
|
|
|
|
90
|
if not exists $self->{$attr}; |
|
295
|
|
|
|
|
|
|
} |
|
296
|
10
|
|
|
|
|
99
|
return $self; |
|
297
|
|
|
|
|
|
|
} |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
1; |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
__END__ |