JSON/Schema/Modern/Document/OpenAPI.pm

filter: Statementstmt 96.8% 370 / 382 Branchbran 89.6% 208 / 232 Conditioncond 81.4% 132 / 162 MC/DCmcdc 64.3% 56 / 87 Subroutinesub 93.6% 44 / 47 Podpod 63.6% 7 / 11 totaltotal 88.7% 817 / 921 CC 203 SCAR 41.0
CC
203
Cov
91%
traverse
109.2
__ANON__
41.1
upgrade
40.7
CRAP 60.5
↑ Summary OpenAPI/Modern.pm »
1 18 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package JSON::Schema::Modern::Document::OpenAPI;
3 # vim: set ts=8 sts=2 sw=2 tw=100 et :
4 # ABSTRACT: One OpenAPI v3.0, v3.1 or v3.2 document
5 # KEYWORDS: JSON Schema data validation request response OpenAPI
6  
7 18 our $VERSION = '0.153';
8  
9 18 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 18 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶no autovivification warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶no if "$]" >= 5.041009, feature => 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 18 ▶use JSON::Schema::Modern::Utilities qw(E canonical_uri jsonp unjsonp is_equal json_pointer_type assert_keyword_type assert_uri_reference load_cached_document get_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 18 ▶use JSON::Schema::Modern::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 18 ▶use OpenAPI::Modern::Utilities qw(:constants add_vocab_and_default_schemas add_formats);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 18 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 18 ▶use Digest::MD5 'md5_hex';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 18 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 18 ▶use builtin::compat qw(blessed indexed);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 18 ▶use MooX::TypeTiny 0.002002;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 18 ▶use Types::Standard qw(HashRef ArrayRef Str Map Any);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 18 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 18 extends 'JSON::Schema::Modern::Document';
34  
35 18 our @CARP_NOT = qw(Sereal Sereal::Decoder JSON::Schema::Modern::Document);
36  
37 18 has '+schema' => (
38 isa => HashRef,
39 );
40  
41 # json pointer => entity name (indexed by integer); overrides parent
42 # these aren't all the different types of objects; for now we only track those that are the valid
43 # target of a $ref keyword in an openapi document.
44 12784 ▶sub __entities { qw(schema response parameter example request-body header security-scheme link callbacks path-item media-type) }
Subroutine __entities: called CC=1 SCAR=0.0
45  
46 # operationId => document path
47 has _operationIds => (
48 is => 'ro',
49 isa => HashRef[json_pointer_type],
50 lazy => 1,
51 59 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 18 );
53  
54 18 *get_operationId_path = \&operationId_path; # deprecated
55  
56 200 ▶sub operationId_path { $_[0]->_operationIds->{$_[1]} }
Subroutine operationId_path: called CC=1 SCAR=0.0
Pod documented
57 101 ▶sub _add_operationId { $_[0]->_operationIds->{$_[1]} = json_pointer_type->($_[2]) }
Subroutine _add_operationId: called CC=1 SCAR=0.0
58  
59 # tag name => document path of tag object
60 18 has _tags => (
61 is => 'bare',
62 isa => HashRef[json_pointer_type],
63 );
64  
65 5 ▶sub tag_path { $_[0]->{_tags}{$_[1]} }
Subroutine tag_path: called CC=1 SCAR=0.0
Pod documented
66  
67 # tag name => document path of operation
68 18 has _operation_tags => (
69 is => 'bare',
70 isa => HashRef[ArrayRef[json_pointer_type]],
71 );
72  
73 6 ▶sub operations_with_tag { ($_[0]->{_operation_tags}{$_[1]}//[])->@* }
Subroutine operations_with_tag: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{"_operation_tags"}{$_[1]} // []
l!l
51
MC/DC100%1/1
$_[0]{"_operation_tags"}{$_[1]} // []
$_[0]{"_operation_tags"}{$_[1]}
Truth table100%2/2
A
A= $_[0]{"_operation_tags"}{$_[1]}
Aresult
11
00
74  
75 # the minor.major version of the OpenAPI specification used for this document
76 18 has oas_version => (
77 is => 'rwp',
78 isa => Str->where(q{/^[1-9]\.(?:0|[1-9][0-9]*)\z/}),
79 );
80  
81 # list of /paths/* path templates, in canonical search order
82 18 has path_templates => (
83 is => 'rwp',
84 isa => ArrayRef[Str],
85 );
86  
87 has defaults => (
88 is => 'rwp',
89 isa => Map[json_pointer_type, Any],
90 lazy => 1,
91 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 18 );
93  
94 1 ▶sub default { $_[0]->defaults->{$_[1]} }
Subroutine default: called CC=1 SCAR=0.0
Pod documented
95  
96 # encoding/contentType value => arrayref of media-types (split by comma)
97 18 has _encoding_contentTypes => (
98 is => 'bare',
99 isa => HashRef[ArrayRef[Str]],
100 );
101  
102 168 ▶sub encoding_contentTypes ($self, $contentType) {
Subroutine encoding_contentTypes: called CC=1 SCAR=0.0
Pod undocumented
103 168 $self->{_encoding_contentTypes}{$contentType};
104 }
105  
106 # we define the sub directly, rather than using an 'around', since our root base class is not
107 # Moo::Object, so we never got a BUILDARGS to modify
108 601 ▶sub BUILDARGS ($class, @args) {
Subroutine BUILDARGS: called CC=3 SCAR=11.0
Pod undocumented
109 601 my $args = $class->Moo::Object::BUILDARGS(@args); # we do not inherit from Moo::Object
110  
111 carp 'json_schema_dialect has been removed as a constructor attribute: use jsonSchemaDialect in your document instead'
112 601 ▶ if exists $args->{json_schema_dialect};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"json_schema_dialect"} 1 600 601
113  
114 carp 'specification_version argument is ignored by this subclass: use jsonSchemaDialect in your document instead'
115 601 ▶ if defined(delete($args->{specification_version}));
Branch: 1 branch
BranchTrueFalseTotal
if defined delete($$args{"specification_version"}) 1 600 601
116  
117 601 return $args;
118 }
119  
120 # (probably) temporary, until the parent class evaluator is completely removed
121 0 ▶sub evaluator { die 'improper attempt to use of document evaluator' }
Subroutine evaluator: not called CC=1 SCAR=6.9
Pod documented
122  
123 # called by this class's base class constructor, in order to validate the integrity of the document
124 # and identify all important details about this document, such as entity locations, referenceable
125 # identifiers, operationIds, etc.
126 599 ▶sub traverse ($self, $evaluator, $config_override = {}) {
Subroutine traverse: called CC=107 SCAR=46.9
Pod undocumented
127 599 ▶ croak join(', ', sort keys %$config_override), ' not supported as a config override in traverse'
Branch: 1 branch
BranchTrueFalseTotal
if keys %$config_override 0 599 599
128 if keys %$config_override;
129  
130 599 my $state = {
131 initial_schema_uri => $self->canonical_uri, # for now, same as original_uri, retrieval_uri
132 traversed_keyword_path => '',
133 keyword_path => '',
134 data_path => '',
135 errors => [],
136 evaluator => $evaluator,
137 identifiers => {},
138 # note that this is the version of the JSON Schema dialect used to define the OpenAPI document,
139 # not the OpenAPI specification version
140 specification_version => $evaluator->SPECIFICATION_VERSION_DEFAULT,
141 vocabularies => [],
142 subschemas => [],
143 references => [],
144 depth => 0,
145 traverse => 1,
146 };
147  
148 599 my $schema = $self->schema;
149  
150 599 ▶ ()= E($state, 'missing openapi version'), return $state if not exists $schema->{openapi};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{"openapi"} 1 598 599
151 ()= E($state, 'bad openapi version: "%s"', $schema->{openapi}//''), return $state
152 598 ▶ if ($schema->{openapi}//'') !~ /^\d+\.\d+\.\d+(-.+)?\z/a;
Branch: 1 branch
BranchTrueFalseTotal
unless ($$schema{"openapi"} // "") =~ /^\d+\.\d+\.\d+(-.+)?\z/a 4 594 598
Condition100%4/4
$$schema{"openapi"} // ""
l!l
5971
$$schema{"openapi"} // ""
l!l
31
MC/DC100%1/1
$$schema{"openapi"} // ""
$$schema{"openapi"}
MC/DC100%1/1
$$schema{"openapi"} // ""
$$schema{"openapi"}
Truth table100%2/2
A
A= $$schema{"openapi"}
Aresult
11
00
Truth table100%2/2
A
A= $$schema{"openapi"}
Aresult
11
00
153  
154 594 my @oad_version = split /[.-]/, $schema->{openapi};
155 594 $self->_set_oas_version(join('.', @oad_version[0..1]));
156  
157 594 my ($max_supported) = grep do {
158 1782 my @supported = split /\./;
159 1782 ▶ $supported[0] == $oad_version[0] && $supported[1] == $oad_version[1]
Condition100%3/3
$supported[0] == $oad_version[0] && $supported[1] == $oad_version[1]
!ll&&!rl&&r
91183590
MC/DC100%2/2
$supported[0] == $oad_version[0] && $supported[1] == $oad_version[1]
$supported[0] == $oad_version[0] $supported[1] == $oad_version[1]
Truth table100%3/3
A && B
A= $supported[0] == $oad_version[0]B= $supported[1] == $oad_version[1]
ABresult
0X0
100
111
160 }, reverse SUPPORTED_OAD_VERSIONS->@*;
161  
162 594 ▶ ()= E($state, 'unrecognized/unsupported openapi version: "%s"', $schema->{openapi}), return $state
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_supported 4 590 594
163 if not defined $max_supported;
164 carp 'WARNING: your document was written for version ', $schema->{openapi},
165 590 ▶ ' but this implementation has only been tested up to ', $max_supported,
Branch: 1 branch
BranchTrueFalseTotal
if defined $oad_version[2] and (split(/\./u, $max_supported, 0))[2] < $oad_version[2] 30 560 590
Condition66%2/3
defined $oad_version[2] and (split(/\./u, $max_supported, 0))[2] < $oad_version[2]
!ll&&!rl&&r
056030
MC/DC50%1/2
defined $oad_version[2] and (split(/\./u, $max_supported, 0))[2] < $oad_version[2]
defined $oad_version[2] (split(/\./u, $max_supported, 0))[2] < $oad_version[2]
Truth table66%2/3
A and B
A= defined $oad_version[2]B= (split(/\./u, $max_supported, 0))[2] < $oad_version[2]
ABresult
0X0
100
111
166 ': this may be okay but you should upgrade your OpenAPI::Modern installation soon',"\n"
167 if defined $oad_version[2] and (split(/\./, $max_supported))[2] < $oad_version[2];
168  
169 590 add_vocab_and_default_schemas($evaluator, $self->oas_version);
170 590 add_formats($evaluator, $self->oas_version);
171  
172 590 ▶ if (exists $schema->{'$self'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$schema{"\$self"}) 14 576 590
173 14 my $state = { %$state, keyword => '$self', initial_schema_uri => Mojo::URL->new };
174  
175 14 ▶ if ($oad_version[0] == 3 and $oad_version[1] < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oad_version[0] == 3 and $oad_version[1] < 2) 1 13 14
Condition66%2/3
$oad_version[0] == 3 and $oad_version[1] < 2
!ll&&!rl&&r
0131
MC/DC50%1/2
$oad_version[0] == 3 and $oad_version[1] < 2
$oad_version[0] == 3 $oad_version[1] < 2
Truth table66%2/3
A and B
A= $oad_version[0] == 3B= $oad_version[1] < 2
ABresult
0X0
100
111
176 1 ()= E($state, 'additional property not permitted');
177 1 return $state;
178 }
179  
180 return $state
181 if not assert_keyword_type($state, $schema, 'string')
182 or not assert_uri_reference($state, $schema)
183 13 ▶ or not ($schema->{'$self'} !~ /#/ || E($state, '$self cannot contain a fragment'));
Branch: 1 branch
BranchTrueFalseTotal
unless assert_keyword_type($state, $schema, "string") and assert_uri_reference($state, $schema) and !($$schema{"\$self"} =~ /#/u) || E($state, "\$self cannot contain a fragment") 2 11 13
Condition77%7/9
assert_keyword_type($state, $schema, "string") and assert_uri_reference($state, $schema) and !($$schema{"\$self"} =~ /#/u) || E($state, "\$self cannot contain a fragment")
!ll&&!rl&&r
1111
assert_keyword_type($state, $schema, "string") and assert_uri_reference($state, $schema)
!ll&&!rl&&r
0112
not $$schema{"\$self"} =~ /#/u or E($state, "\$self cannot contain a fragment")
l!l&&r!l&&!r
1101
MC/DC50%2/4
assert_keyword_type($state, $schema, "string") and assert_uri_reference($state, $schema) and !($$schema{"\$self"} =~ /#/u) || E($state, "\$self cannot contain a fragment")
assert_keyword_type($state, $schema, "string") assert_uri_reference($state, $schema) not $$schema{"\$self"} =~ /#/u E($state, "\$self cannot contain a fragment")
Truth table60%3/5
A and B and not(C) or D
A= assert_keyword_type($state, $schema, "string")B= assert_uri_reference($state, $schema)C= not $$schema{"\$self"} =~ /#/uD= E($state, "\$self cannot contain a fragment")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
184 }
185  
186 # determine canonical uri using rules from v3.2.0 §4.1.2.2.1, "Establishing the Base URI"
187 $self->_set_canonical_uri($state->{initial_schema_uri} =
188 587 ▶ Mojo::URL->new($schema->{'$self'}//())->to_abs($self->retrieval_uri//()));
Condition66%4/6
$$schema{"\$self"} // ()
l!l&&r!l&&!r
115760
$self->retrieval_uri // ()
l!l&&r!l&&!r
520670
MC/DC0%0/2
$$schema{"\$self"} // ()
$$schema{"\$self"} ()
MC/DC0%0/2
$self->retrieval_uri // ()
$self->retrieval_uri ()
Truth table66%2/3
A // B
A= $$schema{"\$self"}B= ()
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $self->retrieval_uriB= ()
ABresult
1X1
011
000
189  
190 # /jsonSchemaDialect: https://spec.openapis.org/oas/latest#specifying-schema-dialects
191 {
192 587 ▶ if (exists $schema->{jsonSchemaDialect}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$schema{"jsonSchemaDialect"}) 11 576 587
193 11 my $state = { %$state, keyword => 'jsonSchemaDialect' };
194 11 ▶ return $state
Branch: 1 branch
BranchTrueFalseTotal
unless assert_keyword_type($state, $schema, "string") and assert_uri_reference($state, $schema) 2 9 11
Condition100%3/3
assert_keyword_type($state, $schema, "string") and assert_uri_reference($state, $schema)
!ll&&!rl&&r
119
MC/DC100%2/2
assert_keyword_type($state, $schema, "string") and assert_uri_reference($state, $schema)
assert_keyword_type($state, $schema, "string") assert_uri_reference($state, $schema)
Truth table100%3/3
A and B
A= assert_keyword_type($state, $schema, "string")B= assert_uri_reference($state, $schema)
ABresult
0X0
100
111
195 if not assert_keyword_type($state, $schema, 'string')
196 or not assert_uri_reference($state, $schema);
197 }
198  
199 # v3.2.0 §4.24.7, "Specifying Schema Dialects": "If [jsonSchemaDialect] is not set, then the OAS
200 # dialect schema id MUST be used for these Schema Objects."
201 # v3.2.0 §4.1.2.2, "Relative References in API Description URIs": "Unless specified otherwise,
202 # all fields that are URIs MAY be relative references as defined by RFC3986 Section 4.2."
203 my $json_schema_dialect = exists $schema->{jsonSchemaDialect}
204 ? Mojo::URL->new($schema->{jsonSchemaDialect})->to_abs($self->canonical_uri)
205 585 ▶ : DEFAULT_DIALECT->{$self->oas_version};
Branch: 1 branch
BranchTrueFalseTotal
exists $$schema{'jsonSchemaDialect'} ? : 9 576 585
206  
207 # continue to support the old strict dialect and metaschema which didn't have "3.1" in the $id
208 585 ▶ if ($json_schema_dialect eq (STRICT_DIALECT->{3.1} =~ s{/3.1/}{/}r)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json_schema_dialect eq {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{"3.1"} =~ s[/3.1/][/]ru) 1 584 585
209 1 $json_schema_dialect =~ s{share/\K}{3.1/};
210 1 $schema->{jsonSchemaDialect} = $json_schema_dialect; # allow the 'const' check to pass
211 }
212 $self->_set_metaschema_uri($self->metaschema_uri =~ s{share/\K}{3.1/}r)
213 585 ▶ if $self->_has_metaschema_uri and $self->metaschema_uri eq (STRICT_METASCHEMA->{3.1} =~ s{/3.1/}{/}r);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_metaschema_uri and $self->metaschema_uri eq {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{"3.1"} =~ s[/3.1/][/]ru 1 584 585
Condition100%3/3
$self->_has_metaschema_uri and $self->metaschema_uri eq {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{"3.1"} =~ s[/3.1/][/]ru
!ll&&!rl&&r
571131
MC/DC100%2/2
$self->_has_metaschema_uri and $self->metaschema_uri eq {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{"3.1"} =~ s[/3.1/][/]ru
$self->_has_metaschema_uri $self->metaschema_uri eq {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{"3.1"} =~ s[/3.1/][/]ru
Truth table100%3/3
A and B
A= $self->_has_metaschema_uriB= $self->metaschema_uri eq {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{"3.1"} =~ s[/3.1/][/]ru
ABresult
0X0
100
111
214  
215 # we used to always preload these, so we need to do it as needed for users who are using them
216 load_cached_document($evaluator, STRICT_DIALECT->{$self->oas_version})
217 if $self->_has_metaschema_uri and $self->metaschema_uri eq (STRICT_METASCHEMA->{$self->oas_version}//'')
218 585 ▶ or $json_schema_dialect eq (STRICT_DIALECT->{$self->oas_version}//'');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_metaschema_uri and $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "") or $json_schema_dialect eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version} // "") 5 580 585
Condition80%8/10
$self->_has_metaschema_uri and $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "") or $json_schema_dialect eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version} // "")
l!l&&r!l&&!r
50580
$self->_has_metaschema_uri and $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "")
!ll&&!rl&&r
57195
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // ""
l!l
140
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version} // ""
l!l
55525
MC/DC66%2/3
$self->_has_metaschema_uri and $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "") or $json_schema_dialect eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version} // "")
$self->_has_metaschema_uri $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "") $json_schema_dialect eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version} // "")
MC/DC0%0/1
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // ""
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version}
MC/DC100%1/1
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version} // ""
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version}
Truth table60%3/5
A and B or C
A= $self->_has_metaschema_uriB= $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "")C= $json_schema_dialect eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version} // "")
ABCresult
11X1
0X11
1011
0X00
1000
Truth table50%1/2
A
A= {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version}
Aresult
11
00
Truth table100%2/2
A
A= {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-dialect.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-dialect.json"}->{$self->oas_version}
Aresult
11
00
219  
220 585 ▶ if ($json_schema_dialect eq DEFAULT_DIALECT->{'3.0'}
Branch: 1 branch
BranchTrueFalseTotal
if ($json_schema_dialect eq {3.0 => 'https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema', 3.1 => 'https://spec.openapis.org/oas/3.1/dialect/2024-11-10', 3.2 => 'https://spec.openapis.org/oas/3.2/dialect/2026-02-26'}->{'3.0'} or $json_schema_dialect eq {3.0 => 'https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema', 3.1 => 'https://spec.openapis.org/oas/3.1/dialect/2024-11-10', 3.2 => 'https://spec.openapis.org/oas/3.2/dialect/2026-02-26'}->{'3.0'} =~ s/\b\d{4}-\d{2}-\d{2}\b/latest/ar) { } 25 560 585
Condition66%2/3
$json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"} or $json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"} =~ s/\b\d{4}-\d{2}-\d{2}\b/latest/ar
l!l&&r!l&&!r
250560
MC/DC50%1/2
$json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"} or $json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"} =~ s/\b\d{4}-\d{2}-\d{2}\b/latest/ar
$json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"} $json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"} =~ s/\b\d{4}-\d{2}-\d{2}\b/latest/ar
Truth table66%2/3
A or B
A= $json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"}B= $json_schema_dialect eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18#/definitions/Schema","3.1" => "https://spec.openapis.org/oas/3.1/dialect/2024-11-10","3.2" => "https://spec.openapis.org/oas/3.2/dialect/2026-02-26"}->{"3.0"} =~ s/\b\d{4}-\d{2}-\d{2}\b/latest/ar
ABresult
1X1
011
000
221 or $json_schema_dialect eq (DEFAULT_DIALECT->{'3.0'} =~ s/\b\d{4}-\d{2}-\d{2}\b/latest/ar)) {
222 25 ▶ croak '3.0 dialect with a non-3.0 OAD is not currently supported' if $self->oas_version ne '3.0';
Branch: 1 branch
BranchTrueFalseTotal
if $self->oas_version ne "3.0" 0 25 25
223  
224 25 $evaluator->add_vocabulary('JSON::Schema::Modern::Vocabulary::OpenAPI_3_0');
225 $evaluator->_set_metaschema_vocabulary_classes($json_schema_dialect => [
226 25 $state->@{qw(specification_version vocabularies)} =
227 ('draft4', ['JSON::Schema::Modern::Vocabulary::OpenAPI_3_0'])
228 ]);
229 }
230 else {
231 # traverse an empty schema with this dialect uri to confirm it is valid, and add an entry in
232 # the evaluator's _metaschema_vocabulary_classes
233 560 my $check_metaschema_state = $evaluator->traverse({}, {
234 metaschema_uri => $json_schema_dialect,
235 initial_schema_uri => $self->canonical_uri->clone->fragment('/jsonSchemaDialect'),
236 traversed_keyword_path => '/jsonSchemaDialect',
237 });
238  
239 # we cannot continue if the metaschema is invalid
240 560 ▶ if ($check_metaschema_state->{errors}->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$$check_metaschema_state{"errors"}}) 2 558 560
241 2 push $state->{errors}->@*, $check_metaschema_state->{errors}->@*;
242 2 return $state;
243 }
244  
245 558 $state->@{qw(specification_version vocabularies)} = $check_metaschema_state->@{qw(specification_version vocabularies)};
246 }
247  
248 # subsequent '$schema' keywords can still override this
249 583 $state->{json_schema_dialect} = $json_schema_dialect;
250  
251 583 ▶ $self->_set_metaschema_uri(DEFAULT_METASCHEMA->{$self->oas_version})
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_metaschema_uri 569 14 583
252 if not $self->_has_metaschema_uri;
253  
254 load_cached_document($evaluator, STRICT_METASCHEMA->{$self->oas_version})
255 583 ▶ if $self->_has_metaschema_uri and $self->metaschema_uri eq (STRICT_METASCHEMA->{$self->oas_version}//'');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_metaschema_uri and $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "") 5 578 583
Condition80%4/5
$self->_has_metaschema_uri and $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "")
!ll&&!rl&&r
05785
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // ""
l!l
55825
MC/DC50%1/2
$self->_has_metaschema_uri and $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "")
$self->_has_metaschema_uri $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "")
MC/DC100%1/1
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // ""
{"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version}
Truth table66%2/3
A and B
A= $self->_has_metaschema_uriB= $self->metaschema_uri eq ({"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version} // "")
ABresult
0X0
100
111
Truth table100%2/2
A
A= {"3.1" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.1/strict-schema.json","3.2" => "https://raw.githubusercontent.com/karenetheridge/OpenAPI-Modern/master/share/3.2/strict-schema.json"}->{$self->oas_version}
Aresult
11
00
256 }
257  
258 $state->{identifiers}{$state->{initial_schema_uri}} = {
259 path => '',
260 canonical_uri => $state->{initial_schema_uri},
261 specification_version => $state->{specification_version},
262 vocabularies => $state->{vocabularies}, # reference, not copy
263 583 };
264  
265 583 my $metaschema_doc;
266  
267 # evaluate the document against its metaschema to find any errors, to identify all schema
268 # resources within to add to the global resource index, and to extract all operationIds
269 583 my (@json_schema_paths, @operation_paths, %bad_path_item_refs, @server_paths, @security_requirements, %tag_operation_paths, @bad_3_0_paths, @references, @encodings);
270 my $result = $evaluator->evaluate(
271 $schema, $self->metaschema_uri,
272 {
273 collect_annotations => 0,
274 validate_formats => 1,
275 callbacks => {
276 # we avoid producing errors here so we don't create extra errors for "not all additional
277 # properties are valid" etc
278 1009 ▶ '$dynamicRef' => sub ($, $schema, $state) {
Subroutine __ANON__: called CC=2 SCAR=7.2
279 # Note that if we are using the default metaschema
280 # https://spec.openapis.org/oas/<version>/schema/<date>, we will only find the root of each
281 # schema, not all subschemas. We will traverse each of these schemas later using
282 # jsonSchemaDialect to find all subschemas and their $ids.
283 1009 ▶ push @json_schema_paths, $state->{data_path} if $schema->{'$dynamicRef'} eq '#meta';
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"\$dynamicRef"} eq "#meta" 1009 0 1009
284 1009 return 1;
285 },
286 17090 ▶ '$ref' => sub ($data, $schema, $state) {
Subroutine __ANON__: called CC=41 SCAR=37.2
287 17090 my $entity;
288  
289 17090 ▶ if ($self->oas_version eq '3.0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->oas_version eq '3.0') { } 186 16904 17090
290 # strip '#/definitions/'; convert CamelCase to kebab-case
291 186 ▶ if ($entity = lc join('-', split /(?=[A-Z])/, substr($schema->{'$ref'}, 14))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entity = lc join("-", split(/(?=[A-Z])/u, substr($$schema{"\$ref"}, 14), 0))) 186 0 186
292 186 ▶ if ($entity eq 'schema') {
Branch: 1 branch
BranchTrueFalseTotal
if ($entity eq "schema") 41 145 186
293 push @bad_3_0_paths, [ items => $state->{data_path} ]
294 41 ▶ if ($data->{type}//'') eq 'array' and not exists $data->{items};
Branch: 1 branch
BranchTrueFalseTotal
if ($$data{"type"} // "") eq "array" and not exists $$data{"items"} 2 39 41
Condition100%5/5
($$data{"type"} // "") eq "array" and not exists $$data{"items"}
!ll&&!rl&&r
3812
$$data{"type"} // ""
l!l
2120
MC/DC100%2/2
($$data{"type"} // "") eq "array" and not exists $$data{"items"}
$$data{"type"} not exists $$data{"items"}
Truth table100%3/3
A and not(B)
A= $$data{"type"}B= not exists $$data{"items"}
ABresult
0X0
100
111
295  
296 push @bad_3_0_paths, [ minimum => $state->{data_path} ]
297 41 ▶ if exists $data->{exclusiveMinimum} and not exists $data->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$data{"exclusiveMinimum"} and not exists $$data{"minimum"} 2 39 41
Condition100%3/3
exists $$data{"exclusiveMinimum"} and not exists $$data{"minimum"}
!ll&&!rl&&r
3812
MC/DC100%2/2
exists $$data{"exclusiveMinimum"} and not exists $$data{"minimum"}
exists $$data{"exclusiveMinimum"} not exists $$data{"minimum"}
Truth table100%3/3
A and not(B)
A= exists $$data{"exclusiveMinimum"}B= not exists $$data{"minimum"}
ABresult
0X0
100
111
298  
299 push @bad_3_0_paths, [ maximum => $state->{data_path} ]
300 41 ▶ if exists $data->{exclusiveMaximum} and not exists $data->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$data{"exclusiveMaximum"} and not exists $$data{"maximum"} 2 39 41
Condition100%3/3
exists $$data{"exclusiveMaximum"} and not exists $$data{"maximum"}
!ll&&!rl&&r
3812
MC/DC100%2/2
exists $$data{"exclusiveMaximum"} and not exists $$data{"maximum"}
exists $$data{"exclusiveMaximum"} not exists $$data{"maximum"}
Truth table100%3/3
A and not(B)
A= exists $$data{"exclusiveMaximum"}B= not exists $$data{"maximum"}
ABresult
0X0
100
111
301 }
302  
303 186 ▶ push @encodings, $state->{data_path} if $entity eq 'encoding';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "encoding" 0 186 186
304  
305 # "$ref" in path-item is not represented in the schema by a Reference object
306 push @references, [ '$ref', $state->{data_path}, Mojo::URL->new($data->{'$ref'})->to_abs($self->canonical_uri), 'path-item' ]
307 186 ▶ if $entity eq 'path-item' and exists $data->{'$ref'};
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "path-item" and exists $$data{"\$ref"} 3 183 186
Condition100%3/3
$entity eq "path-item" and exists $$data{"\$ref"}
!ll&&!rl&&r
17943
MC/DC100%2/2
$entity eq "path-item" and exists $$data{"\$ref"}
$entity eq "path-item" exists $$data{"\$ref"}
Truth table100%3/3
A and B
A= $entity eq "path-item"B= exists $$data{"\$ref"}
ABresult
0X0
100
111
308  
309 186 ▶ if ($entity eq 'reference') {
Branch: 1 branch
BranchTrueFalseTotal
if ($entity eq "reference") 22 164 186
310 22 ▶ $metaschema_doc //= $evaluator->_get_resource($self->metaschema_uri)->{document};
Condition66%2/3
$metaschema_doc //= $evaluator->_get_resource($self->metaschema_uri)->{"document"}
l!l&&r!l&&!r
1750
MC/DC0%0/2
$metaschema_doc //= $evaluator->_get_resource($self->metaschema_uri)->{"document"}
$metaschema_doc $evaluator->_get_resource($self->metaschema_uri)->{"document"}
Truth table66%2/3
A //= B
A= $metaschema_docB= $evaluator->_get_resource($self->metaschema_uri)->{"document"}
ABresult
1X1
011
000
311  
312 # in the 3.0 metaschema, entities are identified via:
313 # "oneOf": [ { "$ref": "#/definitions/Foo" }, { "$ref": "#/definitions/Reference" } ]
314 22 ▶ my $schema_path = ($state->{initial_schema_uri}->fragment//'').$state->{keyword_path};
Condition50%1/2
$$state{"initial_schema_uri"}->fragment // ""
l!l
220
MC/DC0%0/1
$$state{"initial_schema_uri"}->fragment // ""
$$state{"initial_schema_uri"}->fragment
Truth table50%1/2
A
A= $$state{"initial_schema_uri"}->fragment
Aresult
11
00
315 22 ▶ if ($schema_path =~ s{/oneOf/\K([01])\z}{$1 ^ 1}e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_path =~ s[/oneOf/\K([01])\z][$1 ^ 1;]eu) 22 0 22
316 22 $entity = lc join('-', split /(?=[A-Z])/, substr($metaschema_doc->get($schema_path)->{'$ref'}, 14));
317 22 ▶ $entity .= 's' if $entity eq 'callback';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "callback" 1 21 22
318 22 push @references, [ '$ref', $state->{data_path}, Mojo::URL->new($data->{'$ref'})->to_abs($self->canonical_uri), $self->__entity_type->($entity) ];
319 }
320 }
321  
322 186 ▶ $entity .= 's' if $entity eq 'callback';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "callback" 1 185 186
323 186 ▶ undef $entity if not grep $entity eq $_, __entities;
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($entity eq $_), __entities()) 89 97 186
324  
325 # no need to push to @json_schema_paths, as all schema entities are already found
326 # via $refs above, and there are no embedded identifiers to be identified
327 }
328 }
329 else {
330 # path-item is the only entity (that is, an object that can be $ref'd in an OpenAPI
331 # document) that is defined in the schema without an -or-reference
332 ($entity) = (($schema->{'$ref'} =~ m{#/\$defs/([^/]+?)(?:-or-reference)\z}),
333 16904 ($schema->{'$ref'} =~ m{#/\$defs/(path-item|encoding)\z}));
334  
335 16904 ▶ push @encodings, $state->{data_path} if ($entity//'') eq 'encoding';
Branch: 1 branch
BranchTrueFalseTotal
if ($entity // "") eq "encoding" 238 16666 16904
Condition100%2/2
$entity // ""
l!l
296613938
MC/DC100%1/1
$entity // ""
$entity
Truth table100%2/2
A
A= $entity
Aresult
11
00
336  
337 push @references, [ '$ref', $state->{data_path}, Mojo::URL->new($data->{'$ref'})->to_abs($self->canonical_uri), 'path-item' ]
338 16904 ▶ if ($entity//'') eq 'path-item' and exists $data->{'$ref'};
Branch: 1 branch
BranchTrueFalseTotal
if ($entity // "") eq "path-item" and exists $$data{"\$ref"} 35 16869 16904
Condition100%5/5
($entity // "") eq "path-item" and exists $$data{"\$ref"}
!ll&&!rl&&r
1620866135
$entity // ""
l!l
296613938
MC/DC100%2/2
($entity // "") eq "path-item" and exists $$data{"\$ref"}
$entity exists $$data{"\$ref"}
Truth table100%3/3
A and B
A= $entityB= exists $$data{"\$ref"}
ABresult
0X0
100
111
339  
340 16904 ▶ if ($schema->{'$ref'} eq '#/$defs/reference') {
Branch: 1 branch
BranchTrueFalseTotal
if ($$schema{"\$ref"} eq "#/\$defs/reference") 178 16726 16904
341 178 my ($e) = ($state->{initial_schema_uri}->fragment =~ m{/\$defs/([^/]+?)(?:-or-reference)\z});
342 178 push @references, [ '$ref', $state->{data_path}, Mojo::URL->new($data->{'$ref'})->to_abs($self->canonical_uri), $e ];
343 }
344 }
345  
346 # not $reffable at runtime, so no need to track these
347 17090 ▶ undef $entity if ($entity//'') eq 'encoding';
Branch: 1 branch
BranchTrueFalseTotal
if ($entity // "") eq "encoding" 238 16852 17090
Condition100%2/2
$entity // ""
l!l
306314027
MC/DC100%1/1
$entity // ""
$entity
Truth table100%2/2
A
A= $entity
Aresult
11
00
348  
349 17090 ▶ $self->_add_entity_location($state->{data_path}, $entity) if $entity;
Branch: 1 branch
BranchTrueFalseTotal
if $entity 2825 14265 17090
350  
351 17090 ▶ if ($schema->{'$ref'} eq '#/$defs/operation' or $schema->{'$ref'} eq '#/definitions/Operation') {
Branch: 1 branch
BranchTrueFalseTotal
if ($$schema{"\$ref"} eq "#/\$defs/operation" or $$schema{"\$ref"} eq "#/definitions/Operation") 669 16421 17090
Condition100%3/3
$$schema{"\$ref"} eq "#/\$defs/operation" or $$schema{"\$ref"} eq "#/definitions/Operation"
l!l&&r!l&&!r
665416421
MC/DC100%2/2
$$schema{"\$ref"} eq "#/\$defs/operation" or $$schema{"\$ref"} eq "#/definitions/Operation"
$$schema{"\$ref"} eq "#/\$defs/operation" $$schema{"\$ref"} eq "#/definitions/Operation"
Truth table100%3/3
A or B
A= $$schema{"\$ref"} eq "#/\$defs/operation"B= $$schema{"\$ref"} eq "#/definitions/Operation"
ABresult
1X1
011
000
352 push @operation_paths, [ $data->{operationId} => $state->{data_path} ]
353 669 ▶ if defined $data->{operationId};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$data{"operationId"} 107 562 669
354  
355 18 ▶ { use autovivification 'store';
Subroutine BEGIN: called CC=1 SCAR=0.0
356 push $tag_operation_paths{$_}->@*, $state->{data_path}
357 669 ▶ foreach ($data->{tags}//[])->@*;
Condition100%2/2
$$data{"tags"} // []
l!l
3666
MC/DC100%1/1
$$data{"tags"} // []
$$data{"tags"}
Truth table100%2/2
A
A= $$data{"tags"}
Aresult
11
00
358 }
359 }
360  
361 # path-items are weird and allow mixing of fields adjacent to a $ref, which is burdensome
362 # to properly support (see https://github.com/OAI/OpenAPI-Specification/issues/3734)
363 17090 ▶ if ($entity and $entity eq 'path-item' and exists $data->{'$ref'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entity and $entity eq "path-item" and exists $$data{"\$ref"}) 38 17052 17090
Condition100%6/6
$entity and $entity eq "path-item" and exists $$data{"\$ref"}
!ll&&!rl&&r
1638766538
$entity and $entity eq "path-item"
!ll&&!rl&&r
142652122703
MC/DC100%3/3
$entity and $entity eq "path-item" and exists $$data{"\$ref"}
$entity $entity eq "path-item" exists $$data{"\$ref"}
Truth table100%4/4
A and B and C
A= $entityB= $entity eq "path-item"C= exists $$data{"\$ref"}
ABCresult
0XX0
10X0
1100
1111
364 38 my %path_item = $data->%*;
365 38 delete @path_item{qw(summary description $ref)};
366 38 ▶ $bad_path_item_refs{$state->{data_path}} = join(', ', sort keys %path_item) if keys %path_item;
Branch: 1 branch
BranchTrueFalseTotal
if keys %path_item 4 34 38
367 }
368  
369 17090 ▶ push @server_paths, $state->{data_path} if $schema->{'$ref'} eq '#/$defs/server';
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"\$ref"} eq "#/\$defs/server" 96 16994 17090
370  
371 push @security_requirements, [ $state->{data_path}, $data ]
372 17090 ▶ if $schema->{'$ref'} eq '#/$defs/security-requirement';
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"\$ref"} eq "#/\$defs/security-requirement" 7 17083 17090
373  
374 17090 return 1;
375 },
376 },
377 },
378 583 );
379  
380 583 ▶ if (not $result->valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result->valid) 13 570 583
381 13 foreach my $e ($result->errors) {
382 58 ▶ if (($e->keyword//'') eq 'not'
Branch: 1 branch
BranchTrueFalseTotal
if (($e->keyword // "") eq "not" and $e->absolute_keyword_location->fragment eq "/\$defs/parameters/not" and $e->absolute_keyword_location->clone->fragment(undef) eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18","3.1" => "https://spec.openapis.org/oas/3.1/schema/2026-11-05","3.2" => "https://spec.openapis.org/oas/3.2/schema/2026-11-12"}->{$self->oas_version}) 1 57 58
Condition62%5/8
($e->keyword // "") eq "not" and $e->absolute_keyword_location->fragment eq "/\$defs/parameters/not" and $e->absolute_keyword_location->clone->fragment(undef) eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18","3.1" => "https://spec.openapis.org/oas/3.1/schema/2026-11-05","3.2" => "https://spec.openapis.org/oas/3.2/schema/2026-11-12"}->{$self->oas_version}
!ll&&!rl&&r
5701
($e->keyword // "") eq "not" and $e->absolute_keyword_location->fragment eq "/\$defs/parameters/not"
!ll&&!rl&&r
5701
$e->keyword // ""
l!l
580
MC/DC0%0/3
($e->keyword // "") eq "not" and $e->absolute_keyword_location->fragment eq "/\$defs/parameters/not" and $e->absolute_keyword_location->clone->fragment(undef) eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18","3.1" => "https://spec.openapis.org/oas/3.1/schema/2026-11-05","3.2" => "https://spec.openapis.org/oas/3.2/schema/2026-11-12"}->{$self->oas_version}
$e->keyword $e->absolute_keyword_location->fragment eq "/\$defs/parameters/not" $e->absolute_keyword_location->clone->fragment(undef) eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18","3.1" => "https://spec.openapis.org/oas/3.1/schema/2026-11-05","3.2" => "https://spec.openapis.org/oas/3.2/schema/2026-11-12"}->{$self->oas_version}
Truth table25%1/4
A and B and C
A= $e->keywordB= $e->absolute_keyword_location->fragment eq "/\$defs/parameters/not"C= $e->absolute_keyword_location->clone->fragment(undef) eq {"3.0" => "https://spec.openapis.org/oas/3.0/schema/2024-10-18","3.1" => "https://spec.openapis.org/oas/3.1/schema/2026-11-05","3.2" => "https://spec.openapis.org/oas/3.2/schema/2026-11-12"}->{$self->oas_version}
ABCresult
0XX0
10X0
1100
1111
383 and $e->absolute_keyword_location->fragment eq '/$defs/parameters/not'
384 and $e->absolute_keyword_location->clone->fragment(undef) eq DEFAULT_METASCHEMA->{$self->oas_version}
385 ) {
386 1 push $state->{errors}->@*, $e->clone(
387 keyword_location => '',
388 absolute_keyword_location => undef,
389 error => 'cannot use query and querystring together',
390 );
391 }
392  
393 58 push $state->{errors}->@*, $e;
394 }
395  
396 13 return $state;
397 }
398  
399 570 ▶ $self->_set_defaults($result->defaults) if $result->defaults;
Branch: 1 branch
BranchTrueFalseTotal
if $result->defaults 21 549 570
400  
401 570 foreach my $pair (@operation_paths) {
402 107 my ($operation_id, $path) = @$pair;
403 107 ▶ if (my $existing = $self->operationId_path($operation_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $existing = $self->operationId_path($operation_id)) { } 6 101 107
404 6 ()= E({ %$state, keyword_path => $path .'/operationId' },
405 'duplicate of operationId at %s', $existing);
406 }
407 else {
408 101 $self->_add_operationId($operation_id => $path);
409 }
410 }
411  
412 ()= E({ %$state, keyword_path => $_->[1] },
413 $_->[0] eq 'items' ? '"items" must be present if type is "array"'
414 : $_->[0] eq 'minimum' ? '"minimum" must be present when "exclusiveMinimum" is used'
415 : $_->[0] eq 'maximum' ? '"maximum" must be present when "exclusiveMaximum" is used'
416 : die
417 570 ▶ ) foreach @bad_3_0_paths;
Branch: 3 branches
BranchTrueFalseTotal
$our $_[0] eq 'items' ? : 2 4 6
$our $_[0] eq 'minimum' ? : 2 2 4
$our $_[0] eq 'maximum' ? : 2 0 2
418  
419 # v3.2.0 §4.8.1, "Patterned Fields": "When matching URLs, concrete (non-templated) paths would be
420 # matched before their templated counterparts."
421  
422 # caution, Schwartzian transform ahead!
423 $self->_set_path_templates(my $sorted_paths = [
424 map $_->[0], # remove transformed entries
425 318 ▶ sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] } # sort by the transformed entries
Condition80%4/5
$our $a[1] cmp $our $b[1] || $our $a[0] cmp $our $b[0]
l!l&&r!l&&!r
31440
$$schema{"paths"} // {}
l!l
52842
MC/DC0%0/2
$our $a[1] cmp $our $b[1] || $our $a[0] cmp $our $b[0]
$our $a[1] cmp $our $b[1] $our $a[0] cmp $our $b[0]
MC/DC100%1/1
$$schema{"paths"} // {}
$$schema{"paths"}
Truth table66%2/3
A || B
A= $our $a[1] cmp $our $b[1]B= $our $a[0] cmp $our $b[0]
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$schema{"paths"}
Aresult
11
00
426 map [ $_, s/\{[^{}]+\}/\x{10FFFF}/rg ], # transform template names into the highest Unicode char
427 grep !/^x-/, # remove extension keywords
428 570 keys(($schema->{paths}//{})->%*) # all entries in /paths/*
429 ]);
430  
431 570 my %seen_path;
432 570 foreach my $path (@$sorted_paths) {
433 # see ABNF at v3.2.0 §4.8.2
434 637 ▶ die "invalid path: $path" if substr($path, 0, 1) ne '/'; # schema validation catches this
Branch: 1 branch
BranchTrueFalseTotal
if substr($path, 0, 1) ne "/" 0 637 637
435 637 ▶ ()= E({ %$state, keyword_path => jsonp('/paths', $path) }, 'invalid path template "%s"', $path)
Branch: 1 branch
BranchTrueFalseTotal
if grep((!/^(?:\{[^{}]+\}|%[[:xdigit:]]{2}|[:\@!\$&'()*+,;=[:alnum:]._~-]+)+\z/a), split(m[/]u, substr($path, 1), 0)) 4 633 637
436 if grep !/^(?:\{[^{}]+\}|%[[:xdigit:]]{2}|[:@!\$&'()*+,;=[:alnum:]._~-]+)+\z/a,
437 split('/', substr($path, 1)); # split by segment, omitting leading /
438  
439 637 my %seen_names;
440 637 foreach my $name ($path =~ /\{([^{}]+)\}/g) {
441 # v3.2.0 §4.8.1, "Patterned Fields": "Templated paths with the same hierarchy but different
442 # templated names MUST NOT exist as they are identical."
443 187 ▶ if (++$seen_names{$name} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$seen_names{$name} == 2) 2 185 187
444 2 ()= E({ %$state, keyword_path => jsonp('/paths', $path) },
445 'duplicate path template variable "%s"', $name);
446 }
447 }
448  
449 637 my $normalized = $path =~ s/\{[^{}]+\}/\x00/gr;
450 637 ▶ if (my $first_path = $seen_path{$normalized}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $first_path = $seen_path{$normalized}) 3 634 637
451 3 ()= E({ %$state, keyword_path => jsonp('/paths', $path) },
452 'duplicate of templated path "%s"', $first_path);
453 3 next;
454 }
455 634 $seen_path{$normalized} = $path;
456 }
457  
458 570 foreach my $path_item (sort keys %bad_path_item_refs) {
459 ()= E({ %$state, keyword_path => $path_item },
460 4 'invalid keywords used adjacent to $ref in a path-item: %s', $bad_path_item_refs{$path_item});
461 }
462  
463 570 my (%seen_url, %seen_name); # indexed by servers object
464 570 foreach my $server_location (@server_paths) {
465 96 my $server = $self->get($server_location);
466  
467 # see ABNF at v3.2.0 §4.6
468 ()= E({ %$state, keyword_path => $server_location.'/url' },
469 'invalid server url "%s"', $server->{url}), next
470 96 ▶ if $server->{url} !~ /^(?:\{[^{}]+\}|%[[:xdigit:]]{2}|[\x21\x24\x26-\x3B\x3D\x40-\x5B\x5D\x5F\x61-\x7A\x7E\xA0-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}\x{E000}-\x{F8FF}\x{F0000}-\x{FFFFD}\x{100000}-\x{10FFFD}])+\z/a;
Branch: 1 branch
BranchTrueFalseTotal
unless $$server{"url"} =~ /^(?:\{[^{}]+\}|%[[:xdigit:]]{2}|[\x21\x24\x26-\x3B\x3D\x40-\x5B\x5D\x5F\x61-\x7A\x7E\xA0-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}\x{E000}-\x{F8FF}\x{F0000}-\x{FFFFD}\x{100000}-\x{10FFFD}])+\z/a 12 84 96
471  
472 84 my $normalized = $server->{url} =~ s/\{[^{}]+\}/\x00/gr;
473 84 my @url_variables = $server->{url} =~ /\{([^{}]+)\}/g;
474  
475 84 my $servers_location = $server_location =~ s{/[0-9]+\z}{}r;
476  
477 # FIXME: this is not a spec requirement, so change this to a linting item
478 84 ▶ if (my $first_url = ($seen_url{$servers_location}//{})->{$normalized}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $first_url = ($seen_url{$servers_location} // {})->{$normalized}) 6 78 84
Condition100%2/2
$seen_url{$servers_location} // {}
l!l
5529
MC/DC100%1/1
$seen_url{$servers_location} // {}
$seen_url{$servers_location}
Truth table100%2/2
A
A= $seen_url{$servers_location}
Aresult
11
00
479 6 ()= E({ %$state, keyword_path => $server_location.'/url' },
480 'duplicate of templated server url "%s"', $first_url);
481 }
482 18 ▶ { use autovivification 'store'; $seen_url{$servers_location}->{$normalized} = $server->{url}; }
Subroutine BEGIN: called CC=1 SCAR=0.0
483  
484 84 ▶ if (defined $server->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$server{"name"}) 6 78 84
485 ()= E({ %$state, keyword_path => $server_location.'/url' }, 'server name "%s" is not unique', $server->{name})
486 6 ▶ if ($seen_name{$servers_location}//{})->{$server->{name}};
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_name{$servers_location} // {})->{$$server{"name"}} 3 3 6
Condition100%2/2
$seen_name{$servers_location} // {}
l!l
33
MC/DC100%1/1
$seen_name{$servers_location} // {}
$seen_name{$servers_location}
Truth table100%2/2
A
A= $seen_name{$servers_location}
Aresult
11
00
487 18 ▶ use autovivification 'store';
Subroutine BEGIN: called CC=1 SCAR=0.0
488 6 $seen_name{$servers_location}->{$server->{name}}++
489 }
490  
491 84 my $variables_obj = $server->{variables};
492 84 ▶ if (not $variables_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($variables_obj) 44 40 84
493 # missing 'variables': needs variables/$varname/default
494 44 ▶ ()= E({ %$state, keyword_path => $server_location },
Branch: 1 branch
BranchTrueFalseTotal
if @url_variables 3 41 44
495 '"variables" property is required for templated server urls') if @url_variables;
496 44 next;
497 }
498  
499 40 my %seen_names;
500 40 foreach my $name (@url_variables) {
501 ()= E({ %$state, keyword_path => $server_location },
502 'duplicate server template variable "%s"', $name)
503 56 ▶ if ++$seen_names{$name} == 2;
Branch: 1 branch
BranchTrueFalseTotal
if ++$seen_names{$name} == 2 3 53 56
504  
505 ()= E({ %$state, keyword_path => $server_location.'/variables' },
506 'missing "variables" definition for server template variable "%s"', $name)
507 56 ▶ if $seen_names{$name} == 1 and not exists $variables_obj->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $seen_names{$name} == 1 and not exists $$variables_obj{$name} 3 53 56
Condition100%3/3
$seen_names{$name} == 1 and not exists $$variables_obj{$name}
!ll&&!rl&&r
3503
MC/DC100%2/2
$seen_names{$name} == 1 and not exists $$variables_obj{$name}
$seen_names{$name} == 1 not exists $$variables_obj{$name}
Truth table100%3/3
A and not(B)
A= $seen_names{$name} == 1B= not exists $$variables_obj{$name}
ABresult
0X0
100
111
508 }
509  
510 40 foreach my $varname (keys $variables_obj->%*) {
511 ()= E({ %$state, keyword_path => jsonp($server_location, 'variables', $varname, 'default') },
512 'server default is not a member of enum')
513 if exists $variables_obj->{$varname}{enum}
514 56 ▶ and not grep $variables_obj->{$varname}{default} eq $_, $variables_obj->{$varname}{enum}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$variables_obj{$varname}{"enum"} and not grep(($$variables_obj{$varname}{"default"} eq $_), @{$$variables_obj{$varname}{"enum"}}) 6 50 56
Condition100%3/3
exists $$variables_obj{$varname}{"enum"} and not grep(($$variables_obj{$varname}{"default"} eq $_), @{$$variables_obj{$varname}{"enum"}})
!ll&&!rl&&r
38126
MC/DC100%2/2
exists $$variables_obj{$varname}{"enum"} and not grep(($$variables_obj{$varname}{"default"} eq $_), @{$$variables_obj{$varname}{"enum"}})
exists $$variables_obj{$varname}{"enum"} not grep(($$variables_obj{$varname}{"default"} eq $_), @{$$variables_obj{$varname}{"enum"}})
Truth table100%3/3
A and not(B)
A= exists $$variables_obj{$varname}{"enum"}B= not grep(($$variables_obj{$varname}{"default"} eq $_), @{$$variables_obj{$varname}{"enum"}})
ABresult
0X0
100
111
515 }
516 }
517  
518 # name -> index; for duplicates, will contain the first index where the tag can be found
519 570 ▶ my %tag_to_index = reverse indexed map $_->{name}, ($schema->{tags}//[])->@*;
Condition100%2/2
$$schema{"tags"} // []
l!l
2568
MC/DC100%1/1
$$schema{"tags"} // []
$$schema{"tags"}
Truth table100%2/2
A
A= $$schema{"tags"}
Aresult
11
00
520  
521 570 ▶ foreach my $tag_idx (0 .. ($schema->{tags}//[])->$#*) {
Condition100%2/2
$$schema{"tags"} // []
l!l
2568
MC/DC100%1/1
$$schema{"tags"} // []
$$schema{"tags"}
Truth table100%2/2
A
A= $$schema{"tags"}
Aresult
11
00
522 12 my $tag = $schema->{tags}[$tag_idx];
523 ()= E({ %$state, keyword_path => '/tags/'.$tag_idx.'/name' },
524 'duplicate of tag at /tags/%d: "%s"', $tag_to_index{$tag->{name}}, $tag->{name})
525 12 ▶ if $tag_to_index{$tag->{name}} != $tag_idx;
Branch: 1 branch
BranchTrueFalseTotal
if $tag_to_index{$$tag{"name"}} != $tag_idx 3 9 12
526  
527 ()= E({ %$state, keyword_path => '/tags/'.$tag_idx.'/parent' },
528 'parent of tag "%s" does not exist: "%s"', $tag->{name}, $tag->{parent})
529 12 ▶ if exists $tag->{parent} and not exists $tag_to_index{$tag->{parent}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$tag{"parent"} and not exists $tag_to_index{$$tag{"parent"}} 1 11 12
Condition100%3/3
exists $$tag{"parent"} and not exists $tag_to_index{$$tag{"parent"}}
!ll&&!rl&&r
471
MC/DC100%2/2
exists $$tag{"parent"} and not exists $tag_to_index{$$tag{"parent"}}
exists $$tag{"parent"} not exists $tag_to_index{$$tag{"parent"}}
Truth table100%3/3
A and not(B)
A= exists $$tag{"parent"}B= not exists $tag_to_index{$$tag{"parent"}}
ABresult
0X0
100
111
530  
531 12 my @seen;
532 12 ▶ while (defined $tag->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$tag{"parent"}) 12 8 20
533 12 push @seen, $tag->{name};
534 12 ▶ last if not defined $tag_to_index{$tag->{parent}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag_to_index{$$tag{"parent"}} 1 11 12
535 11 $tag = $schema->{tags}[$tag_to_index{$tag->{parent}}];
536  
537 ()= E({ %$state, keyword_path => '/tags/'.$tag_idx.'/parent' },
538 'circular reference between tags: '.join(' -> ', map '"'.$_.'"', @seen, $tag->{name})),
539 last
540 11 ▶ if grep $_ eq $tag->{name}, @seen;
Branch: 1 branch
BranchTrueFalseTotal
if grep(($_ eq $$tag{"name"}), @seen) 3 8 11
541 }
542 }
543  
544 570 foreach my $sec_req_entry (@security_requirements) {
545 # name must be under components, or a URI. if uri, add to the list of references to check.
546 7 my ($location, $security_requirement) = $sec_req_entry->@*;
547  
548 7 foreach my $name (keys $security_requirement->%*) {
549 6 ▶ if (not exists((($schema->{components}//{})->{securitySchemes}//{})->{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists((($$schema{"components"} // {})->{"securitySchemes"} // {})->{$name})) 4 2 6
Condition100%4/4
($$schema{"components"} // {})->{"securitySchemes"} // {}
l!l
42
$$schema{"components"} // {}
l!l
42
MC/DC100%1/1
($$schema{"components"} // {})->{"securitySchemes"} // {}
$$schema{"components"}
Truth table100%2/2
A
A= $$schema{"components"}
Aresult
11
00
550 4 ▶ if ($name =~ m/^[a-zA-Z0-9._-]+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^[a-zA-Z0-9._-]+\z/u) { } 1 3 4
551 1 ()= E({ %$state, keyword_path => jsonp($location, $name) },
552 'security scheme "%s" does not exist at "/components/securitySchemes"', $name);
553 }
554 else {
555 3 push @references, [ undef, jsonp($location, $name), Mojo::URL->new($name)->to_abs($self->canonical_uri), 'security-scheme' ];
556 }
557 }
558 }
559 }
560  
561 570 my %encoding_contentType_index;
562 570 foreach my $encoding_location (@encodings) {
563 238 my $encoding_obj = $self->get($encoding_location);
564 238 ▶ next if not exists $encoding_obj->{contentType};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$encoding_obj{"contentType"} 117 121 238
565 121 ▶ next if exists $encoding_contentType_index{$encoding_obj->{contentType}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $encoding_contentType_index{$$encoding_obj{"contentType"}} 46 75 121
566  
567 # v3.2.1 §4.15.1.1: "The contentType field is defined by the following ABNF syntax:"
568 # encoding-content-type = media-range *( "," OWS media-range )
569 75 my $re = OpenAPI::Modern::Utilities::MEDIA_RANGE_RE;
570 75 my $ct = $encoding_obj->{contentType};
571  
572 75 $ct =~ m/^($re)/gc;
573 75 my @content_types = $1;
574 75 ▶ if (@content_types) {
Branch: 1 branch
BranchTrueFalseTotal
if (@content_types) 75 0 75
575 75 ▶ while ($ct =~ m/\G,[\x09\x20]*($re)/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ct =~ /\G,[\x09\x20]*($re)/cgu) 15 75 90
576 15 push @content_types, $1;
577 }
578 }
579  
580 75 ▶ if (pos($ct) != length($ct)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $ct != length $ct) { } 5 70 75
581 5 ()= E({ %$state, keyword_path => $encoding_location, keyword => 'contentType' },
582 '"%s" is not a valid media-range', substr($ct, pos($ct)) =~ s/^,[\x09\x20]*//r);
583 }
584 else {
585 70 $encoding_contentType_index{$encoding_obj->{contentType}} = \@content_types;
586 }
587 }
588  
589 570 ▶ return $state if $state->{errors}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if @{$$state{"errors"}} 8 562 570
590  
591 562 $self->{_tags} = (HashRef[json_pointer_type])->({ map +($_ => '/tags/'.$tag_to_index{$_}), keys %tag_to_index });
592 562 $self->{_operation_tags} = (HashRef[ArrayRef[json_pointer_type]])->(\%tag_operation_paths);
593 562 $self->{_encoding_contentTypes} = \%encoding_contentType_index;
594  
595 # disregard paths that are not the root of each embedded subschema.
596 # Because the callbacks are executed after the keyword has (recursively) finished evaluating,
597 # for each nested schema group. the schema paths appear longest first, with the parent schema
598 # appearing last. Therefore we can whittle down to the parent schema for each group by iterating
599 # through the full list in reverse, and checking if it is a child of the last path we chose to save.
600 # When the default metaschema is being used, there is no pruning to be done, as only the root of
601 # each embedded schema will be found via callbacks.
602 562 my @real_json_schema_paths;
603 562 ▶ for (my $idx = $#json_schema_paths; $idx >= 0; --$idx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= 0) 1005 562 1567
604 1005 ▶ next if $idx != $#json_schema_paths
Branch: 1 branch
BranchTrueFalseTotal
if $idx != $#json_schema_paths and substr($json_schema_paths[$idx], 0, length($real_json_schema_paths[-1]) + 1) eq $real_json_schema_paths[-1] . '/' 0 1005 1005
Condition66%2/3
$idx != $#json_schema_paths and substr($json_schema_paths[$idx], 0, length($real_json_schema_paths[-1]) + 1) eq $real_json_schema_paths[-1] . '/'
!ll&&!rl&&r
3506550
MC/DC0%0/2
$idx != $#json_schema_paths and substr($json_schema_paths[$idx], 0, length($real_json_schema_paths[-1]) + 1) eq $real_json_schema_paths[-1] . '/'
$idx != $#json_schema_paths substr($json_schema_paths[$idx], 0, length($real_json_schema_paths[-1]) + 1) eq $real_json_schema_paths[-1] . '/'
Truth table66%2/3
A and B
A= $idx != $#json_schema_pathsB= substr($json_schema_paths[$idx], 0, length($real_json_schema_paths[-1]) + 1) eq $real_json_schema_paths[-1] . '/'
ABresult
0X0
100
111
605 and substr($json_schema_paths[$idx], 0, length($real_json_schema_paths[-1])+1)
606 eq $real_json_schema_paths[-1].'/';
607  
608 1005 push @real_json_schema_paths, $json_schema_paths[$idx];
609 }
610  
611 562 ▶ push $state->{references}->@*, @references if $state->{references};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"references"} 562 0 562
612  
613 562 $self->_traverse_schema({ %$state, keyword_path => $_ }) foreach reverse @real_json_schema_paths;
614 562 ▶ return $state if $state->{errors}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if @{$$state{"errors"}} 4 558 562
615  
616 558 $self->_add_entity_location($_, 'schema') foreach $state->{subschemas}->@*;
617  
618 558 return $state;
619 }
620  
621 # just like the base class's version, except we skip the evaluate step because we already did
622 # that as part of traverse.
623 6 ▶sub validate ($class, %args) {
Subroutine validate: called CC=3 SCAR=11.7
Pod documented
624 6 my $with_defaults = delete $args{with_defaults};
625  
626 6 ▶ my $document = blessed($class) ? $class : $class->new(%args);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($class) ? : 0 6 6
627 6 ▶ return JSON::Schema::Modern::Result->new(
Branch: 1 branch
BranchTrueFalseTotal
$with_defaults ? : 0 6 6
628 errors => [ $document->errors ],
629 $with_defaults ? (defaults => $document->defaults) : (),
630 );
631 }
632  
633 7 ▶sub upgrade ($self, $to_version = SUPPORTED_OAD_VERSIONS->[-1]) {
Subroutine upgrade: called CC=36 SCAR=37.1
Pod documented
634 7 ▶ croak 'cannot upgrade an invalid document' if $self->errors;
Branch: 1 branch
BranchTrueFalseTotal
if $self->errors 0 7 7
635  
636 7 ▶ croak 'new openapi version must be a dotted tuple or triple'
Branch: 1 branch
BranchTrueFalseTotal
unless $to_version =~ /^(3\.\d+)(?:\.\d+)?\z/a 1 6 7
637 if $to_version !~ /^(3\.\d+)(?:\.\d+)?\z/a;
638 6 my $to_oas_version = $1;
639 6 ▶ croak 'requested upgrade to an unsupported version: ', $to_version
Branch: 1 branch
BranchTrueFalseTotal
unless 1 5 6
640 if not grep $to_oas_version eq $_, OAS_VERSIONS->@*;
641  
642 5 ▶ ($to_version) = grep /^$to_version\./, SUPPORTED_OAD_VERSIONS->@* if $to_version =~ /^(3\.\d+)\z/a;
Branch: 1 branch
BranchTrueFalseTotal
if $to_version =~ /^(3\.\d+)\z/a 3 2 5
643  
644 5 my $schema = $self->schema;
645  
646 5 my $from_version = $schema->{openapi};
647 5 ▶ return $schema if $from_version eq $to_version;
Branch: 1 branch
BranchTrueFalseTotal
if $from_version eq $to_version 1 4 5
648  
649 4 my ($from_oas_version) = $schema->{openapi} =~ /^(3\.\d+)\.\d+\b/a;
650 4 ▶ croak 'downgrading is not supported' if $from_oas_version > $to_oas_version;
Branch: 1 branch
BranchTrueFalseTotal
if $from_oas_version > $to_oas_version 1 3 4
651  
652 3 $schema->{openapi} = $to_version;
653  
654 3 ▶ return $schema if $from_oas_version eq $to_oas_version;
Branch: 1 branch
BranchTrueFalseTotal
if $from_oas_version eq $to_oas_version 1 2 3
655  
656 2 ▶ if ($from_oas_version eq '3.0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($from_oas_version eq "3.0") 1 1 2
657 1 ▶ delete $schema->{paths} if not keys $schema->{paths}->%* and exists $schema->{components};
Branch: 1 branch
BranchTrueFalseTotal
if not keys %{$$schema{"paths"}} and exists $$schema{"components"} 1 0 1
Condition33%1/3
not keys %{$$schema{"paths"}} and exists $$schema{"components"}
!ll&&!rl&&r
001
MC/DC0%0/2
not keys %{$$schema{"paths"}} and exists $$schema{"components"}
not keys %{$$schema{"paths"}} exists $$schema{"components"}
Truth table33%1/3
not(A) and B
A= not keys %{$$schema{"paths"}}B= exists $$schema{"components"}
ABresult
0X0
100
111
658  
659 1 foreach my $media_type_path ($self->get_entity_locations('media-type')) {
660 1 my $media_type = (unjsonp($media_type_path))[-1];
661  
662 # convert {"schema": {"type": "string", "format": "binary"}} to {}
663 1 ▶ if ($media_type eq 'application/octet-stream') {
Branch: 1 branch
BranchTrueFalseTotal
if ($media_type eq "application/octet-stream") 1 0 1
664 1 my $media_type_obj = $self->get($media_type_path);
665 1 my $schema = $media_type_obj->{schema};
666 1 ▶ if ($schema and keys %$schema == 2
Branch: 1 branch
BranchTrueFalseTotal
if ($schema and keys %$schema == 2 and ($$schema{"type"} // "") eq "string" and ($$schema{"format"} // "") eq "binary") 1 0 1
Condition38%5/13
$schema and keys %$schema == 2 and ($$schema{"type"} // "") eq "string" and ($$schema{"format"} // "") eq "binary"
!ll&&!rl&&r
001
$schema and keys %$schema == 2 and ($$schema{"type"} // "") eq "string"
!ll&&!rl&&r
001
$schema and keys %$schema == 2
!ll&&!rl&&r
001
$$schema{"type"} // ""
l!l
10
$$schema{"format"} // ""
l!l
10
MC/DC0%0/4
$schema and keys %$schema == 2 and ($$schema{"type"} // "") eq "string" and ($$schema{"format"} // "") eq "binary"
$schema keys %$schema == 2 $$schema{"type"} $$schema{"format"}
Truth table20%1/5
A and B and C and D
A= $schemaB= keys %$schema == 2C= $$schema{"type"}D= $$schema{"format"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
667 and ($schema->{type}//'') eq 'string' and ($schema->{format}//'') eq 'binary') {
668 1 delete $media_type_obj->{schema};
669 1 delete $self->_entities->{$media_type_path.'/schema'};
670 }
671 }
672 }
673  
674 1 foreach my $schema_path ($self->get_entity_locations('schema')) {
675 6 my $subschema = $self->get($schema_path);
676  
677 6 ▶ if (exists $subschema->{nullable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$subschema{"nullable"}) 2 4 6
678 $subschema->{type} = [ $subschema->{type}, 'null' ]
679 2 ▶ if delete $subschema->{nullable} and exists $subschema->{type};
Branch: 1 branch
BranchTrueFalseTotal
if delete $$subschema{"nullable"} and exists $$subschema{"type"} 1 1 2
Condition66%2/3
delete $$subschema{"nullable"} and exists $$subschema{"type"}
!ll&&!rl&&r
101
MC/DC50%1/2
delete $$subschema{"nullable"} and exists $$subschema{"type"}
delete $$subschema{"nullable"} exists $$subschema{"type"}
Truth table66%2/3
A and B
A= delete $$subschema{"nullable"}B= exists $$subschema{"type"}
ABresult
0X0
100
111
680 }
681  
682 $subschema->{const} = (delete $subschema->{enum})->[0]
683 6 ▶ if exists $subschema->{enum} and $subschema->{enum}->@* == 1;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$subschema{"enum"} and @{$$subschema{"enum"}} == 1 1 5 6
Condition100%3/3
exists $$subschema{"enum"} and @{$$subschema{"enum"}} == 1
!ll&&!rl&&r
411
MC/DC100%2/2
exists $$subschema{"enum"} and @{$$subschema{"enum"}} == 1
exists $$subschema{"enum"} @{$$subschema{"enum"}} == 1
Truth table100%3/3
A and B
A= exists $$subschema{"enum"}B= @{$$subschema{"enum"}} == 1
ABresult
0X0
100
111
684  
685 6 ▶ $subschema->{exclusiveMinimum} = delete $subschema->{minimum} if delete $subschema->{exclusiveMinimum};
Branch: 1 branch
BranchTrueFalseTotal
if delete $$subschema{"exclusiveMinimum"} 1 5 6
686 6 ▶ $subschema->{exclusiveMaximum} = delete $subschema->{maximum} if delete $subschema->{exclusiveMaximum};
Branch: 1 branch
BranchTrueFalseTotal
if delete $$subschema{"exclusiveMaximum"} 1 5 6
687  
688 6 ▶ $subschema->{examples} = [ delete $subschema->{example} ] if exists $subschema->{example};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$subschema{"example"} 1 5 6
689  
690 6 ▶ if (exists $subschema->{format}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$subschema{"format"}) 2 4 6
691 2 ▶ if ($subschema->{format} eq 'binary') {
Branch: 2 branches
BranchTrueFalseTotal
if ($$subschema{'format'} eq 'binary') { } 1 1 2
elsif ($$subschema{'format'} eq 'base64') { } 1 0 1
692 1 $subschema->{contentMediaType} = 'application/octet-stream';
693 1 delete $subschema->{format};
694 }
695 elsif ($subschema->{format} eq 'base64') {
696 1 $subschema->{contentEncoding} = 'base64';
697 1 delete $subschema->{format};
698 }
699 }
700 }
701 }
702  
703 2 ▶ if ($to_oas_version ge '3.2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_oas_version ge "3.2") 1 1 2
704 1 foreach my $schema_path ($self->get_entity_locations('response')) {
705 2 my $subschema = $self->get($schema_path);
706 delete $subschema->{description}
707 2 ▶ if exists $subschema->{description} and $subschema->{description} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if exists $$subschema{"description"} and $$subschema{"description"} eq "" 1 1 2
Condition66%2/3
exists $$subschema{"description"} and $$subschema{"description"} eq ""
!ll&&!rl&&r
011
MC/DC50%1/2
exists $$subschema{"description"} and $$subschema{"description"} eq ""
exists $$subschema{"description"} $$subschema{"description"} eq ""
Truth table66%2/3
A and B
A= exists $$subschema{"description"}B= $$subschema{"description"} eq ""
ABresult
0X0
100
111
708 }
709 }
710  
711 2 return $schema;
712 }
713  
714 ######## NO PUBLIC INTERFACES FOLLOW THIS POINT ########
715  
716 # https://spec.openapis.org/oas/latest#schema-object
717 # traverse this JSON Schema and identify all errors, subschema locations, and referenceable
718 # identifiers
719 1005 ▶sub _traverse_schema ($self, $state) {
Subroutine _traverse_schema: called CC=11 SCAR=24.0
720 1005 my $schema = $self->get($state->{keyword_path});
721  
722 1005 ▶ if (get_type($schema) eq 'boolean' or not keys %$schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (get_type($schema) eq "boolean" or not keys %$schema) 201 804 1005
Condition100%3/3
get_type($schema) eq "boolean" or not keys %$schema
l!l&&r!l&&!r
16239804
MC/DC100%2/2
get_type($schema) eq "boolean" or not keys %$schema
get_type($schema) eq "boolean" not keys %$schema
Truth table100%3/3
A or not(B)
A= get_type($schema) eq "boolean"B= not keys %$schema
ABresult
1X1
011
000
723 201 push $state->{subschemas}->@*, $state->{keyword_path};
724 201 return;
725 }
726  
727 my $subschema_state = $state->{evaluator}->traverse($schema, {
728 initial_schema_uri => canonical_uri($state),
729 traversed_keyword_path => $state->{traversed_keyword_path}.$state->{keyword_path},
730 metaschema_uri => $state->{json_schema_dialect}, # can be overridden with the '$schema' keyword
731 804 });
732  
733 804 push $state->{errors}->@*, $subschema_state->{errors}->@*;
734 804 push $state->{subschemas}->@*, $subschema_state->{subschemas}->@*;
735 804 ▶ push $state->{references}->@*, ($subschema_state->{references}//[])->@* if $state->{references};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"references"} 804 0 804
Condition50%1/2
$$subschema_state{"references"} // []
l!l
8040
MC/DC0%0/1
$$subschema_state{"references"} // []
$$subschema_state{"references"}
Truth table50%1/2
A
A= $$subschema_state{"references"}
Aresult
11
00
736  
737 804 foreach my $new_uri (sort keys $subschema_state->{identifiers}->%*) {
738 29 ▶ if (not $state->{identifiers}{$new_uri}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$state{"identifiers"}{$new_uri}) 22 7 29
739 22 $state->{identifiers}{$new_uri} = $subschema_state->{identifiers}{$new_uri};
740 22 next;
741 }
742  
743 7 my $existing = $state->{identifiers}{$new_uri};
744 7 my $new = $subschema_state->{identifiers}{$new_uri};
745  
746 7 ▶ if (not is_equal(
Branch: 1 branch
BranchTrueFalseTotal
unless (is_equal({"canonical_uri", $$new{"canonical_uri"} . '', map(($_, $$new{$_}), ("path", "specification_version", "vocabularies"))}, {"canonical_uri", $$existing{"canonical_uri"} . '', map(($_, $$existing{$_}), ("path", "specification_version", "vocabularies"))})) 2 5 7
747 { canonical_uri => $new->{canonical_uri}.'', map +($_ => $new->{$_}), qw(path specification_version vocabularies) },
748 { canonical_uri => $existing->{canonical_uri}.'', map +($_ => $existing->{$_}), qw(path specification_version vocabularies) })) {
749 ()= E({ %$state, keyword_path => $new->{path} },
750 'duplicate canonical uri "%s" found (original at path "%s")',
751 2 $new_uri, $existing->{path});
752 2 next;
753 }
754  
755 5 foreach my $anchor (sort keys $new->{anchors}->%*) {
756 5 ▶ if (my $existing_anchor = ($existing->{anchors}//{})->{$anchor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $existing_anchor = ($$existing{"anchors"} // {})->{$anchor}) 2 3 5
Condition100%2/2
$$existing{"anchors"} // {}
l!l
32
MC/DC100%1/1
$$existing{"anchors"} // {}
$$existing{"anchors"}
Truth table100%2/2
A
A= $$existing{"anchors"}
Aresult
11
00
757 ()= E({ %$state, keyword_path => $new->{anchors}{$anchor}{path} },
758 'duplicate anchor uri "%s" found (original at path "%s")',
759 $new->{canonical_uri}->clone->fragment($anchor),
760 2 $existing->{anchors}{$anchor}{path});
761 2 next;
762 }
763  
764 18 ▶ use autovivification 'store';
Subroutine BEGIN: called CC=1 SCAR=0.0
765 3 $existing->{anchors}{$anchor} = $new->{anchors}{$anchor};
766 }
767 }
768 }
769  
770 # Given a jsonSchemaDialect uri, generate a new schema that wraps the standard OAD schema
771 # to set the jsonSchemaDialect value for the #meta dynamic reference.
772 # This metaschema does not allow subschemas to select their own $schema; for that, you
773 # should construct your own, based on DEFAULT_BASE_METASCHEMA.
774 0 ▶sub _dynamic_metaschema_uri ($self, $json_schema_dialect, $evaluator) {
Subroutine _dynamic_metaschema_uri: not called CC=2 SCAR=17.9
775 0 $json_schema_dialect .= '';
776 0 my $dialect_uri = 'https://custom-dialect.example.com/' . md5_hex($json_schema_dialect);
777 0 ▶ return $dialect_uri if $evaluator->_get_resource($dialect_uri);
Branch: 1 branch
BranchTrueFalseTotal
if $evaluator->_get_resource($dialect_uri) 0 0 0
778  
779 # we use the definition of https://spec.openapis.org/oas/<version>/schema-base/<date> but swap out
780 # the dialect reference.
781 0 my $schema = clone($evaluator->_get_resource(DEFAULT_BASE_METASCHEMA->{$self->oas_version})->{document}->schema);
782 0 $schema->{'$id'} = $dialect_uri;
783 0 $schema->{'$defs'}{dialect}{const} = $json_schema_dialect;
784 0 $schema->{'$defs'}{schema}{'$ref'} = $json_schema_dialect;
785  
786 0 $evaluator->add_document(
787 Mojo::URL->new($dialect_uri),
788 JSON::Schema::Modern::Document->new(
789 schema => $schema,
790 evaluator => $evaluator,
791 ));
792  
793 0 return $dialect_uri;
794 }
795  
796 # FREEZE is defined by parent class
797  
798 # callback hook for Sereal::Decoder
799 2 ▶sub THAW ($class, $serializer, $data) {
Subroutine THAW: called CC=5 SCAR=17.2
Pod undocumented
800 2 delete $data->{evaluator}; # no longer exists on this class
801  
802 2 ▶ if (defined(my $dialect = delete $data->{json_schema_dialect})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dialect = delete $$data{"json_schema_dialect"})) 0 2 2
803 0 carp "use of no-longer-supported constructor argument: json_schema_dialect = \"$dialect\"; use \"jsonSchemaDialect\": \"...\" in your OpenAPI document itself";
804 }
805  
806 2 my $self = bless($data, $class);
807 2 ▶ $self->oas_version(OAS_VERSIONS->[-1]) if not defined $self->oas_version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->oas_version 0 2 2
808  
809 2 foreach my $attr (qw(schema _entities)) {
810 croak "serialization missing attribute '$attr': perhaps your serialized data was produced for an older version of $class?"
811 4 ▶ if not exists $self->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$self{$attr} 0 4 4
812 }
813  
814 2 return $self;
815 }
816  
817 18 1;
818  
819 __END__
↑ Summary OpenAPI/Modern.pm »