OpenAPI/Modern.pm

filter: Statementstmt 97.6% 972 / 995 Branchbran 93.2% 841 / 902 Conditioncond 86.0% 568 / 660 MC/DCmcdc 69.0% 250 / 362 Subroutinesub 94.4% 68 / 72 Podpod 81.8% 9 / 11 totaltotal 90.2% 2708 / 3002 CC 737 SCAR 40.0
CC
737
Cov
93%
_deserialize_style
141.4
find_path_item
82.1
_decode_content_element
64.1
CRAP 54.5
« JSON/Schema/Modern/Document/OpenAPI.pm ↑ Summary JSON/Schema/Modern/Vocabulary/OpenAPI_3_0.pm »
1 18 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package OpenAPI::Modern; # git description: v0.150-7-g92ffb1dc
3 # vim: set ts=8 sts=2 sw=2 tw=100 et :
4 # ABSTRACT: Validate HTTP requests and responses against an OpenAPI v3.0, v3.1 or v3.2 document
5 # KEYWORDS: validation evaluation JSON Schema OpenAPI v3.0 v3.1 v3.2 Swagger HTTP request response
6  
7 18 our $VERSION = '0.151';
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 ▶use if "$]" < 5.026, experimental => 'lexical_subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶no autovivification warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 ▶no if "$]" >= 5.041009, feature => 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 18 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 18 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 18 ▶use List::Util qw(first pairs uniq pairkeys pairgrep max);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 18 ▶use if "$]" < 5.041010, 'List::Util' => qw(all any);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 18 ▶use if "$]" >= 5.041010, experimental => qw(keyword_all keyword_any);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 18 ▶use builtin::compat qw(indexed blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 18 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 18 ▶use Encode 2.89 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 18 ▶use JSON::Schema::Modern;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 18 ▶use JSON::Schema::Modern::Utilities qw(jsonp unjsonp canonical_uri E abort is_equal true false get_type is_type jsonp_set jsonp_get jsonp_elements decode_media_type match_media_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 18 ▶use OpenAPI::Modern::Utilities qw(add_vocab_and_default_schemas add_formats convert_request convert_response uri_decode intersect_types coerce_primitive uri_encode uri_encode_strict is_header_name is_cookie_name is_cookie_value elem deserialize_multipart);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 18 ▶use JSON::Schema::Modern::Document::OpenAPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 18 ▶use MooX::TypeTiny 0.002002;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 18 ▶use Types::Standard qw(ArrayRef InstanceOf Bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 18 ▶use Mojo::Util qw(url_unescape punycode_decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 18 ▶use Mojo::Message::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 18 ▶use Mojo::Message::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 18 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 18 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # the first value is always the entry document
43 18 has openapi_documents => (
44 is => 'ro',
45 isa => ArrayRef[InstanceOf(['JSON::Schema::Modern::Document::OpenAPI'])],
46 required => 1, # populated from 'documents' in BUILDARGS
47 );
48  
49 3571 ▶sub entry_document ($self) { $self->{openapi_documents}[0] }
Subroutine entry_document: called CC=1 SCAR=0.0
Pod documented
50  
51 # backcompat aliases; may be removed eventually
52 18 my ($warn_openapi_document, $warn_openapi_uri, $warn_openapi_schema, $warn_document_get);
53 0 ▶sub openapi_document ($self) {
Subroutine openapi_document: not called CC=2 SCAR=17.9
Pod documented
54 0 ▶ carp 'openapi_document is deprecated; use entry_document instead' if not $warn_openapi_document++;
Branch: 1 branch
BranchTrueFalseTotal
unless $warn_openapi_document++ 0 0 0
55 0 $self->{openapi_documents}[0];
56 }
57 0 ▶sub openapi_uri ($self) {
Subroutine openapi_uri: not called CC=2 SCAR=17.9
Pod documented
58 0 ▶ carp 'openapi_uri is deprecated; use entry_document->canonical_uri instead' if not $warn_openapi_uri++;
Branch: 1 branch
BranchTrueFalseTotal
unless $warn_openapi_uri++ 0 0 0
59 0 $self->{openapi_documents}[0]->canonical_uri;
60 }
61 0 ▶sub openapi_schema ($self) {
Subroutine openapi_schema: not called CC=2 SCAR=17.9
Pod documented
62 0 ▶ carp 'openapi_schema is deprecated; use entry_document->schema instead' if not $warn_openapi_schema++;
Branch: 1 branch
BranchTrueFalseTotal
unless $warn_openapi_schema++ 0 0 0
63 0 $self->{openapi_documents}[0]->schema;
64 }
65 0 ▶sub document_get ($self, $path) {
Subroutine document_get: not called CC=2 SCAR=17.9
Pod documented
66 0 ▶ carp 'document_get is deprecated; use entry_document->get instead' if not $warn_document_get++;
Branch: 1 branch
BranchTrueFalseTotal
unless $warn_document_get++ 0 0 0
67 0 $self->{openapi_documents}[0]->get($path);
68 }
69  
70 18 has evaluator => (
71 is => 'ro',
72 isa => InstanceOf['JSON::Schema::Modern'],
73 required => 1,
74 handles => [ qw(get_media_type add_media_type) ], # deprecated; may be removed
75 );
76  
77 18 our $DEBUG;
78 18 has debug => (
79 is => 'ro',
80 isa => Bool,
81 default => $DEBUG,
82 );
83  
84 18 has with_defaults => (
85 is => 'ro',
86 isa => Bool,
87 );
88  
89 474 ▶around BUILDARGS => sub ($orig, $class, @args) {
Subroutine __ANON__: called CC=13 SCAR=25.7
90 474 my $args = $class->$orig(@args);
91  
92 croak 'cannot provide "openapi_documents"; use "documents" instead'
93 474 ▶ if exists $args->{openapi_documents};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"openapi_documents"} 1 473 474
94  
95 croak 'missing required constructor arguments: either "documents", "openapi_document", or "openapi_schema"'
96 473 ▶ if not any { exists $args->{$_} } qw(documents openapi_document openapi_schema);
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::any {exists $$args{$_};} "documents", "openapi_document", "openapi_schema" 2 471 473
97  
98 croak 'cannot provide both "openapi_document" and "documents"'
99 471 ▶ if exists $args->{openapi_document} and exists $args->{documents};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"openapi_document"} and exists $$args{"documents"} 1 470 471
Condition100%3/3
exists $$args{"openapi_document"} and exists $$args{"documents"}
!ll&&!rl&&r
46551
MC/DC100%2/2
exists $$args{"openapi_document"} and exists $$args{"documents"}
exists $$args{"openapi_document"} exists $$args{"documents"}
Truth table100%3/3
A and B
A= exists $$args{"openapi_document"}B= exists $$args{"documents"}
ABresult
0X0
100
111
100  
101 470 ▶ $args->{documents} = [ delete $args->{openapi_document} ] if exists $args->{openapi_document};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"openapi_document"} 5 465 470
102  
103 croak 'the first document must be a JSON::Schema::Modern::Document::OpenAPI object'
104 470 ▶ if exists $args->{documents} and not $args->{documents}[0]->isa('JSON::Schema::Modern::Document::OpenAPI');
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"documents"} and not $$args{"documents"}[0]->isa("JSON::Schema::Modern::Document::OpenAPI") 0 470 470
Condition66%2/3
exists $$args{"documents"} and not $$args{"documents"}[0]->isa("JSON::Schema::Modern::Document::OpenAPI")
!ll&&!rl&&r
46550
MC/DC0%0/2
exists $$args{"documents"} and not $$args{"documents"}[0]->isa("JSON::Schema::Modern::Document::OpenAPI")
exists $$args{"documents"} not $$args{"documents"}[0]->isa("JSON::Schema::Modern::Document::OpenAPI")
Truth table66%2/3
A and not(B)
A= exists $$args{"documents"}B= not $$args{"documents"}[0]->isa("JSON::Schema::Modern::Document::OpenAPI")
ABresult
0X0
100
111
105  
106 470 my $extra_args = { %$args };
107 470 delete $extra_args->@{qw(documents openapi_schema openapi_uri evaluator debug)};
108  
109 470 ▶ $args->{evaluator} //= JSON::Schema::Modern->new(
Condition66%2/3
$$args{"evaluator"} //= "JSON::Schema::Modern"->new("validate_formats", 1, "max_depth", 80, %$extra_args)
l!l&&r!l&&!r
44660
MC/DC0%0/2
$$args{"evaluator"} //= "JSON::Schema::Modern"->new("validate_formats", 1, "max_depth", 80, %$extra_args)
$$args{"evaluator"} "JSON::Schema::Modern"->new("validate_formats", 1, "max_depth", 80, %$extra_args)
Truth table66%2/3
A //= B
A= $$args{"evaluator"}B= "JSON::Schema::Modern"->new("validate_formats", 1, "max_depth", 80, %$extra_args)
ABresult
1X1
011
000
110 validate_formats => 1,
111 max_depth => 80,
112 %$extra_args, # may include with_defaults, or other arguments recognized by JSM
113 );
114  
115 470 ▶ if (not (exists $args->{documents} and $args->{documents}->@*)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $$args{'documents'} && @{$$args{'documents'}}) { } 465 5 470
Condition66%2/3
exists $$args{'documents'} && @{$$args{'documents'}}
!ll&&!rl&&r
46505
MC/DC50%1/2
exists $$args{'documents'} && @{$$args{'documents'}}
exists $$args{'documents'} @{$$args{'documents'}}
Truth table66%2/3
A && B
A= exists $$args{'documents'}B= @{$$args{'documents'}}
ABresult
0X0
100
111
116 $args->{documents} = [ JSON::Schema::Modern::Document::OpenAPI->new(
117 exists $args->{openapi_uri} ? (canonical_uri => delete $args->{openapi_uri}) : (),
118 schema => delete $args->{openapi_schema},
119 evaluator => $args->{evaluator},
120 465 ▶ ) ];
Branch: 1 branch
BranchTrueFalseTotal
exists $$args{'openapi_uri'} ? : 463 2 465
121 }
122 else {
123 # add the OpenAPI vacabulary, formats and metaschemas to the evaluator if not already there
124 5 add_vocab_and_default_schemas($args->{evaluator}, $args->{documents}[0]->oas_version);
125 5 add_formats($args->{evaluator}, $args->{documents}[0]->oas_version);
126 }
127  
128 # if there were errors, this will die with a JSON::Schema::Modern::Result object
129 469 $args->{evaluator}->add_document($_) foreach $args->{documents}->@*;
130  
131 468 $args->{openapi_documents} = [ grep $_->isa('JSON::Schema::Modern::Document::OpenAPI'), $args->{documents}->@* ];
132 468 delete $args->{documents}; # no need to save non-OpenAPI documents; they are in the evaluator
133  
134 468 return $args;
135 18 };
136  
137 566 ▶sub validate_request ($self, $request, $options = {}) {
Subroutine validate_request: called CC=57 SCAR=40.8
Pod documented
138 566 ▶ croak 'missing request' if not $request;
Branch: 1 branch
BranchTrueFalseTotal
unless $request 5 561 566
139  
140 croak '$request and $options->{request} are inconsistent'
141 561 ▶ if $options->{request} and $request != $options->{request};
Branch: 1 branch
BranchTrueFalseTotal
if $$options{"request"} and $request != $$options{"request"} 2 559 561
Condition66%2/3
$$options{"request"} and $request != $$options{"request"}
!ll&&!rl&&r
55902
MC/DC50%1/2
$$options{"request"} and $request != $$options{"request"}
$$options{"request"} $request != $$options{"request"}
Truth table66%2/3
A and B
A= $$options{"request"}B= $request != $$options{"request"}
ABresult
0X0
100
111
142  
143 # mostly populated by find_path_item
144 559 ▶ my $state = {
Branch: 1 branch
BranchTrueFalseTotal
$self->with_defaults ? : 24 535 559
145 data_path => '/request',
146 $self->with_defaults ? (defaults => {}) : (),
147 };
148  
149 559 try {
150 559 ▶ $options->{request} //= $request;
Condition33%1/3
$$options{"request"} //= $request
l!l&&r!l&&!r
05590
MC/DC0%0/2
$$options{"request"} //= $request
$$options{"request"} $request
Truth table33%1/3
A //= B
A= $$options{"request"}B= $request
ABresult
1X1
011
000
151 559 my $path_ok = $self->find_path_item($options, $state);
152 559 delete $options->{errors};
153  
154 559 my $path_item = delete $options->{_path_item}; # after following path-item $refs
155 559 my $operation = delete $options->{_operation};
156 559 my $ops = delete $options->{_operation_path_suffix}; # jsonp-encoded
157  
158 # Reporting a failed find_path_item as an exception will result in a recommended response of
159 # [ 500, Internal Server Error ], which is warranted if we consider the lack of a specification
160 # entry for this incoming request as an unexpected, server-side error.
161 # Callers can decide if this should instead be reported as a [ 404, Not Found ], but that sort
162 # of response is likely to leave oversights in the specification go unnoticed.
163 559 ▶ return $self->_result($state, 1) if not $path_ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $path_ok 11 548 559
164  
165 548 my $server = { $options->{uri_captures}->%* };
166 548 delete $server->@{keys $options->{path_captures}->%*};
167 548 ▶ $state->{data} = keys %$server ? { request => { uri => { server => $server } } } : {};
Branch: 1 branch
BranchTrueFalseTotal
keys %$server ? : 2 546 548
168  
169 548 $request = $options->{request}; # now guaranteed to be a Mojo::Message::Request
170  
171 # PARAMETERS
172 # { $in => { $name => path-item|operation } } as we process each one.
173 548 my $request_parameters_processed = {};
174 548 my %seen_q;
175  
176 # first, consider parameters at the operation level.
177 # parameters at the path-item level are also considered, if not already seen at the operation level
178 SECTION:
179 548 foreach my $section (qw(operation path-item)) {
180 ENTRY:
181 1080 ▶ foreach my $idx (0 .. (($section eq 'operation' ? $operation : $path_item)->{parameters}//[])->$#*) {
Branch: 1 branch
BranchTrueFalseTotal
$section eq 'operation' ? : 548 532 1080
Condition100%2/2
($section eq "operation" ? $operation : $path_item)->{"parameters"} // []
l!l
260820
MC/DC100%1/1
($section eq "operation" ? $operation : $path_item)->{"parameters"} // []
($section eq "operation" ? $operation : $path_item)->{"parameters"}
Truth table100%2/2
A
A= ($section eq "operation" ? $operation : $path_item)->{"parameters"}
Aresult
11
00
182 842 ▶ my $state = { %$state, keyword_path => $state->{keyword_path}.($section eq 'operation' ? $ops : '').'/parameters/'.$idx };
Branch: 1 branch
BranchTrueFalseTotal
$section eq 'operation' ? : 679 163 842
183 842 ▶ my $param_obj = ($section eq 'operation' ? $operation : $path_item)->{parameters}[$idx];
Branch: 1 branch
BranchTrueFalseTotal
$section eq 'operation' ? : 679 163 842
184 842 ▶ while (defined(my $ref = $param_obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$param_obj{"\$ref"})) 90 834 924
185 90 $param_obj = $self->_resolve_ref('parameter', $ref, $state);
186 }
187  
188 834 ▶ my $fc_name = $param_obj->{in} eq 'header' ? fc($param_obj->{name}) : $param_obj->{name};
Branch: 1 branch
BranchTrueFalseTotal
$$param_obj{'in'} eq 'header' ? : 313 521 834
189  
190 # v3.2.0 §4.12.2.1: "If in is "header" and the name field is "Accept", "Content-Type" or
191 # "Authorization", the parameter definition SHALL be ignored."
192 834 ▶ next if $param_obj->{in} eq 'header' and elem($fc_name, [map fc, qw(Accept Content-Type Authorization)]);
Branch: 1 branch
BranchTrueFalseTotal
if $$param_obj{"in"} eq "header" and elem($fc_name, [map(fc($_), ("Accept", "Content-Type", "Authorization"))]) 6 828 834
Condition100%3/3
$$param_obj{"in"} eq "header" and elem($fc_name, [map(fc($_), ("Accept", "Content-Type", "Authorization"))])
!ll&&!rl&&r
5213076
MC/DC100%2/2
$$param_obj{"in"} eq "header" and elem($fc_name, [map(fc($_), ("Accept", "Content-Type", "Authorization"))])
$$param_obj{"in"} eq "header" elem($fc_name, [map(fc($_), ("Accept", "Content-Type", "Authorization"))])
Truth table100%3/3
A and B
A= $$param_obj{"in"} eq "header"B= elem($fc_name, [map(fc($_), ("Accept", "Content-Type", "Authorization"))])
ABresult
0X0
100
111
193  
194 # v3.2.0 §4.10.1:"The list MUST NOT include duplicated parameters. A unique parameter is
195 # defined by a combination of a name and location."
196 abort($state, 'duplicate %s parameter "%s"', $param_obj->{in}, $param_obj->{name})
197 828 ▶ if (($request_parameters_processed->{$param_obj->{in}}//{})->{$fc_name} // '') eq $section;
Branch: 1 branch
BranchTrueFalseTotal
if (($$request_parameters_processed{$$param_obj{"in"}} // {})->{$fc_name} // "") eq $section 4 824 828
Condition100%4/4
($$request_parameters_processed{$$param_obj{"in"}} // {})->{$fc_name} // ""
l!l
22806
$$request_parameters_processed{$$param_obj{"in"}} // {}
l!l
424404
MC/DC100%1/1
($$request_parameters_processed{$$param_obj{"in"}} // {})->{$fc_name} // ""
$$request_parameters_processed{$$param_obj{"in"}}
Truth table100%2/2
A
A= $$request_parameters_processed{$$param_obj{"in"}}
Aresult
11
00
198  
199 824 ++$seen_q{$param_obj->{in}};
200 abort({ %$state, data_path => '/request/uri/query' }, 'cannot use query and querystring together')
201 824 ▶ if $seen_q{query} and $seen_q{querystring};
Branch: 1 branch
BranchTrueFalseTotal
if $seen_q{"query"} and $seen_q{"querystring"} 2 822 824
Condition100%3/3
$seen_q{"query"} and $seen_q{"querystring"}
!ll&&!rl&&r
3444782
MC/DC100%2/2
$seen_q{"query"} and $seen_q{"querystring"}
$seen_q{"query"} $seen_q{"querystring"}
Truth table100%3/3
A and B
A= $seen_q{"query"}B= $seen_q{"querystring"}
ABresult
0X0
100
111
202  
203 abort({ %$state, data_path => '/request/uri/query' }, 'cannot use more than one querystring')
204 822 ▶ if ($seen_q{querystring}//0) >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_q{"querystring"} // 0) >= 2 2 820 822
Condition100%2/2
$seen_q{"querystring"} // 0
l!l
45777
MC/DC100%1/1
$seen_q{"querystring"} // 0
$seen_q{"querystring"}
Truth table100%2/2
A
A= $seen_q{"querystring"}
Aresult
11
00
205  
206 # v3.2.0 §4.10.1: "If a[n operation-level] parameter is already defined at the Path Item,
207 # the new definition will override it but can never remove it."
208 18 ▶ { use autovivification qw(exists store);
Subroutine BEGIN: called CC=1 SCAR=0.0
209 820 ▶ next ENTRY if exists $request_parameters_processed->{$param_obj->{in}}{$fc_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$request_parameters_processed{$$param_obj{"in"}}{$fc_name} 16 804 820
210 804 $request_parameters_processed->{$param_obj->{in}}{$fc_name} = $section;
211 }
212  
213 my $valid = $self->_validate_parameter({ %$state, depth => $state->{depth}+1,
214 data_path => ($param_obj->{in} eq 'path' ? '/request/uri/path'
215 : $param_obj->{in} eq 'query' ? '/request/uri/query'
216 : $param_obj->{in} eq 'header' ? '/request/header'
217 : $param_obj->{in} eq 'cookie' ? '/request/header/Cookie'
218 : $param_obj->{in} eq 'querystring' ? '/request/uri/query' : die) },
219 $param_obj,
220 $param_obj->{in} eq 'path' ? (path_captures => $options->{path_captures})
221 : $param_obj->{in} eq 'query' ? (params => $request->url->query->clone)
222 : $param_obj->{in} eq 'header' ? (name => $param_obj->{name}, headers => $request->headers)
223 : $param_obj->{in} eq 'cookie' ? (headers => $request->headers)
224 804 ▶ : $param_obj->{in} eq 'querystring' ? (params => $request->url->query->clone)
Branch: 10 branches
BranchTrueFalseTotal
$$param_obj{'in'} eq 'path' ? : 152 652 804
$$param_obj{'in'} eq 'query' ? : 230 422 652
$$param_obj{'in'} eq 'header' ? : 295 127 422
$$param_obj{'in'} eq 'cookie' ? : 84 43 127
$$param_obj{'in'} eq 'querystring' ? : 43 0 43
$$param_obj{'in'} eq 'path' ? : 152 652 804
$$param_obj{'in'} eq 'query' ? : 230 422 652
$$param_obj{'in'} eq 'header' ? : 295 127 422
$$param_obj{'in'} eq 'cookie' ? : 84 43 127
$$param_obj{'in'} eq 'querystring' ? : 43 0 43
225 : die);
226 }
227 }
228  
229 # v3.2.0 §4.8.2, "Path Templating": "Each template expression in the path MUST correspond to a
230 # path parameter that is included in the Path Item itself and/or in each of the Path Item’s
231 # Operations."
232 # We could validate this at document parse time, except the path-item can also be reached via a
233 # $ref and the referencing path could be from another document and is therefore unknowable until
234 # runtime.
235 524 foreach my $path_name (sort keys $options->{path_captures}->%*) {
236 abort({ %$state, data_path => jsonp('/request/uri/path', $path_name) },
237 'missing path parameter specification for "%s"', $path_name)
238 148 ▶ if not exists(($request_parameters_processed->{path}//{})->{$path_name});
Branch: 1 branch
BranchTrueFalseTotal
unless exists(($$request_parameters_processed{"path"} // {})->{$path_name}) 2 146 148
Condition100%2/2
$$request_parameters_processed{"path"} // {}
l!l
1462
MC/DC100%1/1
$$request_parameters_processed{"path"} // {}
$$request_parameters_processed{"path"}
Truth table100%2/2
A
A= $$request_parameters_processed{"path"}
Aresult
11
00
239 }
240  
241 522 $state->{keyword_path} .= $ops;
242  
243 # RFC9112 §6.2-2: "A sender MUST NOT send a Content-Length header field in any message that
244 # contains a Transfer-Encoding header field."
245 522 ▶ ()= E({ %$state, data_path => '/request/header/Content-Length', },
Branch: 1 branch
BranchTrueFalseTotal
if defined $request->headers->content_length and $request->content->is_chunked 2 520 522
Condition100%3/3
defined $request->headers->content_length and $request->content->is_chunked
!ll&&!rl&&r
1453752
MC/DC100%2/2
defined $request->headers->content_length and $request->content->is_chunked
defined $request->headers->content_length $request->content->is_chunked
Truth table100%3/3
A and B
A= defined $request->headers->content_lengthB= $request->content->is_chunked
ABresult
0X0
100
111
246 'Content-Length cannot appear together with Transfer-Encoding')
247 if defined $request->headers->content_length and $request->content->is_chunked;
248  
249 # RFC9112 §6.3-7: "A user agent that sends a request that contains a message body MUST send
250 # either a valid Content-Length header field or use the chunked transfer coding."
251 522 ▶ ()= E({ %$state, data_path => '/request/header',
Branch: 1 branch
BranchTrueFalseTotal
if $request->body_size and not $request->headers->content_length and not $request->content->is_chunked 2 520 522
Condition83%5/6
$request->body_size and not $request->headers->content_length and not $request->content->is_chunked
!ll&&!rl&&r
52002
$request->body_size and not $request->headers->content_length
!ll&&!rl&&r
1613592
MC/DC66%2/3
$request->body_size and not $request->headers->content_length and not $request->content->is_chunked
$request->body_size not $request->headers->content_length not $request->content->is_chunked
Truth table75%3/4
A and not(B) and not(C)
A= $request->body_sizeB= not $request->headers->content_lengthC= not $request->content->is_chunked
ABCresult
0XX0
10X0
1100
1111
252 recommended_response => [ 411 ] }, 'missing header: Content-Length')
253 if $request->body_size and not $request->headers->content_length
254 and not $request->content->is_chunked;
255  
256 522 ▶ if (my $body_obj = $operation->{requestBody}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body_obj = $$operation{'requestBody'}) { } 388 134 522
257 388 $state->{keyword_path} .= '/requestBody';
258  
259 388 ▶ while (defined(my $ref = $body_obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$body_obj{"\$ref"})) 14 386 400
260 14 $body_obj = $self->_resolve_ref('request-body', $ref, $state);
261 }
262  
263 386 ▶ if ($request->body_size) {
Branch: 2 branches
BranchTrueFalseTotal
if ($request->body_size) { } 355 31 386
elsif ($$body_obj{'required'}) { } 5 26 31
264 355 $state->{data_path} = '/request/body';
265 355 $self->_validate_body_content({ %$state, depth => $state->{depth}+1 }, $body_obj->{content}, $request);
266 }
267 elsif ($body_obj->{required}) {
268 5 ()= E({ %$state, keyword => 'required' }, 'request body is required but missing');
269 }
270 }
271 else {
272 134 $state->{data_path} = '/request/body';
273 # we presume that no body specification for GET and HEAD requests -> no body is expected
274 134 ▶ ()= E($state, 'unspecified body is present in %s request', $request->method)
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "GET" || $request->method eq "HEAD" and $request->headers->content_length // $request->body_size 8 126 134
Condition88%8/9
$request->method eq "GET" || $request->method eq "HEAD" and $request->headers->content_length // $request->body_size
!ll&&!rl&&r
221048
$request->method eq "GET" or $request->method eq "HEAD"
l!l&&r!l&&!r
108422
$request->headers->content_length // $request->body_size
l!l&&r!l&&!r
81040
MC/DC50%2/4
$request->method eq "GET" || $request->method eq "HEAD" and $request->headers->content_length // $request->body_size
$request->method eq "GET" $request->method eq "HEAD" $request->headers->content_length $request->body_size
Truth table57%4/7
A or B and C // D
A= $request->method eq "GET"B= $request->method eq "HEAD"C= $request->headers->content_lengthD= $request->body_size
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
275 if ($request->method eq 'GET' or $request->method eq 'HEAD')
276 and $request->headers->content_length // $request->body_size;
277 }
278 }
279 catch ($e) {
280 36 ▶ if (blessed($e) and $e->isa('JSON::Schema::Modern::Result')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($e) and $e->isa('JSON::Schema::Modern::Result')) { } 0 36 36
elsif (builtin::blessed($e) and $e->isa('JSON::Schema::Modern::Error')) { } 36 0 36
Condition33%1/3
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Result")
!ll&&!rl&&r
0360
MC/DC0%0/2
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Result")
builtin::blessed($e) $e->isa("JSON::Schema::Modern::Result")
Truth table33%1/3
A and B
A= builtin::blessed($e)B= $e->isa("JSON::Schema::Modern::Result")
ABresult
0X0
100
111
281 0 return $e;
282 }
283 ▶ elsif (blessed($e) and $e->isa('JSON::Schema::Modern::Error')) {
Condition33%1/3
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Error")
!ll&&!rl&&r
0036
MC/DC0%0/2
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Error")
builtin::blessed($e) $e->isa("JSON::Schema::Modern::Error")
Truth table33%1/3
A and B
A= builtin::blessed($e)B= $e->isa("JSON::Schema::Modern::Error")
ABresult
0X0
100
111
284 36 push @{$state->{errors}}, $e;
285 }
286 else {
287 0 ()= E({ %$state, exception => 1 }, 'EXCEPTION: '.$e);
288 }
289 }
290  
291 548 return $self->_result($state);
292 }
293  
294 91 ▶sub validate_response ($self, $response, $options = {}) {
Subroutine validate_response: called CC=41 SCAR=37.9
Pod documented
295 91 ▶ croak 'missing response' if not $response;
Branch: 1 branch
BranchTrueFalseTotal
unless $response 1 90 91
296  
297 # handle the existence of HTTP::Response::request
298 90 ▶ if (my $request = $response->can('request') && $response->request) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $request = $response->can("request") && $response->request) 4 86 90
Condition100%3/3
$response->can('request') && $response->request
!ll&&!rl&&r
43434
MC/DC100%2/2
$response->can('request') && $response->request
$response->can('request') $response->request
Truth table100%3/3
A && B
A= $response->can('request')B= $response->request
ABresult
0X0
100
111
299 croak '$response->request and $options->{request} are inconsistent'
300 4 ▶ if $request and $options->{request} and $request != $options->{request};
Branch: 1 branch
BranchTrueFalseTotal
if $request and $$options{"request"} and $request != $$options{"request"} 1 3 4
Condition66%4/6
$request and $$options{"request"} and $request != $$options{"request"}
!ll&&!rl&&r
301
$request and $$options{"request"}
!ll&&!rl&&r
031
MC/DC33%1/3
$request and $$options{"request"} and $request != $$options{"request"}
$request $$options{"request"} $request != $$options{"request"}
Truth table50%2/4
A and B and C
A= $requestB= $$options{"request"}C= $request != $$options{"request"}
ABCresult
0XX0
10X0
1100
1111
301 3 ▶ $options->{request} //= $request;
Condition33%1/3
$$options{"request"} //= $request
l!l&&r!l&&!r
030
MC/DC0%0/2
$$options{"request"} //= $request
$$options{"request"} $request
Truth table33%1/3
A //= B
A= $$options{"request"}B= $request
ABresult
1X1
011
000
302 }
303  
304 croak '$response and $options->{response} are inconsistent'
305 89 ▶ if $options->{response} and $response != $options->{response};
Branch: 1 branch
BranchTrueFalseTotal
if $$options{"response"} and $response != $$options{"response"} 0 89 89
Condition33%1/3
$$options{"response"} and $response != $$options{"response"}
!ll&&!rl&&r
8900
MC/DC0%0/2
$$options{"response"} and $response != $$options{"response"}
$$options{"response"} $response != $$options{"response"}
Truth table33%1/3
A and B
A= $$options{"response"}B= $response != $$options{"response"}
ABresult
0X0
100
111
306  
307 # mostly populated by find_path_item
308 89 ▶ my $state = {
Branch: 1 branch
BranchTrueFalseTotal
$self->with_defaults ? : 4 85 89
309 data_path => '/response',
310 $self->with_defaults ? (defaults => {}) : (),
311 };
312  
313 89 try {
314 # we only need the operation location, and do not need to verify the request uri, path template
315 # and path_captures, so do not pass unnecessary information to find_path_item
316 89 my $fp_options = +{ %$options };
317 89 ▶ delete $fp_options->@{qw(request uri method path_template path_captures)} if exists $options->{operation_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$options{"operation_id"} 27 62 89
318 89 ▶ delete $fp_options->@{qw(request uri path_captures)} if exists $options->{path_template} and exists $options->{method};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$options{"path_template"} and exists $$options{"method"} 56 33 89
Condition66%2/3
exists $$options{"path_template"} and exists $$options{"method"}
!ll&&!rl&&r
33056
MC/DC50%1/2
exists $$options{"path_template"} and exists $$options{"method"}
exists $$options{"path_template"} exists $$options{"method"}
Truth table66%2/3
A and B
A= exists $$options{"path_template"}B= exists $$options{"method"}
ABresult
0X0
100
111
319 89 my $path_ok = $self->find_path_item($fp_options, $state);
320 89 $options->@{keys $fp_options->%*} = values $fp_options->%*;
321  
322 89 delete $options->@{qw(errors _path_item)};
323 89 my $operation = delete $options->{_operation};
324  
325 89 ▶ return $self->_result($state, 1, 1) if not $path_ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $path_ok 5 84 89
326  
327 84 $state->{data} = {};
328 84 $state->{keyword_path} .= delete $options->{_operation_path_suffix}; # jsonp-encoded
329  
330 # now guaranteed to be a Mojo::Message::Response
331 84 $options->{response} = $response = convert_response($response);
332  
333 84 ▶ return $self->_result($state, 0, 1) if not exists $operation->{responses};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$operation{"responses"} 3 81 84
334  
335 81 ▶ if ($response->headers->header('Transfer-Encoding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->headers->header("Transfer-Encoding")) 8 73 81
336 8 ▶ ()= E({ %$state, data_path => '/response/header/Transfer-Encoding' },
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_info or $response->code == 204 4 4 8
Condition100%3/3
$response->is_info or $response->code == 204
l!l&&r!l&&!r
224
MC/DC100%2/2
$response->is_info or $response->code == 204
$response->is_info $response->code == 204
Truth table100%3/3
A or B
A= $response->is_infoB= $response->code == 204
ABresult
1X1
011
000
337 'RFC9112 §6.1-10: "A server MUST NOT send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content)"')
338 if $response->is_info or $response->code == 204;
339  
340 ()= E({ %$state, data_path => '/response/header/Transfer-Encoding' },
341 'RFC9112 §6.1-10: "A server MUST NOT send a Transfer-Encoding header field in any 2xx (Successful) response to a CONNECT request"')
342 8 ▶ if $response->is_success and $options->{method} eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success and $$options{"method"} eq "CONNECT" 2 6 8
Condition100%3/3
$response->is_success and $$options{"method"} eq "CONNECT"
!ll&&!rl&&r
242
MC/DC100%2/2
$response->is_success and $$options{"method"} eq "CONNECT"
$response->is_success $$options{"method"} eq "CONNECT"
Truth table100%3/3
A and B
A= $response->is_successB= $$options{"method"} eq "CONNECT"
ABresult
0X0
100
111
343 }
344  
345 # RFC9112 §6.2-2: "A sender MUST NOT send a Content-Length header field in any message that
346 # contains a Transfer-Encoding header field."
347 81 ▶ ()= E({ %$state, data_path => '/response/header/Content-Length' },
Branch: 1 branch
BranchTrueFalseTotal
if defined $response->headers->content_length and $response->content->is_chunked 2 79 81
Condition100%3/3
defined $response->headers->content_length and $response->content->is_chunked
!ll&&!rl&&r
23562
MC/DC100%2/2
defined $response->headers->content_length and $response->content->is_chunked
defined $response->headers->content_length $response->content->is_chunked
Truth table100%3/3
A and B
A= defined $response->headers->content_lengthB= $response->content->is_chunked
ABresult
0X0
100
111
348 'Content-Length cannot appear together with Transfer-Encoding')
349 if defined $response->headers->content_length and $response->content->is_chunked;
350  
351 # RFC9112 §6.3-7: "A user agent that sends a request that contains a message body MUST send
352 # either a valid Content-Length header field or use the chunked transfer coding."
353 81 ▶ ()= E({ %$state, data_path => '/response/header' }, 'missing header: Content-Length')
Branch: 1 branch
BranchTrueFalseTotal
if $response->body_size and not $response->headers->content_length and not $response->content->is_chunked 5 76 81
Condition100%6/6
$response->body_size and not $response->headers->content_length and not $response->content->is_chunked
!ll&&!rl&&r
7065
$response->body_size and not $response->headers->content_length
!ll&&!rl&&r
254511
MC/DC100%3/3
$response->body_size and not $response->headers->content_length and not $response->content->is_chunked
$response->body_size not $response->headers->content_length not $response->content->is_chunked
Truth table100%4/4
A and not(B) and not(C)
A= $response->body_sizeB= not $response->headers->content_lengthC= not $response->content->is_chunked
ABCresult
0XX0
10X0
1100
1111
354 if $response->body_size and not $response->headers->content_length
355 and not $response->content->is_chunked;
356  
357 81 ▶ if (not $response->code) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->code) 1 80 81
358 1 ()= E($state, 'Failed to parse response: %s', $response->error->{message});
359 1 return $self->_result($state, 0, 1);
360 }
361  
362 206 ▶ my $response_name = first { exists $operation->{responses}{$_} }
Subroutine __ANON__: called CC=1 SCAR=0.0
363 80 $response->code, substr(sprintf('%03s', $response->code), 0, -2).'XX', 'default';
364  
365 80 ▶ if (not $response_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response_name) 2 78 80
366 2 ()= E({ %$state, keyword => 'responses', data_path => $state->{data_path}.'/code' },
367 'no response object found for code %s', $response->code);
368 2 return $self->_result($state, 0, 1);
369 }
370  
371 78 my $response_obj = $operation->{responses}{$response_name};
372 78 $state->{keyword_path} = jsonp($state->{keyword_path}, 'responses', $response_name);
373 78 ▶ while (defined(my $ref = $response_obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$response_obj{"\$ref"})) 34 74 108
374 34 $response_obj = $self->_resolve_ref('response', $ref, $state);
375 }
376  
377 74 ▶ foreach my $header_name (sort keys(($response_obj->{headers}//{})->%*)) {
Condition100%2/2
$$response_obj{"headers"} // {}
l!l
3836
MC/DC100%1/1
$$response_obj{"headers"} // {}
$$response_obj{"headers"}
Truth table100%2/2
A
A= $$response_obj{"headers"}
Aresult
11
00
378 # v3.2.0 §4.17.1: "If a response header is defined with the name "Content-Type", it SHALL be
379 # ignored."
380 60 ▶ next if fc $header_name eq fc 'Content-Type';
Branch: 1 branch
BranchTrueFalseTotal
if fc $header_name eq "content-type" 10 50 60
381  
382 50 my $state = { %$state, keyword_path => jsonp($state->{keyword_path}, 'headers', $header_name) };
383 50 my $header_obj = $response_obj->{headers}{$header_name};
384 50 ▶ while (defined(my $ref = $header_obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$header_obj{"\$ref"})) 6 50 56
385 6 $header_obj = $self->_resolve_ref('header', $ref, $state);
386 }
387  
388 50 my $valid = $self->_validate_parameter({ %$state, depth => $state->{depth}+1,
389 data_path => '/response/header' },
390 $header_obj, name => $header_name, headers => $response->headers);
391 }
392  
393 # FIXME: can we have a 'required' property here, just like in request?
394 # why do we check for the 'content' property here, and Content-Length, but not for request?
395  
396 $self->_validate_body_content({ %$state, data_path => '/response/body', depth => $state->{depth}+1 },
397 $response_obj->{content}, $response)
398 74 ▶ if exists $response_obj->{content} and $response->headers->content_length // $response->body_size;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$response_obj{"content"} and $response->headers->content_length // $response->body_size 58 16 74
Condition83%5/6
exists $$response_obj{"content"} and $response->headers->content_length // $response->body_size
!ll&&!rl&&r
10658
$response->headers->content_length // $response->body_size
l!l&&r!l&&!r
50140
MC/DC33%1/3
exists $$response_obj{"content"} and $response->headers->content_length // $response->body_size
exists $$response_obj{"content"} $response->headers->content_length $response->body_size
Truth table75%3/4
A and B // C
A= exists $$response_obj{"content"}B= $response->headers->content_lengthC= $response->body_size
ABCresult
0XX0
1000
11X1
1011
399 }
400 catch ($e) {
401 6 ▶ if (blessed($e) and $e->isa('JSON::Schema::Modern::Result')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($e) and $e->isa('JSON::Schema::Modern::Result')) { } 0 6 6
elsif (builtin::blessed($e) and $e->isa('JSON::Schema::Modern::Error')) { } 6 0 6
Condition33%1/3
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Result")
!ll&&!rl&&r
060
MC/DC0%0/2
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Result")
builtin::blessed($e) $e->isa("JSON::Schema::Modern::Result")
Truth table33%1/3
A and B
A= builtin::blessed($e)B= $e->isa("JSON::Schema::Modern::Result")
ABresult
0X0
100
111
402 0 $e->recommended_response(undef); # responses don't have responses
403 0 return $e;
404 }
405 ▶ elsif (blessed($e) and $e->isa('JSON::Schema::Modern::Error')) {
Condition33%1/3
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Error")
!ll&&!rl&&r
006
MC/DC0%0/2
builtin::blessed($e) and $e->isa("JSON::Schema::Modern::Error")
builtin::blessed($e) $e->isa("JSON::Schema::Modern::Error")
Truth table33%1/3
A and B
A= builtin::blessed($e)B= $e->isa("JSON::Schema::Modern::Error")
ABresult
0X0
100
111
406 6 push @{$state->{errors}}, $e;
407 }
408 else {
409 0 ()= E({ %$state, exception => 1 }, 'EXCEPTION: '.$e);
410 }
411 }
412  
413 78 return $self->_result($state, 0, 1);
414 }
415  
416 # deprecated, but we'll continue to support it
417 18 *find_path = \&find_path_item;
418  
419 844 ▶sub find_path_item ($self, $options, $state = {}) {
Subroutine find_path_item: called CC=81 SCAR=44.1
Pod documented
420 844 ▶ $state->{data_path} //= '';
Condition100%2/2
$$state{"data_path"} //= ""
l!l
648196
MC/DC100%1/1
$$state{"data_path"} //= ""
$$state{"data_path"}
Truth table100%2/2
A
A= $$state{"data_path"}
Aresult
11
00
421 # the canonical URI as of the start or last $id, or the last traversed $ref
422 844 $state->{initial_schema_uri} = $self->entry_document->canonical_uri;
423 844 $state->{traversed_keyword_path} = ''; # the accumulated traversal path as of the start, or last $id, or up to the last traversed $ref
424 844 $state->{keyword_path} = ''; # the rest of the path, since the last $id or the last traversed $ref
425 844 $state->{document} = $self->entry_document;
426 $state->@{qw(specification_version vocabularies)} =
427 844 $state->{document}->_get_resource($state->{document}->canonical_uri)->@{qw(specification_version vocabularies)};
428 844 $state->{dynamic_scope} = [ $state->{initial_schema_uri} ];
429 844 ▶ $state->{errors} = $options->{errors} //= [];
Condition50%1/2
$$options{"errors"} //= []
l!l
0844
MC/DC0%0/1
$$options{"errors"} //= []
$$options{"errors"}
Truth table50%1/2
A
A= $$options{"errors"}
Aresult
11
00
430 844 ▶ $state->{annotations} //= [];
Condition50%1/2
$$state{"annotations"} //= []
l!l
0844
MC/DC0%0/1
$$state{"annotations"} //= []
$$state{"annotations"}
Truth table50%1/2
A
A= $$state{"annotations"}
Aresult
11
00
431 844 $state->{depth} = 0;
432 844 ▶ $state->{debug} = $options->{debug} = {} if $DEBUG or $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $OpenAPI::Modern::DEBUG or $self->debug 21 823 844
Condition100%3/3
$OpenAPI::Modern::DEBUG or $self->debug
l!l&&r!l&&!r
219823
MC/DC100%2/2
$OpenAPI::Modern::DEBUG or $self->debug
$OpenAPI::Modern::DEBUG $self->debug
Truth table100%3/3
A or B
A= $OpenAPI::Modern::DEBUGB= $self->debug
ABresult
1X1
011
000
433  
434 return E({ %$state, exception => 1, recommended_response => [ 500 ] },
435 'at least one of $options->{request}, ($options->{uri} and $options->{method}), ($options->{path_template} and $options->{method}), or $options->{operation_id} must be provided')
436 if not $options->{request}
437 and not (exists $options->{uri} and exists $options->{method})
438 and not ($options->{path_template} and exists $options->{method})
439 844 ▶ and not exists $options->{operation_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $$options{"request"} or exists $$options{"uri"} and exists $$options{"method"} or $$options{"path_template"} and exists $$options{"method"} or exists $$options{"operation_id"} 4 840 844
Condition93%14/15
$$options{"request"} or exists $$options{"uri"} and exists $$options{"method"} or $$options{"path_template"} and exists $$options{"method"} or exists $$options{"operation_id"}
l!l&&r!l&&!r
786544
$$options{"request"} or exists $$options{"uri"} and exists $$options{"method"} or $$options{"path_template"} and exists $$options{"method"}
l!l&&r!l&&!r
7176958
$$options{"request"} or exists $$options{"uri"} and exists $$options{"method"}
l!l&&r!l&&!r
572145127
exists $$options{"uri"} and exists $$options{"method"}
!ll&&!rl&&r
1270145
$$options{"path_template"} and exists $$options{"method"}
!ll&&!rl&&r
53569
MC/DC83%5/6
$$options{"request"} or exists $$options{"uri"} and exists $$options{"method"} or $$options{"path_template"} and exists $$options{"method"} or exists $$options{"operation_id"}
$$options{"request"} exists $$options{"uri"} exists $$options{"method"} $$options{"path_template"} exists $$options{"method"} exists $$options{"operation_id"}
Truth table58%7/12
A or B and C or D and E or F
A= $$options{"request"}B= exists $$options{"uri"}C= exists $$options{"method"}D= $$options{"path_template"}E= exists $$options{"method"}F= exists $$options{"operation_id"}
ABCDEFresult
1XXXXX1
011XXX1
00X11X1
01011X1
00X0X11
00X1011
0100X11
0101011
00X0X00
00X1000
0100X00
0101000
440  
441 return E({ %$state, exception => 1, recommended_response => [ 500 ] },
442 'provided path_captures values must be strings')
443 if exists $options->{path_captures}
444 36 ▶ and any { $_ ne 'string' and $_ ne 'number' and $_ ne 'integer' }
Condition83%5/6
$_ ne 'string' && $_ ne 'number' && $_ ne 'integer'
!ll&&!rl&&r
11241
$_ ne "string" and $_ ne "number"
!ll&&!rl&&r
11025
MC/DC66%2/3
$_ ne 'string' && $_ ne 'number' && $_ ne 'integer'
$_ ne "string" $_ ne "number" $_ ne 'integer'
Truth table75%3/4
A and B && C
A= $_ ne "string"B= $_ ne "number"C= $_ ne 'integer'
ABCresult
0XX0
10X0
1100
1111
445 840 ▶ map get_type($_), values $options->{path_captures}->%*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$options{"path_captures"} and CORE::any {$_ ne "string" and $_ ne "number" and $_ ne "integer";} map(get_type($_), values %{$$options{"path_captures"}}) 1 839 840
Condition100%3/3
exists $$options{"path_captures"} and CORE::any {$_ ne "string" and $_ ne "number" and $_ ne "integer";} map(get_type($_), values %{$$options{"path_captures"}})
!ll&&!rl&&r
806331
MC/DC100%2/2
exists $$options{"path_captures"} and CORE::any {$_ ne "string" and $_ ne "number" and $_ ne "integer";} map(get_type($_), values %{$$options{"path_captures"}})
exists $$options{"path_captures"} CORE::any {$_ ne "string" and $_ ne "number" and $_ ne "integer";} map(get_type($_), values %{$$options{"path_captures"}})
Truth table100%3/3
A and B
A= exists $$options{"path_captures"}B= CORE::any {$_ ne "string" and $_ ne "number" and $_ ne "integer";} map(get_type($_), values %{$$options{"path_captures"}})
ABresult
0X0
100
111
446  
447 # now guaranteed to be a Mojo::Message::Request
448 839 ▶ if ($options->{request}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$options{'request'}) { } 571 268 839
elsif (exists $$options{'uri'}) { } 145 123 268
449 571 $options->{request} = convert_request($options->{request});
450  
451 # requests don't have response codes, so if 'error' is set, it is some sort of parsing error
452 571 ▶ if (my $error = $options->{request}->error) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $$options{"request"}->error) 8 563 571
453 8 return E({ %$state, data_path => '/request', recommended_response => [ 500 ] }, 'Failed to parse request: %s', $error->{message});
454 }
455  
456 return E({ %$state, data_path => '/request/uri', recommended_response => [ 500 ] },
457 'mismatched uri "%s"', $options->{request}->url)
458 563 ▶ if exists $options->{uri} and $options->{request}->url ne $options->{uri};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$options{"uri"} and $$options{"request"}->url ne $$options{"uri"} 1 562 563
Condition66%2/3
exists $$options{"uri"} and $$options{"request"}->url ne $$options{"uri"}
!ll&&!rl&&r
56201
MC/DC50%1/2
exists $$options{"uri"} and $$options{"request"}->url ne $$options{"uri"}
exists $$options{"uri"} $$options{"request"}->url ne $$options{"uri"}
Truth table66%2/3
A and B
A= exists $$options{"uri"}B= $$options{"request"}->url ne $$options{"uri"}
ABresult
0X0
100
111
459 562 $options->{uri} = $options->{request}->url; # a Mojo::URL object
460  
461 return E({ %$state, data_path => '/request/method', recommended_response => [ 500 ] },
462 'wrong HTTP method "%s"', $options->{request}->method)
463 562 ▶ if exists $options->{method} and $options->{request}->method ne $options->{method};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$options{"method"} and $$options{"request"}->method ne $$options{"method"} 2 560 562
Condition66%2/3
exists $$options{"method"} and $$options{"request"}->method ne $$options{"method"}
!ll&&!rl&&r
56002
MC/DC50%1/2
exists $$options{"method"} and $$options{"request"}->method ne $$options{"method"}
exists $$options{"method"} $$options{"request"}->method ne $$options{"method"}
Truth table66%2/3
A and B
A= exists $$options{"method"}B= $$options{"request"}->method ne $$options{"method"}
ABresult
0X0
100
111
464 560 $options->{method} = $options->{request}->method;
465 }
466 elsif (exists $options->{uri}) {
467 $options->{uri} = Mojo::URL->new($options->{uri}.'')
468 145 ▶ if not blessed($options->{uri}) or not $options->{uri}->isa('Mojo::URL');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($$options{"uri"}) and $$options{"uri"}->isa("Mojo::URL") 143 2 145
Condition66%2/3
builtin::blessed($$options{"uri"}) and $$options{"uri"}->isa("Mojo::URL")
!ll&&!rl&&r
14302
MC/DC50%1/2
builtin::blessed($$options{"uri"}) and $$options{"uri"}->isa("Mojo::URL")
builtin::blessed($$options{"uri"}) $$options{"uri"}->isa("Mojo::URL")
Truth table66%2/3
A and B
A= builtin::blessed($$options{"uri"})B= $$options{"uri"}->isa("Mojo::URL")
ABresult
0X0
100
111
469 }
470  
471 # method from operation_id from options
472 828 ▶ if (exists $options->{operation_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$options{"operation_id"}) 93 735 828
473 # FIXME: what if the operation is defined in another document? Need to look it up across
474 # all documents, and localize $state->{initial_schema_uri}
475 93 my $operation_path = $state->{document}->operationId_path($options->{operation_id});
476 return E({ %$state, recommended_response => [ 500 ] }, 'unknown operation_id "%s"', $options->{operation_id})
477 93 ▶ if not $operation_path;
Branch: 1 branch
BranchTrueFalseTotal
unless $operation_path 4 89 93
478  
479 # The path_template cannot be unambiguously found by looking at the path of the operation:
480 # the operation path may be under /components/pathItems or /webhooks, or the intended /paths
481 # entry might contain a $ref to this location.
482 # We can do a URI -> path_template lookup later on, which will succeed if the operation is
483 # reachable from a /paths entry, but as this can possibly match more than once, in order to
484 # provide an unambiguous result, provide the operation_id as well.
485  
486 # the operation path always ends with the method, but casing may vary depending on the parent
487 89 my @parts = unjsonp($operation_path);
488 my ($path_item_path, $method) = $parts[-2] ne 'additionalOperations'
489 # differentiate between these operation paths:
490 # /components/pathItems/additionalOperations/get (method = 'GET') vs
491 # /components/pathItems/additionalOperations/additionalOperations/get (method = 'get')
492 89 ▶ || $state->{document}->get_entity_at_location(jsonp(@parts[0..$#parts-1])) eq 'path-item'
Branch: 1 branch
BranchTrueFalseTotal
$parts[-2] ne 'additionalOperations' || $$state{'document'}->get_entity_at_location(jsonp(@parts[0 .. $#parts - 1])) eq 'path-item' ? : 81 8 89
Condition100%3/3
$parts[-2] ne "additionalOperations" or $$state{"document"}->get_entity_at_location(jsonp(@parts[0 .. $#parts - 1])) eq "path-item"
l!l&&r!l&&!r
8018
MC/DC100%2/2
$parts[-2] ne "additionalOperations" or $$state{"document"}->get_entity_at_location(jsonp(@parts[0 .. $#parts - 1])) eq "path-item"
$parts[-2] ne "additionalOperations" $$state{"document"}->get_entity_at_location(jsonp(@parts[0 .. $#parts - 1])) eq "path-item"
Truth table100%3/3
A or B
A= $parts[-2] ne "additionalOperations"B= $$state{"document"}->get_entity_at_location(jsonp(@parts[0 .. $#parts - 1])) eq "path-item"
ABresult
1X1
011
000
493 ? (jsonp(@parts[0..$#parts-1]), uc($parts[-1]))
494 : (jsonp(@parts[0..$#parts-2]), $parts[-1]);
495  
496 return E({ %$state, ($options->{uri} ? (data_path => '/request/method') : ()), keyword_path => $operation_path.'/operationId' },
497 'operation at operation_id does not match %s method "%s"%s',
498 $options->{uri} ? 'request' : 'provided HTTP', $options->{method},
499 (!$options->{uri} && $options->{method} eq lc $options->{method}
500 && exists $state->{document}->get($path_item_path)->{$options->{method}}
501 ? (' (should be '.uc $options->{method}.')') : ''))
502 89 ▶ if exists $options->{method} and $options->{method} ne $method;
Branch: 4 branches
BranchTrueFalseTotal
if exists $$options{"method"} and $$options{"method"} ne $method 12 77 89
$$options{'uri'} ? : 4 8 12
$$options{'uri'} ? : 4 8 12
!$$options{'uri'} && $$options{'method'} eq lc $$options{'method'} && exists $$state{'document'}->get($path_item_path)->{$$options{'method'}} ? : 1 11 12
Condition100%9/9
exists $$options{"method"} and $$options{"method"} ne $method
!ll&&!rl&&r
383912
not $$options{"uri"} and $$options{"method"} eq lc $$options{"method"} and exists $$state{"document"}->get($path_item_path)->{$$options{"method"}}
!ll&&!rl&&r
741
not $$options{"uri"} and $$options{"method"} eq lc $$options{"method"}
!ll&&!rl&&r
435
MC/DC100%2/2
exists $$options{"method"} and $$options{"method"} ne $method
exists $$options{"method"} $$options{"method"} ne $method
MC/DC100%3/3
not $$options{"uri"} and $$options{"method"} eq lc $$options{"method"} and exists $$state{"document"}->get($path_item_path)->{$$options{"method"}}
not $$options{"uri"} $$options{"method"} eq lc $$options{"method"} exists $$state{"document"}->get($path_item_path)->{$$options{"method"}}
Truth table100%3/3
A and B
A= exists $$options{"method"}B= $$options{"method"} ne $method
ABresult
0X0
100
111
Truth table100%4/4
not(A) and B and C
A= not $$options{"uri"}B= $$options{"method"} eq lc $$options{"method"}C= exists $$state{"document"}->get($path_item_path)->{$$options{"method"}}
ABCresult
0XX0
10X0
1100
1111
503  
504 77 $options->{method} = $method;
505  
506 77 ▶ if (not $options->{path_template} and not $options->{uri}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$options{"path_template"} or $$options{"uri"}) 39 38 77
Condition100%3/3
$$options{"path_template"} or $$options{"uri"}
l!l&&r!l&&!r
162239
MC/DC100%2/2
$$options{"path_template"} or $$options{"uri"}
$$options{"path_template"} $$options{"uri"}
Truth table100%3/3
A or B
A= $$options{"path_template"}B= $$options{"uri"}
ABresult
1X1
011
000
507 # some operations don't live under a /paths/$path_template (even via a $ref), e.g. webhooks or
508 # callbacks, but they are still usable via operationId for validating responses
509 39 $state->{keyword_path} = $path_item_path;
510 39 $options->{_path_item} = $state->{document}->get($path_item_path);
511 39 $options->{_operation} = $state->{document}->get($operation_path);
512 39 $options->{_operation_path_suffix} = substr($operation_path, length($path_item_path));
513  
514 # FIXME: this is not accurate if the operation lives in another document
515 # (and in that case, get_operation_uri_by_id can be returned as-is)
516 39 $options->{operation_uri} = $state->{initial_schema_uri}->clone->fragment($operation_path);
517 39 return 1;
518 }
519 }
520  
521 # path_template from options
522 return E({ %$state, ($options->{uri} ? (data_path => '/request/uri') : ()),
523 keyword => 'paths' }, 'missing path "%s"', $options->{path_template})
524 if exists $options->{path_template}
525 773 ▶ and not exists(($state->{document}->schema->{paths}//{})->{$options->{path_template}});
Branch: 2 branches
BranchTrueFalseTotal
if exists $$options{"path_template"} and not exists(($$state{"document"}->schema->{"paths"} // {})->{$$options{"path_template"}}) 4 769 773
$$options{'uri'} ? : 2 2 4
Condition100%5/5
exists $$options{"path_template"} and not exists(($$state{"document"}->schema->{"paths"} // {})->{$$options{"path_template"}})
!ll&&!rl&&r
6561134
$$state{"document"}->schema->{"paths"} // {}
l!l
1161
MC/DC100%2/2
exists $$options{"path_template"} and not exists(($$state{"document"}->schema->{"paths"} // {})->{$$options{"path_template"}})
exists $$options{"path_template"} $$state{"document"}->schema->{"paths"}
Truth table100%3/3
A and not(B)
A= exists $$options{"path_template"}B= $$state{"document"}->schema->{"paths"}
ABresult
0X0
110
101
526  
527 # hashrefs of template variable names -> concrete values from the uri
528 769 my ($server_captures, $path_captures);
529  
530 769 ▶ if (not $options->{path_template} and $options->{uri}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $$options{'path_template'} and $$options{'uri'}) { } 656 113 769
elsif ($$options{'uri'}) { } 42 71 113
Condition66%2/3
not $$options{"path_template"} and $$options{"uri"}
!ll&&!rl&&r
1130656
MC/DC50%1/2
not $$options{"path_template"} and $$options{"uri"}
not $$options{"path_template"} $$options{"uri"}
Truth table66%2/3
not(A) and B
A= not $$options{"path_template"}B= $$options{"uri"}
ABresult
0X0
100
111
531 # derive path_template and capture values from the request URI
532  
533 656 my $errors = $state->{errors}; # most likely [], but bound to $options
534 656 foreach my $pt ($state->{document}->path_templates->@*) {
535 1041 my $local_state = +{ %$state, errors => [] }; # we do not keep errors from match attempts
536 1041 $local_state->{path_item} = $state->{document}->schema->{paths}{$pt};
537 1041 $local_state->{keyword_path} = jsonp('/paths', $pt);
538 1041 ($server_captures, $path_captures) = $self->_match_uri($options->@{qw(method uri)}, $pt, $local_state);
539  
540 1041 ▶ if ($path_captures) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path_captures) 642 399 1041
541 # a URI can match multiple /paths entries, and an operationId can be reachable from multiple
542 # /paths entries, so keep searching until both are a match
543 next if exists $options->{operation_id}
544 and (not exists $local_state->{operation}{operationId}
545 642 ▶ or $local_state->{operation}{operationId} ne $options->{operation_id});
Branch: 1 branch
BranchTrueFalseTotal
if exists $$options{"operation_id"} and !exists($$local_state{"operation"}{"operationId"}) || $$local_state{"operation"}{"operationId"} ne $$options{"operation_id"} 17 625 642
Condition100%6/6
exists $$options{"operation_id"} and !exists($$local_state{"operation"}{"operationId"}) || $$local_state{"operation"}{"operationId"} ne $$options{"operation_id"}
!ll&&!rl&&r
6151017
not exists $$local_state{"operation"}{"operationId"} or $$local_state{"operation"}{"operationId"} ne $$options{"operation_id"}
l!l&&r!l&&!r
8910
MC/DC100%3/3
exists $$options{"operation_id"} and !exists($$local_state{"operation"}{"operationId"}) || $$local_state{"operation"}{"operationId"} ne $$options{"operation_id"}
exists $$options{"operation_id"} not exists $$local_state{"operation"}{"operationId"} $$local_state{"operation"}{"operationId"} ne $$options{"operation_id"}
Truth table100%4/4
A and not(B) or C
A= exists $$options{"operation_id"}B= not exists $$local_state{"operation"}{"operationId"}C= $$local_state{"operation"}{"operationId"} ne $$options{"operation_id"}
ABCresult
0XX0
1000
11X1
1011
546  
547 # preserve location of the match
548 625 %$state = (%$local_state, errors => $errors);
549 625 $options->{path_template} = $pt;
550 625 last;
551 }
552 }
553  
554 return E({ %$state, data_path => '/request', keyword => 'paths' },
555 'no match found for request %s %s',
556 $options->{method}, $options->{uri}->clone->query('')->fragment(undef))
557 656 ▶ if not exists $options->{path_template};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$options{"path_template"} 31 625 656
558 }
559  
560 elsif ($options->{uri}) {
561 # we were passed path_template in options, and now we verify it against the request URI
562 42 $state->{path_item} = $state->{document}->schema->{paths}{$options->{path_template}};
563 42 $state->{keyword_path} = jsonp('/paths', $options->{path_template});
564 42 ($server_captures, $path_captures) = $self->_match_uri($options->@{qw(method uri path_template)}, $state);
565  
566 42 ▶ if (not $path_captures) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path_captures) 18 24 42
567 # no path-item and operation found that matches the request's method and uri
568 18 delete $options->{operation_id};
569  
570 # the initial match succeeded, but something else went wrong
571 18 ▶ if ($state->{errors}->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$$state{"errors"}}) 7 11 18
572 7 $options->@{qw(_path_item _operation _operation_path_suffix)} = $state->@{qw(path_item operation operation_path_suffix)};
573 7 return;
574 }
575  
576 return E({ %$state, data_path => '/request/uri', recommended_response => [ 500 ] },
577 'provided path_template does not match request URI "%s"',
578 11 $options->{uri}->clone->query('')->fragment(undef));
579 }
580  
581 24 ▶ if (exists $options->{operation_id}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$options{"operation_id"} and !exists($$state{"operation"}{"operationId"}) || $$state{"operation"}{"operationId"} ne $$options{"operation_id"}) 8 16 24
Condition100%6/6
exists $$options{"operation_id"} and !exists($$state{"operation"}{"operationId"}) || $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
!ll&&!rl&&r
1338
not exists $$state{"operation"}{"operationId"} or $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
l!l&&r!l&&!r
353
MC/DC100%3/3
exists $$options{"operation_id"} and !exists($$state{"operation"}{"operationId"}) || $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
exists $$options{"operation_id"} not exists $$state{"operation"}{"operationId"} $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
Truth table100%4/4
A and not(B) or C
A= exists $$options{"operation_id"}B= not exists $$state{"operation"}{"operationId"}C= $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
ABCresult
0XX0
1000
11X1
1011
582 and (not exists $state->{operation}{operationId}
583 or $state->{operation}{operationId} ne $options->{operation_id})) {
584 8 delete $options->@{qw(_path_item _operation _operation_path_suffix path_captures uri_captures operation_uri)};
585 return E({ %$state, keyword_path => $state->{keyword_path}.$state->{operation_path_suffix}
586 .(exists $state->{operation}{operationId} ? '/operationId' : ''),
587 recommended_response => [ 500 ] },
588 'provided path_template and operation_id do not match request %s %s',
589 8 ▶ $options->{method}, $options->{uri}->clone->query('')->fragment(undef));
Branch: 1 branch
BranchTrueFalseTotal
exists $$state{'operation'}{'operationId'} ? : 5 3 8
590 }
591 }
592  
593 else {
594 # we were provided $options->{path_template}, and we have already confirmed that it exists.
595 71 $state->{path_item} = $state->{document}->schema->{paths}{$options->{path_template}};
596 71 $state->{keyword_path} = jsonp('/paths', $options->{path_template});
597 71 ▶ while (defined(my $ref = $state->{path_item}{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$state{"path_item"}{"\$ref"})) 3 71 74
598 3 $state->{path_item} = $self->_resolve_ref('path-item', $ref, $state);
599 }
600  
601 $state->@{qw(operation operation_path_suffix)} =
602 elem($options->{method}, [qw(GET PUT POST DELETE OPTIONS HEAD PATCH TRACE QUERY)])
603 ? ($state->{path_item}{lc $options->{method}}, '/'.lc $options->{method})
604 71 ▶ : (($state->{path_item}{additionalOperations}//{})->{$options->{method}}, jsonp('/additionalOperations', $options->{method}));
Branch: 1 branch
BranchTrueFalseTotal
elem($$options{'method'}, ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE', 'QUERY']) ? : 67 4 71
Condition50%1/2
$$state{"path_item"}{"additionalOperations"} // {}
l!l
40
MC/DC0%0/1
$$state{"path_item"}{"additionalOperations"} // {}
$$state{"path_item"}{"additionalOperations"}
Truth table50%1/2
A
A= $$state{"path_item"}{"additionalOperations"}
Aresult
11
00
605  
606 return E({ %$state, recommended_response => [ 405 ] },
607 'missing operation for HTTP method "%s" under "%s"%s', $options->@{qw(method path_template)},
608 exists $options->{method} && $options->{method} eq lc $options->{method}
609 && exists $state->{path_item}{$options->{method}} ? (' (should be '.uc $options->{method}.')') : '')
610 71 ▶ if not $state->{operation};
Branch: 2 branches
BranchTrueFalseTotal
unless $$state{"operation"} 5 66 71
exists $$options{'method'} && $$options{'method'} eq lc $$options{'method'} && exists $$state{'path_item'}{$$options{'method'}} ? : 1 4 5
Condition66%4/6
exists $$options{"method"} and $$options{"method"} eq lc $$options{"method"} and exists $$state{"path_item"}{$$options{"method"}}
!ll&&!rl&&r
401
exists $$options{"method"} and $$options{"method"} eq lc $$options{"method"}
!ll&&!rl&&r
041
MC/DC33%1/3
exists $$options{"method"} and $$options{"method"} eq lc $$options{"method"} and exists $$state{"path_item"}{$$options{"method"}}
exists $$options{"method"} $$options{"method"} eq lc $$options{"method"} exists $$state{"path_item"}{$$options{"method"}}
Truth table50%2/4
A and B and C
A= exists $$options{"method"}B= $$options{"method"} eq lc $$options{"method"}C= exists $$state{"path_item"}{$$options{"method"}}
ABCresult
0XX0
10X0
1100
1111
611  
612 return E({ %$state, keyword_path => $state->{keyword_path}.$state->{operation_path_suffix}
613 .(exists $state->{operation}{operationId} ? '/operationId' : ''),
614 recommended_response => [ 500 ] },
615 'templated operation does not match provided operation_id')
616 if exists $options->{operation_id}
617 and (not exists $state->{operation}{operationId}
618 66 ▶ or $state->{operation}{operationId} ne $options->{operation_id});
Branch: 2 branches
BranchTrueFalseTotal
if exists $$options{"operation_id"} and !exists($$state{"operation"}{"operationId"}) || $$state{"operation"}{"operationId"} ne $$options{"operation_id"} 3 63 66
exists $$state{'operation'}{'operationId'} ? : 1 2 3
Condition66%4/6
exists $$options{"operation_id"} and !exists($$state{"operation"}{"operationId"}) || $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
!ll&&!rl&&r
6303
not exists $$state{"operation"}{"operationId"} or $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
l!l&&r!l&&!r
210
MC/DC33%1/3
exists $$options{"operation_id"} and !exists($$state{"operation"}{"operationId"}) || $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
exists $$options{"operation_id"} not exists $$state{"operation"}{"operationId"} $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
Truth table75%3/4
A and not(B) or C
A= exists $$options{"operation_id"}B= not exists $$state{"operation"}{"operationId"}C= $$state{"operation"}{"operationId"} ne $$options{"operation_id"}
ABCresult
0XX0
1000
11X1
1011
619 }
620  
621 704 $options->@{qw(_path_item _operation _operation_path_suffix)} = $state->@{qw(path_item operation operation_path_suffix)};
622  
623 # if initial_schema_uri still points to the head of the entry document, then we have not followed
624 # a $ref and the path-item is located at /paths/<path_template>
625 $options->{operation_uri} = $state->{initial_schema_uri}->clone
626 704 ▶ ->fragment(($state->{initial_schema_uri}->fragment // $state->{keyword_path}).$options->{_operation_path_suffix});
Condition66%2/3
$$state{"initial_schema_uri"}->fragment // $$state{"keyword_path"}
l!l&&r!l&&!r
396650
MC/DC0%0/2
$$state{"initial_schema_uri"}->fragment // $$state{"keyword_path"}
$$state{"initial_schema_uri"}->fragment $$state{"keyword_path"}
Truth table66%2/3
A // B
A= $$state{"initial_schema_uri"}->fragmentB= $$state{"keyword_path"}
ABresult
1X1
011
000
627  
628 $options->{operation_id} = $options->{_operation}{operationId}
629 704 ▶ if exists $options->{_operation}{operationId};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$options{"_operation"}{"operationId"} 47 657 704
630  
631 704 my @path_capture_names = ($options->{path_template} =~ /\{([^{}]+)\}/g);
632 return E({ %$state, $options->{uri} ? (data_path => '/request/uri') : (), recommended_response => [ 500 ] }, 'provided path_captures names do not match path template "%s"', $options->{path_template})
633 if exists $options->{path_captures}
634 704 ▶ and not is_equal([ sort keys $options->{path_captures}->%* ], [ sort @path_capture_names ]);
Branch: 2 branches
BranchTrueFalseTotal
if exists $$options{"path_captures"} and not is_equal([sort(keys %{$$options{"path_captures"}})], [sort(@path_capture_names)]) 8 696 704
$$options{'uri'} ? : 7 1 8
Condition100%3/3
exists $$options{"path_captures"} and not is_equal([sort(keys %{$$options{"path_captures"}})], [sort(@path_capture_names)])
!ll&&!rl&&r
674228
MC/DC100%2/2
exists $$options{"path_captures"} and not is_equal([sort(keys %{$$options{"path_captures"}})], [sort(@path_capture_names)])
exists $$options{"path_captures"} not is_equal([sort(keys %{$$options{"path_captures"}})], [sort(@path_capture_names)])
Truth table100%3/3
A and not(B)
A= exists $$options{"path_captures"}B= not is_equal([sort(keys %{$$options{"path_captures"}})], [sort(@path_capture_names)])
ABresult
0X0
100
111
635  
636 696 ▶ return 1 if not $path_captures;
Branch: 1 branch
BranchTrueFalseTotal
unless $path_captures 62 634 696
637  
638 634 my @uri_capture_names = uniq keys %$server_captures, keys %$path_captures;
639  
640 634 ▶ if (exists $options->{uri_captures}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$options{'uri_captures'}) { } 4 630 634
641 return E({ %$state, $options->{uri} ? (data_path => '/request/uri') : (), recommended_response => [ 500 ] },
642 'provided uri_captures names do not match extracted values')
643 4 ▶ if not is_equal([ sort keys $options->{uri_captures}->%* ], [ sort @uri_capture_names ]);
Branch: 2 branches
BranchTrueFalseTotal
unless is_equal([sort(keys %{$$options{"uri_captures"}})], [sort(@uri_capture_names)]) 1 3 4
$$options{'uri'} ? : 1 0 1
644  
645 # $equal_state will contain { path => '/0' } indicating the index of the mismatch
646 3 ▶ if (not is_equal([ $options->{uri_captures}->@{@uri_capture_names} ], [ { %$path_captures, %$server_captures }->@{@uri_capture_names} ], my $equal_state = { stringy_numbers => 1 })) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_equal([@$$options{"uri_captures"}{@uri_capture_names}], [@{%$path_captures, %$server_captures}{@uri_capture_names}], my $equal_state = {"stringy_numbers", 1})) 1 2 3
647 return E({ %$state, data_path => '/request/uri', recommended_response => [ 500 ] },
648 1 'provided uri_captures values do not match request URI (value for %s differs)', $uri_capture_names[substr($equal_state->{path}, 1)]);
649 }
650 }
651 else {
652 # server capture values are fully decoded and do not need further deserialization, so we will
653 # always provide that value here in the case of name reuse; use path_captures if the encoded
654 # form is needed
655 630 $options->{uri_captures} = { %$path_captures, %$server_captures };
656 }
657  
658 632 ▶ if (exists $options->{path_captures}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$options{'path_captures'}) { } 21 611 632
659 # $equal_state will contain { path => '/0' } indicating the index of the mismatch
660 21 ▶ if (not is_equal([ $options->{path_captures}->@{@path_capture_names} ], [ $path_captures->@{@path_capture_names} ], my $equal_state = { stringy_numbers => 1 })) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_equal([@$$options{"path_captures"}{@path_capture_names}], [@$path_captures{@path_capture_names}], my $equal_state = {"stringy_numbers", 1})) 3 18 21
661 return E({ %$state, data_path => '/request/uri', recommended_response => [ 500 ] },
662 3 'provided path_captures values do not match request URI (value for %s differs)', $path_capture_names[substr($equal_state->{path}, 1)]);
663 }
664 }
665 else {
666 611 $options->{path_captures} = $path_captures;
667 }
668  
669 629 return 1;
670 }
671  
672 # TODO: this should (also?) be available at JSON::Schema::Modern
673 9 ▶sub recursive_get ($self, $uri_reference, $entity_type = undef) {
Subroutine recursive_get: called CC=18 SCAR=29.0
Pod documented
674 9 my $base = $self->entry_document->canonical_uri;
675 9 my $ref = $uri_reference;
676 9 my ($depth, $schema);
677 9 my $parent_obj = {};
678  
679 9 ▶ while ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 33 5 38
680 33 ▶ croak 'maximum evaluation depth exceeded' if $depth++ > $self->evaluator->max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $depth++ > $self->evaluator->max_depth 1 32 33
681 32 my $uri = Mojo::URL->new($ref)->to_abs($base);
682  
683 32 my $schema_info = $self->evaluator->_fetch_from_uri($uri);
684  
685 32 ▶ croak 'unable to find resource "', $uri, '"' if not $schema_info;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema_info 1 31 32
686 31 my $this_entity = $schema_info->{document}->get_entity_at_location($schema_info->{document_path});
687 31 ▶ croak sprintf('bad $ref to %s: not a%s "%s"', $schema_info->{canonical_uri}, ($entity_type =~ /^[aeiou]/ ? 'n' : ''), $entity_type)
Branch: 2 branches
BranchTrueFalseTotal
if $entity_type and $this_entity ne $entity_type 2 29 31
$entity_type =~ /^[aeiou]/u ? : 1 1 2
Condition100%3/3
$entity_type and $this_entity ne $entity_type
!ll&&!rl&&r
8212
MC/DC100%2/2
$entity_type and $this_entity ne $entity_type
$entity_type $this_entity ne $entity_type
Truth table100%3/3
A and B
A= $entity_typeB= $this_entity ne $entity_type
ABresult
0X0
100
111
688 if $entity_type and $this_entity ne $entity_type;
689  
690 29 ▶ $entity_type //= $this_entity;
Condition66%2/3
$entity_type //= $this_entity
l!l&&r!l&&!r
2180
MC/DC0%0/2
$entity_type //= $this_entity
$entity_type $this_entity
Truth table66%2/3
A //= B
A= $entity_typeB= $this_entity
ABresult
1X1
011
000
691 29 $schema = $schema_info->{schema};
692 29 $base = $schema_info->{canonical_uri};
693 29 ▶ if (defined($ref = $schema->{'$ref'}) and not elem($this_entity, [qw(schema callbacks)])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($ref = $$schema{"\$ref"}) and not elem($this_entity, ["schema", "callbacks"])) 22 7 29
Condition100%3/3
defined($ref = $$schema{"\$ref"}) and not elem($this_entity, ["schema", "callbacks"])
!ll&&!rl&&r
5222
MC/DC100%2/2
defined($ref = $$schema{"\$ref"}) and not elem($this_entity, ["schema", "callbacks"])
defined($ref = $$schema{"\$ref"}) not elem($this_entity, ["schema", "callbacks"])
Truth table100%3/3
A and not(B)
A= defined($ref = $$schema{"\$ref"})B= not elem($this_entity, ["schema", "callbacks"])
ABresult
0X0
100
111
694 # OAS reference object or path-item object: copy summary, description
695 $parent_obj->{summary} = $schema->{summary}
696 if elem($this_entity, [qw(response example path-item)])
697 22 ▶ and exists $schema->{summary} and not exists $parent_obj->{summary};
Branch: 1 branch
BranchTrueFalseTotal
if elem($this_entity, ["response", "example", "path-item"]) and exists $$schema{"summary"} and not exists $$parent_obj{"summary"} 1 21 22
Condition66%4/6
elem($this_entity, ["response", "example", "path-item"]) and exists $$schema{"summary"} and not exists $$parent_obj{"summary"}
!ll&&!rl&&r
2101
elem($this_entity, ["response", "example", "path-item"]) and exists $$schema{"summary"}
!ll&&!rl&&r
2101
MC/DC33%1/3
elem($this_entity, ["response", "example", "path-item"]) and exists $$schema{"summary"} and not exists $$parent_obj{"summary"}
elem($this_entity, ["response", "example", "path-item"]) exists $$schema{"summary"} not exists $$parent_obj{"summary"}
Truth table50%2/4
A and B and not(C)
A= elem($this_entity, ["response", "example", "path-item"])B= exists $$schema{"summary"}C= not exists $$parent_obj{"summary"}
ABCresult
0XX0
10X0
1100
1111
698 $parent_obj->{description} = $schema->{description}
699 22 ▶ if exists $schema->{description} and not exists $parent_obj->{description};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"description"} and not exists $$parent_obj{"description"} 1 21 22
Condition100%3/3
exists $$schema{"description"} and not exists $$parent_obj{"description"}
!ll&&!rl&&r
7141
MC/DC100%2/2
exists $$schema{"description"} and not exists $$parent_obj{"description"}
exists $$schema{"description"} not exists $$parent_obj{"description"}
Truth table100%3/3
A and not(B)
A= exists $$schema{"description"}B= not exists $$parent_obj{"description"}
ABresult
0X0
100
111
700 }
701 }
702  
703 5 $schema = clone($schema);
704 5 $schema->{$_} = $parent_obj->{$_} foreach keys %$parent_obj;
705  
706 5 ▶ return wantarray ? ($schema, $base) : $schema;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 0 5
707 }
708  
709 ######## NO PUBLIC INTERFACES FOLLOW THIS POINT ########
710  
711 # given a request's method and uri, and a path_template, check that these match (taking into
712 # consideration additional information in the current path-item), and extract capture values.
713 # returns false on error, possibly adding errors to $state.
714 1083 ▶sub _match_uri ($self, $method, $uri, $path_template, $state) {
Subroutine _match_uri: called CC=31 SCAR=34.3
715 1083 $uri = $uri->clone->fragment(undef)->query('');
716  
717 # v3.2.0 §4.8.2, "Path Templating": "The value for these path parameters MUST NOT contain any
718 # unescaped “generic syntax” characters described by RFC3986 Section 3: forward slashes (/),
719 # question marks (?), or hashes (#)."
720 # If the path template equals '/' then we should ALWAYS match, and propagate to server url matching
721 1083 ▶ my $path_pattern = $path_template eq '/' ? ''
Branch: 2 branches
BranchTrueFalseTotal
$path_template eq '/' ? : 16 1067 1083
substr($_, 0, 1) eq '{' ? : 304 1137 1441
722 : join '', map +(substr($_, 0, 1) eq '{' ? '([^/?#]*)' : quotemeta($_)),
723 split /(\{[^{}]+\})/, $path_template;
724  
725 # if the uri doesn't match against the path alone, we can immediately bail (and keep looking for
726 # another /paths entry that might match)... this also saves us needless parsing of server objects
727 18 ▶ do { use autovivification 'store'; push $state->{debug}{uri_patterns}->@*, $path_pattern.'\z' }
Subroutine BEGIN: called CC=1 SCAR=0.0
728 1083 ▶ if exists $state->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$state{"debug"}) 24 1059 1083
729 1083 ▶ return if $uri !~ m/$path_pattern\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri =~ /$path_pattern\z/u 385 698 1083
730  
731 # identify the unmatched part of the request URI, to be later matched against server urls
732 698 ▶ my $uri_prefix = $path_template eq '/' ? $uri : substr($uri, 0, -length($&));
Branch: 1 branch
BranchTrueFalseTotal
$path_template eq '/' ? : 16 682 698
733  
734 # extract all capture values from path template variables: ($1 .. $n)
735 # perldoc perlvar, @-: $n coincides with "substr $_, $-[n], $+[n] - $-[n]" if "$-[n]" is defined
736 # We do not url-decode here, because we may need to parse the string for style delimiters first
737 698 my @path_capture_values = map substr($uri, $-[$_], $+[$_]-$-[$_]), 1 .. $#-;
738  
739 # we set aside $state for potential restoration because we might still encounter issues later on
740 # that require us to keep iterating for another URI match, and we use the original $state for
741 # the global servers object
742 698 my $local_state = +{ %$state };
743  
744 698 ▶ while (defined(my $ref = $local_state->{path_item}{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$local_state{"path_item"}{"\$ref"})) 59 698 757
745 59 $local_state->{path_item} = $self->_resolve_ref('path-item', $ref, $local_state);
746 }
747  
748 # v3.2.0 §4.8.1, "Patterned Fields": "In case of ambiguous matching, it’s up to the tooling to
749 # decide which one to use."
750 # There could be another paths entry that matches this URI that does have this method
751 # implemented, so we return false and keep searching. Since we may still match to the wrong URI,
752 # the correct operation can be forced to match by explicitly passing the corresponding
753 # path_template or (preferably) operationId to be used in the search.
754  
755 $local_state->@{qw(operation operation_path_suffix)} =
756 elem($method, [qw(GET PUT POST DELETE OPTIONS HEAD PATCH TRACE QUERY)])
757 ? ($local_state->{path_item}{lc $method}, '/'.lc $method)
758 698 ▶ : (($local_state->{path_item}{additionalOperations}//{})->{$method}, jsonp('/additionalOperations', $method));
Branch: 1 branch
BranchTrueFalseTotal
elem($method, ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE', 'QUERY']) ? : 692 6 698
Condition100%2/2
$$local_state{"path_item"}{"additionalOperations"} // {}
l!l
51
MC/DC100%1/1
$$local_state{"path_item"}{"additionalOperations"} // {}
$$local_state{"path_item"}{"additionalOperations"}
Truth table100%2/2
A
A= $$local_state{"path_item"}{"additionalOperations"}
Aresult
11
00
759  
760 698 ▶ return if not $local_state->{operation};
Branch: 1 branch
BranchTrueFalseTotal
unless $$local_state{"operation"} 11 687 698
761  
762 687 my $server_state = +{ %$local_state }; # for errors pertaining to the server object
763  
764 # we need to keep track of the traversed path to the servers object, as well as its absolute
765 # location, for usage in error objects
766 687 my $servers;
767 687 ▶ if (exists $local_state->{operation}{servers}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $$local_state{'operation'}{'servers'}) { } 29 658 687
elsif (exists $$local_state{'path_item'}{'servers'}) { } 11 647 658
768 29 $servers = $local_state->{operation}{servers};
769 29 $server_state->{keyword_path} .= $server_state->{operation_path_suffix}.'/servers';
770 }
771 elsif (exists $local_state->{path_item}{servers}) {
772 11 $servers = $local_state->{path_item}{servers};
773 11 $server_state->{keyword_path} .= '/servers';
774 }
775 else {
776 # v3.2.1 §4.1.1: "If the servers field is not provided ..., the default value
777 # would be an array consisting of a single Server Object with a url value of `/`."
778 647 ▶ $servers = $state->{document}->schema->{servers} // [{ url => '/' }];
Condition100%2/2
$$state{"document"}->schema->{"servers"} // [{"url", "/"}]
l!l
22625
MC/DC100%1/1
$$state{"document"}->schema->{"servers"} // [{"url", "/"}]
$$state{"document"}->schema->{"servers"}
Truth table100%2/2
A
A= $$state{"document"}->schema->{"servers"}
Aresult
11
00
779  
780 # The global server object comes from the document containing the original
781 # /paths/<path_template> (via $state), not the document containing the resulting path-item and
782 # operation (via $local_state)
783 647 $server_state = +{ %$state };
784 647 $server_state->{initial_schema_uri} = $state->{document}->canonical_uri;
785 647 $server_state->{traversed_keyword_path} = '';
786 647 ▶ $server_state->{keyword_path} = exists $state->{document}->schema->{servers} ? '/servers' : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $$state{'document'}->schema->{'servers'} ? : 22 625 647
787 }
788  
789 # v3.2.1 §4.1.1: "If the servers field is ... an empty array, the default value
790 # would be an array consisting of a single Server Object with a url value of `/`."
791 687 ▶ $servers = [{ url => '/' }] if not @$servers;
Branch: 1 branch
BranchTrueFalseTotal
unless @$servers 7 680 687
792  
793 687 my @path_capture_names = ($path_template =~ /\{([^{}]+)\}/g);
794  
795 687 foreach my $index_and_server (pairs indexed @$servers) {
796 732 my ($server_index, $server) = @$index_and_server;
797  
798 # v3.2.1 §4.5.1: "This [server] URL ... MAY be relative, to indicate that the host location is
799 # relative to the location where the document containing the Server Object is being served."
800 # We need a full uri to match against the full uri taken from the request (with scheme and
801 # host). If it is unknown, or relative, then we further resolve against the request's scheme,
802 # host and port, otherwise the match can never succeed.
803 # But before we apply URI logic to the server url, we must first protect any templated sections
804 # so they are not altered by normalization. We use NUL, as it is unchanged in the host during
805 # punycode-encoding
806 my $normalized_server_url = Mojo::URL->new($server->{url} =~ s/\{[^{}]+\}/\x00/gr)
807 732 ▶ ->to_abs($server_state->{document}->retrieval_uri//())
Condition66%2/3
$$server_state{"document"}->retrieval_uri // ()
l!l&&r!l&&!r
73020
MC/DC0%0/2
$$server_state{"document"}->retrieval_uri // ()
$$server_state{"document"}->retrieval_uri ()
Truth table66%2/3
A // B
A= $$server_state{"document"}->retrieval_uriB= ()
ABresult
1X1
011
000
808 ->to_abs($uri);
809  
810 732 my $normalized_host = $normalized_server_url->host;
811  
812 # note: this stringifies the uri.
813 # we don't call $uri->path->leading_slash(0) because it normalizes escaped characters like /
814 732 ▶ $normalized_server_url =~ s{/\z}{} if $normalized_server_url->path eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $normalized_server_url->path eq "/" 635 97 732
815  
816 732 ▶ my $server_pattern = join '',
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '%00' ? : 39 752 791
817 map +($_ eq '%00' ? '([^/?#]*)' : quotemeta($_)),
818 split /(%00)/, $normalized_server_url; # all NULs appear as %00 in the stringified form
819 18 ▶ do { use autovivification 'store'; push $state->{debug}{uri_patterns}->@*, '^'.$server_pattern }
Subroutine BEGIN: called CC=1 SCAR=0.0
820 732 ▶ if exists $state->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$state{"debug"}) 24 708 732
821  
822 732 ▶ next if $uri_prefix !~ m/^$server_pattern\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri_prefix =~ /^$server_pattern\z/u 53 679 732
823  
824 # extract all capture values from server variables: ($1 .. $n)...
825 # perldoc perlvar, @-: $n coincides with "substr $_, $-[n], $+[n] - $-[n]" if "$-[n]" is defined
826 679 my @server_capture_values = map substr($uri_prefix, $-[$_], $+[$_]-$-[$_]), 1 .. $#-;
827  
828 # ...and punycode-decode those from the host, and url-unescape those from the path
829 679 ▶ my $host_variable_count = ()= ($normalized_host//'') =~ /\x00/g;
Condition100%2/2
$normalized_host // ""
l!l
6754
MC/DC100%1/1
$normalized_host // ""
$normalized_host
Truth table100%2/2
A
A= $normalized_host
Aresult
11
00
830 679 ▶ @server_capture_values = (
Branch: 1 branch
BranchTrueFalseTotal
/^xn--(.+)\z/u ? : 4 20 24
831 (map +(/^xn--(.+)\z/ ? punycode_decode($1) : $_), @server_capture_values[0 .. $host_variable_count-1]),
832 (map uri_decode($_), @server_capture_values[$host_variable_count .. $#server_capture_values]));
833  
834 # we have a match, so preserve our new $state values created via _resolve_ref (but do not change
835 # values being used specifically for the "server" location)
836 679 %$state = %$local_state;
837  
838 679 my @server_capture_names = ($server->{url} =~ /\{([^{}]+)\}/g);
839  
840 679 ▶ next if any {
Branch: 1 branch
BranchTrueFalseTotal
if CORE::any {my $server_capture_name = $server_capture_names[$_]; my($index) = grep(($path_capture_names[$_] eq $server_capture_name), 0 .. $#path_capture_names); defined $index and uri_decode($path_capture_values[$index]) ne $server_capture_values[$_];} 0 .. $#server_capture_names 5 674 679
841 37 my $server_capture_name = $server_capture_names[$_];
842 37 my ($index) = grep $path_capture_names[$_] eq $server_capture_name, 0..$#path_capture_names;
843 37 ▶ defined $index && uri_decode($path_capture_values[$index]) ne $server_capture_values[$_];
Condition100%3/3
defined $index && uri_decode($path_capture_values[$index]) ne $server_capture_values[$_]
!ll&&!rl&&r
3025
MC/DC100%2/2
defined $index && uri_decode($path_capture_values[$index]) ne $server_capture_values[$_]
defined $index uri_decode($path_capture_values[$index]) ne $server_capture_values[$_]
Truth table100%3/3
A && B
A= defined $indexB= uri_decode($path_capture_values[$index]) ne $server_capture_values[$_]
ABresult
0X0
100
111
844 } 0..$#server_capture_names;
845  
846 674 my $valid = 1;
847 674 foreach my $name_index (0..$#server_capture_names) {
848 32 my $name = $server_capture_names[$name_index];
849 32 ▶ next if not exists((($server->{variables}//{})->{$name}//{})->{enum});
Branch: 1 branch
BranchTrueFalseTotal
unless exists((($$server{"variables"} // {})->{$name} // {})->{"enum"}) 9 23 32
Condition50%2/4
($$server{"variables"} // {})->{$name} // {}
l!l
320
$$server{"variables"} // {}
l!l
320
MC/DC0%0/1
($$server{"variables"} // {})->{$name} // {}
$$server{"variables"}
Truth table50%1/2
A
A= $$server{"variables"}
Aresult
11
00
850  
851 $valid = E({ %$server_state, data_path => '/request/uri', keyword => 'enum',
852 keyword_path => jsonp($server_state->{keyword_path}, $server_index, 'variables', $name) },
853 'server url value does not match any of the allowed values')
854 23 ▶ if not elem($server_capture_values[$name_index], $server->{variables}{$name}{enum});
Branch: 1 branch
BranchTrueFalseTotal
unless elem($server_capture_values[$name_index], $$server{"variables"}{$name}{"enum"}) 8 15 23
855 }
856  
857 674 ▶ next if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 8 666 674
858  
859 666 my (%server_captures, %path_captures);
860 666 @server_captures{@server_capture_names} = @server_capture_values;
861 666 @path_captures{@path_capture_names} = @path_capture_values;
862  
863 666 return \%server_captures, \%path_captures;
864 }
865  
866 # no match against any servers urls
867 21 return;
868 }
869  
870 # $param_obj can be a parameter object or a header object
871 # %args can contain any of:
872 # - when $param_obj->{in} is 'path': 'path_captures', a hashref
873 # - when $param_obj->{in} is 'query' or 'querystring': 'params', a Mojo::Parameters object
874 # - when $param_obj->{in} is 'header' or 'cookie': 'headers', a Mojo::Headers object
875 # - when $param_obj->{in} is missing (i.e a header object): 'name', the parameter name
876 1523 ▶sub _validate_parameter ($self, $state, $param_obj, %args) {
Subroutine _validate_parameter: called CC=26 SCAR=32.6
877 1523 ▶ my $in = $param_obj->{in} // 'header'; # header objects do not have an 'in' property
Condition100%2/2
$$param_obj{"in"} // "header"
l!l
1369154
MC/DC100%1/1
$$param_obj{"in"} // "header"
$$param_obj{"in"}
Truth table100%2/2
A
A= $$param_obj{"in"}
Aresult
11
00
878 1523 ▶ my $name = $param_obj->{name} // $args{name}; # ..or a 'name' property
Condition66%2/3
$$param_obj{"name"} // $args{"name"}
l!l&&r!l&&!r
13691540
MC/DC0%0/2
$$param_obj{"name"} // $args{"name"}
$$param_obj{"name"} $args{"name"}
Truth table66%2/3
A // B
A= $$param_obj{"name"}B= $args{"name"}
ABresult
1X1
011
000
879  
880 1523 my ($path_captures, $params, $headers) = @args{qw(path_captures params headers)};
881 1523 my $error_count = $state->{errors}->@*;
882  
883 return E({ %$state, data_path => jsonp($state->{data_path}, $name), keyword => 'content' },
884 'multipart content is not permitted outside request and response bodies')
885 if exists $param_obj->{content}
886 1523 ▶ and match_media_type((keys $param_obj->{content}->%*)[0], ['multipart/*']);
Branch: 1 branch
BranchTrueFalseTotal
if exists $$param_obj{"content"} and match_media_type((keys %{$$param_obj{"content"}})[0], ["multipart/*"]) 8 1515 1523
Condition100%3/3
exists $$param_obj{"content"} and match_media_type((keys %{$$param_obj{"content"}})[0], ["multipart/*"])
!ll&&!rl&&r
11963198
MC/DC100%2/2
exists $$param_obj{"content"} and match_media_type((keys %{$$param_obj{"content"}})[0], ["multipart/*"])
exists $$param_obj{"content"} match_media_type((keys %{$$param_obj{"content"}})[0], ["multipart/*"])
Truth table100%3/3
A and B
A= exists $$param_obj{"content"}B= match_media_type((keys %{$$param_obj{"content"}})[0], ["multipart/*"])
ABresult
0X0
100
111
887  
888 # when $data_ref is false, value is missing; otherwise it is a reference to the deserialized data
889 1515 ▶ my $data_ref =
Branch: 5 branches
BranchTrueFalseTotal
$in eq 'path' ? : 348 1167 1515
$in eq 'query' ? : 457 710 1167
$in eq 'header' ? : 441 269 710
$in eq 'cookie' ? : 222 47 269
$in eq 'querystring' ? : 47 0 47
890 $in eq 'path' ? $self->_deserialize_path_parameter({ %$state }, $param_obj, $path_captures)
891 : $in eq 'query' ? $self->_deserialize_query_parameter({ %$state }, $param_obj, $params)
892 : $in eq 'header' ? $self->_deserialize_header_parameter({ %$state }, $param_obj, $name, $headers)
893 : $in eq 'cookie' ? $self->_deserialize_cookie_parameter({ %$state }, $param_obj, $headers)
894 : $in eq 'querystring' ? $self->_deserialize_querystring_parameter({ %$state }, $param_obj, $params)
895 : die;
896  
897 1505 ▶ return if $state->{errors}->@* > $error_count;
Branch: 1 branch
BranchTrueFalseTotal
if @{$$state{"errors"}} > $error_count 156 1349 1505
898  
899 1349 my $obj = $param_obj; # $obj can be a parameter, header or media-type object; contains 'schema'
900  
901 1349 ▶ if (exists $obj->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$obj{"content"}) 290 1059 1349
902 290 my ($media_type) = keys $obj->{content}->%*;
903 290 $obj = $obj->{content}{$media_type};
904 290 $state->{keyword_path} = jsonp($state->{keyword_path}, 'content', $media_type);
905 290 ▶ while (defined(my $ref = $obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$obj{"\$ref"})) 52 290 342
906 52 $obj = $self->_resolve_ref('media-type', $ref, $state);
907 }
908 }
909  
910 1349 ▶ $state->{data_path} = jsonp($state->{data_path}, $name) if $in ne 'querystring';
Branch: 1 branch
BranchTrueFalseTotal
if $in ne "querystring" 1306 43 1349
911  
912 1349 ▶ if (not $data_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data_ref) 351 998 1349
913 # value is missing, but not required - populate defaults
914 $state->{defaults}{$state->{data_path}} =
915 ref $obj->{schema}{default} ? clone($obj->{schema}{default}) : $obj->{schema}{default}
916 if $state->{defaults} and exists $obj->{schema}
917 351 ▶ and ref $obj->{schema} eq 'HASH' and exists $obj->{schema}{default};
Branch: 2 branches
BranchTrueFalseTotal
if $$state{"defaults"} and exists $$obj{"schema"} and ref $$obj{"schema"} eq "HASH" and exists $$obj{"schema"}{"default"} 36 315 351
ref $$obj{'schema'}{'default'} ? : 36 0 36
Condition88%8/9
$$state{"defaults"} and exists $$obj{"schema"} and ref $$obj{"schema"} eq "HASH" and exists $$obj{"schema"}{"default"}
!ll&&!rl&&r
315036
$$state{"defaults"} and exists $$obj{"schema"} and ref $$obj{"schema"} eq "HASH"
!ll&&!rl&&r
2892636
$$state{"defaults"} and exists $$obj{"schema"}
!ll&&!rl&&r
2771262
MC/DC75%3/4
$$state{"defaults"} and exists $$obj{"schema"} and ref $$obj{"schema"} eq "HASH" and exists $$obj{"schema"}{"default"}
$$state{"defaults"} exists $$obj{"schema"} ref $$obj{"schema"} eq "HASH" exists $$obj{"schema"}{"default"}
Truth table80%4/5
A and B and C and D
A= $$state{"defaults"}B= exists $$obj{"schema"}C= ref $$obj{"schema"} eq "HASH"D= exists $$obj{"schema"}{"default"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
918  
919 351 return 1;
920 }
921  
922 998 jsonp_set($state->{data}, $state->{data_path}, $data_ref->$*);
923  
924 998 my $valid = 1;
925  
926 $valid = 0 if exists $obj->{schema} and not $self->_evaluate_subschema($data_ref, $obj->{schema},
927 998 ▶ { %$state, depth => $state->{depth}+1, keyword_path => $state->{keyword_path}.'/schema' });
Branch: 1 branch
BranchTrueFalseTotal
if exists $$obj{"schema"} and not $self->_evaluate_subschema($data_ref, $$obj{"schema"}, {%$state, "depth", $$state{"depth"} + 1, "keyword_path", $$state{"keyword_path"} . '/schema'}) 134 864 998
Condition100%3/3
exists $$obj{"schema"} and not $self->_evaluate_subschema($data_ref, $$obj{"schema"}, {%$state, "depth", $$state{"depth"} + 1, "keyword_path", $$state{"keyword_path"} . '/schema'})
!ll&&!rl&&r
31833134
MC/DC100%2/2
exists $$obj{"schema"} and not $self->_evaluate_subschema($data_ref, $$obj{"schema"}, {%$state, "depth", $$state{"depth"} + 1, "keyword_path", $$state{"keyword_path"} . '/schema'})
exists $$obj{"schema"} not $self->_evaluate_subschema($data_ref, $$obj{"schema"}, {%$state, "depth", $$state{"depth"} + 1, "keyword_path", $$state{"keyword_path"} . '/schema'})
Truth table100%3/3
A and not(B)
A= exists $$obj{"schema"}B= not $self->_evaluate_subschema($data_ref, $$obj{"schema"}, {%$state, "depth", $$state{"depth"} + 1, "keyword_path", $$state{"keyword_path"} . '/schema'})
ABresult
0X0
100
111
928  
929 998 ▶ if (exists $obj->{itemSchema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$obj{"itemSchema"}) 16 982 998
930 16 ▶ return E({ %$state, keyword_path => $state->{keyword_path}.'/itemSchema' },
Branch: 1 branch
BranchTrueFalseTotal
if ref $$data_ref ne "ARRAY" 2 14 16
931 'deserialized %s parameter content is not an array', $in)
932 if ref $data_ref->$* ne 'ARRAY';
933  
934 14 foreach my $idx (0..$data_ref->$*->$#*) {
935 $valid = 0 if not $self->_evaluate_subschema(\ $data_ref->$*->[$idx], $obj->{itemSchema},
936 { %$state, depth => $state->{depth}+1, data_path => $state->{data_path}.'/'.$idx,
937 16 ▶ keyword_path => $state->{keyword_path}.'/itemSchema' });
Branch: 1 branch
BranchTrueFalseTotal
unless 12 4 16
938 }
939 }
940  
941 996 return $valid;
942 }
943  
944 # returns false or reference to deserialized data
945 348 ▶sub _deserialize_path_parameter ($self, $state, $param_obj, $path_captures) {
Subroutine _deserialize_path_parameter: called CC=7 SCAR=19.5
946 # 'required' is always true for path parameters
947 # v3.2.0 §4.12.2.1: "If "in" is "path", the name field MUST correspond to a single template
948 # expression occurring within the path field in the Paths Object."
949 return E({ %$state, keyword => 'required' }, 'missing path parameter: %s', $param_obj->{name})
950 348 ▶ if not exists $path_captures->{$param_obj->{name}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$path_captures{$$param_obj{"name"}} 4 344 348
951  
952 344 my $data = $path_captures->{$param_obj->{name}};
953  
954 # path parameters are always percent-encoded
955 344 ▶ return E({ %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}) },
Branch: 1 branch
BranchTrueFalseTotal
if ($data // "") =~ /[^\x00-\x7F]/u 2 342 344
Condition50%1/2
$data // ""
l!l
3440
MC/DC0%0/1
$data // ""
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
956 'non-ascii character detected in parameter value: not deserializable')
957 if ($data//'') =~ /[^\x00-\x7F]/;
958  
959 return $self->_deserialize_content(\ uri_decode($data),
960 { %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}) },
961 $param_obj->{content}, ((keys $param_obj->{content}->%*)[0])x2)
962 342 ▶ if exists $param_obj->{content};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$param_obj{"content"} 51 291 342
963  
964 return $self->_deserialize_style($data,
965 { %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}) },
966 style => $param_obj->{style}//'simple',
967 explode => $param_obj->{explode}//false,
968 291 ▶ $param_obj->%{qw(in name schema)},
Condition100%4/4
$$param_obj{"style"} // "simple"
l!l
19398
$$param_obj{"explode"} // bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
l!l
145146
MC/DC100%1/1
$$param_obj{"style"} // "simple"
$$param_obj{"style"}
MC/DC100%1/1
$$param_obj{"explode"} // bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
$$param_obj{"explode"}
Truth table100%2/2
A
A= $$param_obj{"style"}
Aresult
11
00
Truth table100%2/2
A
A= $$param_obj{"explode"}
Aresult
11
00
969 );
970 }
971  
972 # returns false or reference to deserialized data
973 457 ▶sub _deserialize_query_parameter ($self, $state, $param_obj, $params) {
Subroutine _deserialize_query_parameter: called CC=19 SCAR=29.5
974 457 ▶ croak '$params must be a Mojo::Parameters object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($params) and $params->isa("Mojo::Parameters") 0 457 457
Condition33%1/3
builtin::blessed($params) and $params->isa("Mojo::Parameters")
!ll&&!rl&&r
00457
MC/DC0%0/2
builtin::blessed($params) and $params->isa("Mojo::Parameters")
builtin::blessed($params) $params->isa("Mojo::Parameters")
Truth table33%1/3
A and B
A= builtin::blessed($params)B= $params->isa("Mojo::Parameters")
ABresult
0X0
100
111
975 if not blessed($params) or not $params->isa('Mojo::Parameters');
976  
977 457 ▶ if (exists $param_obj->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$param_obj{"content"}) 112 345 457
978 112 my $data = $params->param($param_obj->{name});
979 112 ▶ if (not defined $data or ($param_obj->{allowEmptyValue} and not length $data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data or $$param_obj{"allowEmptyValue"} and not length $data) 64 48 112
Condition83%5/6
not defined $data or $$param_obj{"allowEmptyValue"} and not length $data
l!l&&r!l&&!r
62248
$$param_obj{"allowEmptyValue"} and not length $data
!ll&&!rl&&r
4802
MC/DC66%2/3
not defined $data or $$param_obj{"allowEmptyValue"} and not length $data
not defined $data $$param_obj{"allowEmptyValue"} not length $data
Truth table75%3/4
not(A) or B and not(C)
A= not defined $dataB= $$param_obj{"allowEmptyValue"}C= not length $data
ABCresult
1XX1
0111
00X0
0100
980 return E({ %$state, keyword => 'required' }, 'missing query parameter: %s', $param_obj->{name})
981 64 ▶ if $param_obj->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $$param_obj{"required"} 2 62 64
982 62 return;
983 }
984  
985 return $self->_deserialize_content(\$data,
986 { %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}) },
987 48 $param_obj->{content}, ((keys $param_obj->{content}->%*)[0])x2);
988 }
989  
990 # Note that since we already percent-decoded all extracted query components via $params->parse
991 # (called by param, every_param and pairs), we do not do so again here. If the user wishes to
992 # embed delimiter characters (',' or '&') within the value and not have them confused with the
993 # chosen style decoding, they must be escaped first and decoded by the application.
994  
995 345 ▶ my $style = $param_obj->{style}//'form';
Condition100%2/2
$$param_obj{"style"} // "form"
l!l
184161
MC/DC100%1/1
$$param_obj{"style"} // "form"
$$param_obj{"style"}
Truth table100%2/2
A
A= $$param_obj{"style"}
Aresult
11
00
996 345 ▶ my $explode = $param_obj->{explode} // ($style eq 'form' ? true : false);
Branch: 1 branch
BranchTrueFalseTotal
$style eq 'form' ? : 135 104 239
Condition100%2/2
$$param_obj{"explode"} // ($style eq "form" ? bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ) : bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ))
l!l
106239
MC/DC100%1/1
$$param_obj{"explode"} // ($style eq "form" ? bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ) : bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ))
$$param_obj{"explode"}
Truth table100%2/2
A
A= $$param_obj{"explode"}
Aresult
11
00
997  
998 345 my $error_count = $state->{errors}->@*;
999 my $data_ref = $self->_deserialize_style($params,
1000 { %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}) },
1001 style => $style,
1002 explode => $explode,
1003 allowEmptyValue => $param_obj->{allowEmptyValue}//false,
1004 345 ▶ $param_obj->%{qw(in name schema)},
Condition100%2/2
$$param_obj{"allowEmptyValue"} // bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
l!l
36309
MC/DC100%1/1
$$param_obj{"allowEmptyValue"} // bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
$$param_obj{"allowEmptyValue"}
Truth table100%2/2
A
A= $$param_obj{"allowEmptyValue"}
Aresult
11
00
1005 );
1006  
1007 344 ▶ return if $state->{errors}->@* > $error_count;
Branch: 1 branch
BranchTrueFalseTotal
if @{$$state{"errors"}} > $error_count 23 321 344
1008  
1009 321 ▶ if (not $data_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data_ref) 89 232 321
1010 89 ▶ if ($param_obj->{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$param_obj{"required"}) 24 65 89
1011 my @types = $self->_type_in_schema($param_obj->{schema},
1012 24 { %$state, keyword_path => $state->{keyword_path}.'/schema' });
1013 return E({ %$state, keyword => 'required' },
1014 $style eq 'form' && $explode && @types != 6 && elem('object', \@types)
1015 ? 'missing query parameters'
1016 24 ▶ : ('missing query parameter: %s', $param_obj->{name}));
Branch: 1 branch
BranchTrueFalseTotal
$style eq 'form' && $explode && @types != 6 && elem('object', \@types) ? : 3 21 24
Condition100%9/9
$style eq "form" and $explode and @types != 6 and elem("object", \@types)
!ll&&!rl&&r
1743
$style eq "form" and $explode and @types != 6
!ll&&!rl&&r
1527
$style eq "form" and $explode
!ll&&!rl&&r
969
MC/DC100%4/4
$style eq "form" and $explode and @types != 6 and elem("object", \@types)
$style eq "form" $explode @types != 6 elem("object", \@types)
Truth table100%5/5
A and B and C and D
A= $style eq "form"B= $explodeC= @types != 6D= elem("object", \@types)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1017 }
1018  
1019 65 return;
1020 }
1021  
1022 232 return $data_ref;
1023 }
1024  
1025 # validates a header, from either the request or the response
1026 # $header_obj can be a parameter object or a header object ('in' and 'name' might be absent)
1027 # returns false or reference to deserialized data
1028 441 ▶sub _deserialize_header_parameter ($self, $state, $header_obj, $header_name, $headers) {
Subroutine _deserialize_header_parameter: called CC=10 SCAR=23.3
1029 441 ▶ croak '$headers must be a Mojo::Headers object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($headers) and $headers->isa("Mojo::Headers") 0 441 441
Condition33%1/3
builtin::blessed($headers) and $headers->isa("Mojo::Headers")
!ll&&!rl&&r
00441
MC/DC0%0/2
builtin::blessed($headers) and $headers->isa("Mojo::Headers")
builtin::blessed($headers) $headers->isa("Mojo::Headers")
Truth table33%1/3
A and B
A= builtin::blessed($headers)B= $headers->isa("Mojo::Headers")
ABresult
0X0
100
111
1030 if not blessed($headers) or not $headers->isa('Mojo::Headers');
1031  
1032 # temporary, until the ABNF is enforced in the OAD schema
1033 441 ▶ return E($state, 'invalid character detected in header name')
Branch: 1 branch
BranchTrueFalseTotal
unless is_header_name($header_name) 0 441 441
1034 if not is_header_name($header_name);
1035  
1036 441 ▶ if (not $headers->every_header($header_name)->@*) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$headers->every_header($header_name)}) 191 250 441
1037 return E({ %$state, keyword => 'required' }, 'missing header: %s', $header_name)
1038 191 ▶ if $header_obj->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $$header_obj{"required"} 25 166 191
1039 166 return;
1040 }
1041  
1042 # RFC9110 §5.5:
1043 # field-value = *field-content
1044 # field-content = field-vchar [ 1*( SP / HTAB / field-vchar ) field-vchar ]
1045 # field-vchar = VCHAR / obs-text
1046 # obs-text = %x80-FF
1047 return E({ %$state, data_path => jsonp($state->{data_path}, $header_name) },
1048 'invalid syntax in header value')
1049 250 ▶ if any { !/^(?:[\x21-\x7E\x80-\xFF](?:[\x09\x20-\x7E\x80-\xFF]+[\x21-\x7E\x80-\xFF])?)*\z/ }
Branch: 1 branch
BranchTrueFalseTotal
if CORE::any {not /^(?:[\x21-\x7E\x80-\xFF](?:[\x09\x20-\x7E\x80-\xFF]+[\x21-\x7E\x80-\xFF])?)*\z/u;} @{$headers->every_header($header_name)} 2 248 250
1050 $headers->every_header($header_name)->@*;
1051  
1052 # validate as a single comma-concatenated string, presumably to be decoded
1053 return $self->_deserialize_content(\ $headers->header($header_name),
1054 { %$state, data_path => jsonp($state->{data_path}, $header_name) },
1055 $header_obj->{content}, ((keys $header_obj->{content}->%*)[0])x2)
1056 248 ▶ if exists $header_obj->{content};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$header_obj{"content"} 36 212 248
1057  
1058 # RFC9112 §5.1-3: "The field line value does not include that leading or trailing whitespace: OWS
1059 # occurring before the first non-whitespace octet of the field line value, or after the last
1060 # non-whitespace octet of the field line value, is excluded by parsers when extracting the field
1061 # line value from a field line."
1062  
1063 # RFC9110 §5.3-1: "A recipient MAY combine multiple field lines within a field section that have
1064 # the same field name into one field line, without changing the semantics of the message, by
1065 # appending each subsequent field line value to the initial field line value in order, separated
1066 # by a comma (",") and optional whitespace (OWS, defined in Section 5.6.3). For consistency, use
1067 # comma SP."
1068  
1069 # In order to deserialize from a single string using the "simple" style, we concatenate all header
1070 # lines together, after removing leading and trailing whitespace and then pct-encoding the result
1071 # (as it is decoded again after splitting on delimiters). OWS after commas are parsed out later.
1072  
1073 return $self->_deserialize_style(
1074 # , and = delimiters are not percent-encoded
1075 Mojo::Util::url_escape(join(',', $headers->every_header($header_name)->@*),
1076 '^A-Za-z0-9\-._~:/?#[\]@!$&\'()*+,;='), # unreserved and reserved
1077 { %$state, data_path => jsonp($state->{data_path}, $header_name) },
1078 in => 'header',
1079 style => $header_obj->{style}//'simple',
1080 explode => $header_obj->{explode}//false,
1081 name => $header_name,
1082 schema => $header_obj->{schema},
1083 212 ▶ strip_internal_ws => 1,
Condition100%4/4
$$header_obj{"style"} // "simple"
l!l
40172
$$header_obj{"explode"} // bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
l!l
50162
MC/DC100%1/1
$$header_obj{"style"} // "simple"
$$header_obj{"style"}
MC/DC100%1/1
$$header_obj{"explode"} // bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
$$header_obj{"explode"}
Truth table100%2/2
A
A= $$header_obj{"style"}
Aresult
11
00
Truth table100%2/2
A
A= $$header_obj{"explode"}
Aresult
11
00
1084 );
1085 }
1086  
1087 # returns false or reference to deserialized data
1088 222 ▶sub _deserialize_cookie_parameter ($self, $state, $param_obj, $headers) {
Subroutine _deserialize_cookie_parameter: called CC=36 SCAR=35.9
1089 222 ▶ croak '$headers must be a Mojo::Headers object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($headers) and $headers->isa("Mojo::Headers") 0 222 222
Condition33%1/3
builtin::blessed($headers) and $headers->isa("Mojo::Headers")
!ll&&!rl&&r
00222
MC/DC0%0/2
builtin::blessed($headers) and $headers->isa("Mojo::Headers")
builtin::blessed($headers) $headers->isa("Mojo::Headers")
Truth table33%1/3
A and B
A= builtin::blessed($headers)B= $headers->isa("Mojo::Headers")
ABresult
0X0
100
111
1090 if not blessed($headers) or not $headers->isa('Mojo::Headers');
1091  
1092 222 my $cookie = $headers->every_header('Cookie');
1093  
1094 222 ▶ if (not @$cookie) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$cookie) 38 184 222
1095 38 ▶ return E({ %$state, keyword => 'required' }, 'missing header: Cookie') if $param_obj->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $$param_obj{"required"} 3 35 38
1096 35 return;
1097 }
1098  
1099 184 ▶ return E($state, 'RFC6265 §5.4: "When the user agent generates an HTTP request, the user agent MUST NOT attach more than one Cookie header field."') if @$cookie > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$cookie > 1 0 184 184
1100  
1101 184 my $error_count = $state->{errors}->@*;
1102  
1103 # parse into individual cookie parameters as per RFC6265 (see ABNF in OpenAPI::Modern::Utilities)
1104 184 my $data = $cookie->[0];
1105 184 my @pairs = map [ split /=/, $_, 2 ], split /; /, $data;
1106  
1107 184 ▶ if (my @missing_values = grep !defined $_->[1], @pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing_values) = grep((!defined($our $_[1])), @pairs)) 4 180 184
1108 ()= E({ %$state, data_path => jsonp($state->{data_path}, $_->[0]) },
1109 4 'cookie-string "%s" is missing a value', $_->[0] =~ s/"/\\"/gr) foreach @missing_values;
1110 }
1111  
1112 184 ▶ if (my @bad_names = grep !is_cookie_name($_), map $_->[0], @pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@bad_names) = grep((!is_cookie_name($_)), map($our $_[0], @pairs))) 3 181 184
1113 ()= E({ %$state, data_path => jsonp($state->{data_path}, $_) },
1114 3 'invalid cookie name: "%s"', s/"/\\"/gr) foreach @bad_names;
1115 }
1116  
1117 184 ▶ if (my @bad_values = grep defined $_->[1] && !is_cookie_value($_->[1]), @pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@bad_values) = grep((defined $our $_[1] && !is_cookie_value($our $_[1])), @pairs)) 5 179 184
Condition100%3/3
defined $our $_[1] && !is_cookie_value($our $_[1])
!ll&&!rl&&r
62737
MC/DC100%2/2
defined $our $_[1] && !is_cookie_value($our $_[1])
defined $our $_[1] !is_cookie_value($our $_[1])
Truth table100%3/3
A && not(B)
A= defined $our $_[1]B= !is_cookie_value($our $_[1])
ABresult
0X0
100
111
1118 ()= E({ %$state, data_path => jsonp($state->{data_path}, $_->[0]) },
1119 5 'invalid cookie value: "%s"', $_->[1] =~ s/"/\\"/gr) foreach @bad_values;
1120 }
1121  
1122 184 ▶ return if $state->{errors}->@* > $error_count;
Branch: 1 branch
BranchTrueFalseTotal
if @{$$state{"errors"}} > $error_count 12 172 184
1123  
1124 172 map do { $_->[1] =~ s/^"//; $_->[1] =~ s/"\z// }, @pairs;
1125  
1126 172 ▶ if (exists $param_obj->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$param_obj{"content"}) 22 150 172
1127 22 ▶ my $data = ((grep +($_->[0] eq $param_obj->{name}), @pairs)[-1]//[])->[1];
Condition100%2/2
(grep(($our $_[0] eq $$param_obj{"name"}), @pairs))[-1] // []
l!l
202
MC/DC100%1/1
(grep(($our $_[0] eq $$param_obj{"name"}), @pairs))[-1] // []
(grep(($our $_[0] eq $$param_obj{"name"}), @pairs))[-1]
Truth table100%2/2
A
A= (grep(($our $_[0] eq $$param_obj{"name"}), @pairs))[-1]
Aresult
11
00
1128  
1129 22 ▶ if (not defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 2 20 22
1130 return E({ %$state, keyword => 'required' }, 'missing cookie parameter: %s', $param_obj->{name})
1131 2 ▶ if $param_obj->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $$param_obj{"required"} 1 1 2
1132 1 return;
1133 }
1134  
1135 return $self->_deserialize_content(\$data,
1136 { %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}) },
1137 20 $param_obj->{content}, ((keys $param_obj->{content}->%*)[0])x2);
1138 }
1139  
1140 150 ▶ my $style = $param_obj->{style}//'form';
Condition100%2/2
$$param_obj{"style"} // "form"
l!l
10941
MC/DC100%1/1
$$param_obj{"style"} // "form"
$$param_obj{"style"}
Truth table100%2/2
A
A= $$param_obj{"style"}
Aresult
11
00
1141 150 ▶ my $explode = $param_obj->{explode}//true;
Condition100%2/2
$$param_obj{"explode"} // bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
l!l
46104
MC/DC100%1/1
$$param_obj{"explode"} // bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
$$param_obj{"explode"}
Truth table100%2/2
A
A= $$param_obj{"explode"}
Aresult
11
00
1142  
1143 150 ▶ if ($style eq 'form') {
Branch: 1 branch
BranchTrueFalseTotal
if ($style eq "form") 95 55 150
1144 my @types = $self->_type_in_schema($param_obj->{schema},
1145 { %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}),
1146 95 keyword_path => $state->{keyword_path}.'/schema' });
1147  
1148 94 ▶ if ($explode and @types != 6 and elem('object', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explode and @types != 6 and elem('object', \@types)) { } 19 75 94
Condition100%6/6
$explode and @types != 6 and elem("object", \@types)
!ll&&!rl&&r
66919
$explode and @types != 6
!ll&&!rl&&r
4288
MC/DC100%3/3
$explode and @types != 6 and elem("object", \@types)
$explode @types != 6 elem("object", \@types)
Truth table100%4/4
A and B and C
A= $explodeB= @types != 6C= elem("object", \@types)
ABCresult
0XX0
10X0
1100
1111
1149 19 ▶ if (@pairs > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs > 1) 1 18 19
1150 1 return E({ %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}),
1151 keyword => 'style' },
1152 'cannot deserialize into an object with style=form, explode=true when multiple cookies are present');
1153 }
1154  
1155 # deserialize this entire cookie string as form-style-encoded
1156 18 ▶ $data = Mojo::Parameters->new(@pairs ? join('=', $pairs[0]->@*) : ());
Branch: 1 branch
BranchTrueFalseTotal
@pairs ? : 15 3 18
1157 }
1158 else {
1159 # find the matching cookie parameter and parse it as form-style-encoded
1160 # we construct the object as a string, not as pairs, so any embedded '&' and '=' do not become
1161 # encoded
1162 75 my @data = grep +(uri_decode($_->[0]) eq $param_obj->{name}), @pairs;
1163 75 ▶ $data = Mojo::Parameters->new(@data ? uri_encode_strict($param_obj->{name}).'='.($data[-1]->[1]//'') : ());
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 60 15 75
Condition50%1/2
$data[-1][1] // ""
l!l
600
MC/DC0%0/1
$data[-1][1] // ""
$data[-1][1]
Truth table50%1/2
A
A= $data[-1][1]
Aresult
11
00
1164 }
1165 }
1166  
1167 # for style=cookie, we send the entire header string to be parsed
1168  
1169 148 ▶ die if $error_count != $state->{errors}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $error_count != @{$$state{"errors"}} 0 148 148
1170 my $data_ref = $self->_deserialize_style($data,
1171 { %$state, data_path => jsonp($state->{data_path}, $param_obj->{name}) },
1172 style => $style,
1173 explode => $explode,
1174 148 $param_obj->%{qw(in name schema)},
1175 );
1176  
1177 148 ▶ return if $state->{errors}->@* > $error_count;
Branch: 1 branch
BranchTrueFalseTotal
if @{$$state{"errors"}} > $error_count 2 146 148
1178  
1179 146 ▶ if (not $data_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data_ref) 21 125 146
1180 21 ▶ if ($param_obj->{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$param_obj{"required"}) 8 13 21
1181 my @types = $self->_type_in_schema($param_obj->{schema},
1182 8 { %$state, keyword_path => $state->{keyword_path}.'/schema' });
1183 return E({ %$state, keyword => 'required' },
1184 $style eq 'form' && $explode && @types != 6 && elem('object', \@types)
1185 ? 'missing cookie parameters'
1186 8 ▶ : ('missing cookie parameter: %s', $param_obj->{name}));
Branch: 1 branch
BranchTrueFalseTotal
$style eq 'form' && $explode && @types != 6 && elem('object', \@types) ? : 2 6 8
Condition88%8/9
$style eq "form" and $explode and @types != 6 and elem("object", \@types)
!ll&&!rl&&r
332
$style eq "form" and $explode and @types != 6
!ll&&!rl&&r
305
$style eq "form" and $explode
!ll&&!rl&&r
125
MC/DC75%3/4
$style eq "form" and $explode and @types != 6 and elem("object", \@types)
$style eq "form" $explode @types != 6 elem("object", \@types)
Truth table80%4/5
A and B and C and D
A= $style eq "form"B= $explodeC= @types != 6D= elem("object", \@types)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1187 }
1188 }
1189  
1190 138 return $data_ref;
1191 }
1192  
1193 # returns false or reference to deserialized data
1194 47 ▶sub _deserialize_querystring_parameter ($self, $state, $param_obj, $params) {
Subroutine _deserialize_querystring_parameter: called CC=8 SCAR=21.1
1195 47 ▶ die '$params must be a Mojo::Parameters object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($params) and $params->isa("Mojo::Parameters") 0 47 47
Condition33%1/3
builtin::blessed($params) and $params->isa("Mojo::Parameters")
!ll&&!rl&&r
0047
MC/DC0%0/2
builtin::blessed($params) and $params->isa("Mojo::Parameters")
builtin::blessed($params) $params->isa("Mojo::Parameters")
Truth table33%1/3
A and B
A= builtin::blessed($params)B= $params->isa("Mojo::Parameters")
ABresult
0X0
100
111
1196 if not blessed($params) or not $params->isa('Mojo::Parameters');
1197  
1198 # note: if something has caused the Mojo::Parameters object to be normalized (e.g. calling
1199 # 'pairs'), the raw string value is lost -- we could try stringifying it again, but if the
1200 # data is incompatible with application/x-www-form-urlencoded, we may not be able to recover
1201 # all the intended data.
1202  
1203 47 ▶ if (not exists $params->{string}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$params{"string"}) 13 34 47
1204 # $params->clone (done above) will create empty pairs if {string} is missing
1205 carp 'request uri querystring has been lost: see L<OpenAPI::Modern/LIMITATIONS> for how to avoid'
1206 13 ▶ if exists $params->{pairs} and $params->{pairs}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$params{"pairs"} and @{$$params{"pairs"}} 1 12 13
Condition100%3/3
exists $$params{"pairs"} and @{$$params{"pairs"}}
!ll&&!rl&&r
2101
MC/DC100%2/2
exists $$params{"pairs"} and @{$$params{"pairs"}}
exists $$params{"pairs"} @{$$params{"pairs"}}
Truth table100%3/3
A and B
A= exists $$params{"pairs"}B= @{$$params{"pairs"}}
ABresult
0X0
100
111
1207  
1208 13 ▶ return E({ %$state, keyword => 'required' }, 'missing querystring') if $param_obj->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $$param_obj{"required"} 4 9 13
1209 9 return;
1210 }
1211  
1212 34 my $data = $params->{string};
1213  
1214 # query parameters are always percent-encoded
1215 34 ▶ return E($state, 'non-ascii character detected in parameter value: not deserializable')
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /[^\x00-\x7F]/u 0 34 34
1216 if $data =~ /[^\x00-\x7F]/;
1217  
1218 # Replace "+" with whitespace, unescape and decode as in Mojo::Parameters::pairs
1219 # We do not UTF-8-decode the content: this is the responsibility of the media-type decoder.
1220 34 $data = url_unescape($data =~ s/\+/ /gr);
1221  
1222 return $self->_deserialize_content(\$data, $state,
1223 34 $param_obj->{content}, ((keys $param_obj->{content}->%*)[0])x2);
1224 }
1225  
1226 # Data comes in as a string, or for some styles as a Mojo::Parameters object.
1227 # When parsing fails, $state->{errors} is populated and false is returned;
1228 # otherwise, the return value is a reference to the fully deserialized data, parsed into the correct
1229 # type(s) (which may be undef = null), or undef if no data was extracted
1230 # %opt is (:$in, :$style, :$explode, :$allowEmptyValue, :$name, :$schema, $strip_internal_ws)
1231 1052 ▶sub _deserialize_style ($self, $data, $state, %opt) {
Subroutine _deserialize_style: called CC=134 SCAR=49.5
1232 # numbers and builtin bools can be treated as strings, but reject undef and references
1233 1052 ▶ croak 'only strings can be deserialized' if not defined $data
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data or ref $data and ref $data ne "Mojo::Parameters" 0 1052 1052
Condition50%3/6
not defined $data or ref $data and ref $data ne "Mojo::Parameters"
l!l&&r!l&&!r
001052
ref $data and ref $data ne "Mojo::Parameters"
!ll&&!rl&&r
5824700
MC/DC0%0/3
not defined $data or ref $data and ref $data ne "Mojo::Parameters"
not defined $data ref $data ref $data ne "Mojo::Parameters"
Truth table50%2/4
not(A) or B and C
A= not defined $dataB= ref $dataC= ref $data ne "Mojo::Parameters"
ABCresult
1XX1
0111
00X0
0100
1234 or (ref $data and ref $data ne 'Mojo::Parameters');
1235  
1236 my ($in, $style, $explode, $allowEmptyValue, $name, $schema, $strip_internal_ws) =
1237 1052 @opt{qw(in style explode allowEmptyValue name schema strip_internal_ws)};
1238  
1239 # sometimes the schema is somewhere else; respect it
1240 1052 ▶ $state = { %$state, schema_path => $state->{keyword_path}.'/schema' } if not exists $state->{schema_path};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$state{"schema_path"} 996 56 1052
1241  
1242 1052 my @types = $self->_type_in_schema($schema, { %$state, keyword_path => $state->{schema_path} });
1243  
1244 1049 ▶ if ($style eq 'simple' or $style eq 'matrix' or $style eq 'label') {
Branch: 5 branches
BranchTrueFalseTotal
if ($style eq 'simple' or $style eq 'matrix' or $style eq 'label') { } 501 548 1049
elsif ($style eq 'form') { } 349 199 548
elsif ($style eq 'spaceDelimited' or $style eq 'pipeDelimited') { } 102 97 199
elsif ($style eq 'deepObject') { } 42 55 97
elsif ($style eq 'cookie') { } 55 0 55
Condition100%6/6
$style eq "simple" or $style eq "matrix" or $style eq "label"
l!l&&r!l&&!r
43764548
$style eq "simple" or $style eq "matrix"
l!l&&r!l&&!r
36869612
MC/DC100%3/3
$style eq "simple" or $style eq "matrix" or $style eq "label"
$style eq "simple" $style eq "matrix" $style eq "label"
Truth table100%4/4
A or B or C
A= $style eq "simple"B= $style eq "matrix"C= $style eq "label"
ABCresult
1XX1
01X1
0011
0000
1245 # RFC6570 §3.2.1: "A variable that is undefined (§2.3) has no value and is ignored by the
1246 # expansion process. If all of the variables in an expression are undefined, then the
1247 # expression's expansion is the empty string."
1248 501 ▶ if ($data eq '' and ($style ne 'simple' or @types != 6)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data eq "" and $style ne "simple" || @types != 6) 68 433 501
Condition100%6/6
$data eq "" and $style ne "simple" || @types != 6
!ll&&!rl&&r
428568
$style ne "simple" or @types != 6
l!l&&r!l&&!r
13555
MC/DC100%3/3
$data eq "" and $style ne "simple" || @types != 6
$data eq "" $style ne "simple" @types != 6
Truth table100%4/4
A and B or C
A= $data eq ""B= $style ne "simple"C= @types != 6
ABCresult
0XX0
1000
11X1
1011
1249 68 ▶ if (elem('null', \@types)) {
Branch: 3 branches
BranchTrueFalseTotal
if (elem('null', \@types)) { } 10 58 68
elsif (elem('array', \@types)) { } 26 32 58
elsif (elem('object', \@types)) { } 26 6 32
1250 10 return \undef;
1251 }
1252 elsif (elem('array', \@types)) {
1253 # RFC6570 §2.3-6: "A variable defined as a list value is considered undefined if the list
1254 # contains zero members."
1255 26 return \ [];
1256 }
1257 elsif (elem('object', \@types)) {
1258 # RFC6570 §2.3-6: "A variable defined as an associative array of (name, value) pairs is
1259 # considered undefined if the array contains zero members or if all member names in the
1260 # array are associated with undefined values."
1261 26 return \ {};
1262 }
1263 }
1264  
1265 439 ▶ my $prefix =
Branch: 3 branches
BranchTrueFalseTotal
$style eq 'simple' ? : 318 121 439
$style eq 'label' ? : 58 63 121
$style eq 'matrix' ? : 63 0 63
1266 $style eq 'simple' ? ''
1267 : $style eq 'label' ? '\.'
1268 : $style eq 'matrix' ? ';'
1269 : die;
1270  
1271 439 ▶ return E({ %$state, keyword => 'style' },
Branch: 1 branch
BranchTrueFalseTotal
if length $prefix and not $data =~ s/^$prefix//u 1 438 439
Condition100%3/3
length $prefix and not $data =~ s/^$prefix//u
!ll&&!rl&&r
3181201
MC/DC100%2/2
length $prefix and not $data =~ s/^$prefix//u
length $prefix not $data =~ s/^$prefix//u
Truth table100%3/3
A and not(B)
A= length $prefixB= not $data =~ s/^$prefix//u
ABresult
0X0
100
111
1272 'data does not match indicated style "%s" (invalid prefix)', $style)
1273 if length $prefix and $data !~ s/^$prefix//;
1274  
1275 438 ▶ my $delimiter =
Branch: 5 branches
BranchTrueFalseTotal
$style eq 'simple' && $strip_internal_ws ? : 191 247 438
!$explode ? : 178 69 247
$style eq 'simple' ? : 24 45 69
$style eq 'matrix' ? : 23 22 45
$style eq 'label' ? : 22 0 22
Condition100%3/3
$style eq "simple" and $strip_internal_ws
!ll&&!rl&&r
120127191
MC/DC100%2/2
$style eq "simple" and $strip_internal_ws
$style eq "simple" $strip_internal_ws
Truth table100%3/3
A and B
A= $style eq "simple"B= $strip_internal_ws
ABresult
0X0
100
111
1276 $style eq 'simple' && $strip_internal_ws ? ',(?:%09|%20)*'
1277 : !$explode ? ','
1278 : $style eq 'simple' ? ','
1279 : $style eq 'matrix' ? ';'
1280 : $style eq 'label' ? '\.'
1281 : die;
1282  
1283 438 my @errors;
1284  
1285 # if all types are acceptable, fall through to returning string immediately
1286  
1287 # this block is for:
1288 # style=simple, explode=true, object
1289 # style=label, explode=true, object
1290 # style=matrix, explode=true, object
1291 # style=matrix, explode=true, array
1292 # but NOT: explode=false (any style), or style=simple/label, explode=true for arrays.
1293 438 ▶ if (@types != 6 and $explode
Branch: 1 branch
BranchTrueFalseTotal
if (@types != 6 and $explode and ($style eq "simple" || $style eq "label") && elem("object", \@types) || $style eq "matrix" && elem(["object", "array"], \@types)) 66 372 438
Condition94%17/18
@types != 6 and $explode and ($style eq "simple" || $style eq "label") && elem("object", \@types) || $style eq "matrix" && elem(["object", "array"], \@types)
!ll&&!rl&&r
3502266
@types != 6 and $explode
!ll&&!rl&&r
2832288
$style eq "simple" || $style eq "label" and elem("object", \@types) or $style eq "matrix" and elem(["object", "array"], \@types)
l!l&&r!l&&!r
432322
$style eq "simple" || $style eq "label" and elem("object", \@types)
!ll&&!rl&&r
232243
$style eq "simple" or $style eq "label"
l!l&&r!l&&!r
432223
$style eq "matrix" and elem(["object", "array"], \@types)
!ll&&!rl&&r
22023
MC/DC42%3/7
@types != 6 and $explode and ($style eq "simple" || $style eq "label") && elem("object", \@types) || $style eq "matrix" && elem(["object", "array"], \@types)
@types != 6 $explode $style eq "simple" $style eq "label" elem("object", \@types) $style eq "matrix" elem(["object", "array"], \@types)
Truth table53%7/13
A and B and C or D and E or F and G
A= @types != 6B= $explodeC= $style eq "simple"D= $style eq "label"E= elem("object", \@types)F= $style eq "matrix"G= elem(["object", "array"], \@types)
ABCDEFGresult
0XXXXXX0
10XXXXX0
1100X0X0
1100X100
111X00X0
111X0100
110100X0
11010100
111X1XX1
11011XX1
1100X111
111X0111
11010111
1294 and ((($style eq 'simple' or $style eq 'label') and elem('object', \@types))
1295 or ($style eq 'matrix' and elem([qw(object array)], \@types)))) {
1296  
1297 66 my @values = split($delimiter, $data, -1);
1298  
1299 66 ▶ my $type = elem('object', \@types) ? 'object' : 'array';
Branch: 1 branch
BranchTrueFalseTotal
elem('object', \@types) ? : 56 10 66
1300 66 my $idx = -1;
1301  
1302 # we only make one attempt, even if both types are requested, because any errors when
1303 # deserializing to an object will also occur for array
1304 # RFC6570 §3.2.1-7: for arrays with style=matrix and explode=true, expand as an object,
1305 # where the key names are the parameter name
1306  
1307 my @keys_and_values = map uri_decode($_),
1308 66 map do {
1309 189 ++$idx;
1310 # RFC6570 §3.2.1-6: empty value does not use '='
1311 189 my ($key, $val) = split(/=/, $_, 2);
1312  
1313 189 ▶ ()= E({ %$state, keyword => 'style', errors => \@errors },
Branch: 2 branches
BranchTrueFalseTotal
if defined $val and not length $val 13 176 189
$type eq 'object' ? : 10 3 13
Condition100%3/3
defined $val and not length $val
!ll&&!rl&&r
4013613
MC/DC100%2/2
defined $val and not length $val
defined $val not length $val
Truth table100%3/3
A and not(B)
A= defined $valB= not length $val
ABresult
0X0
100
111
1314 'data does not match indicated style "%s" for %s (invalid separator at %s)',
1315 $style, $type, $type eq 'object' ? 'key "'.$key.'"' : 'index '.$idx)
1316 if defined $val and not length $val;
1317 189 ▶ ($key//'', $val//'');
Condition100%4/4
$key // ""
l!l
1845
$val // ""
l!l
14940
MC/DC100%1/1
$key // ""
$key
MC/DC100%1/1
$val // ""
$val
Truth table100%2/2
A
A= $key
Aresult
11
00
Truth table100%2/2
A
A= $val
Aresult
11
00
1318 },
1319 @values;
1320  
1321 my $data = $type eq 'object' ? +{ @keys_and_values }
1322 66 ▶ : [ map do {
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'object' ? : 56 10 66
1323 28 ▶ ()= E({ %$state, keyword => 'style', errors => \@errors },
Branch: 2 branches
BranchTrueFalseTotal
if not defined $our $_[0] or $our $_[0] ne $name 1 27 28
defined $our $_[0] ? : 1 0 1
Condition66%2/3
not defined $our $_[0] or $our $_[0] ne $name
l!l&&r!l&&!r
0127
MC/DC50%1/2
not defined $our $_[0] or $our $_[0] ne $name
not defined $our $_[0] $our $_[0] ne $name
Truth table66%2/3
not(A) or B
A= not defined $our $_[0]B= $our $_[0] ne $name
ABresult
1X1
011
000
1324 'data does not match indicated style "matrix" for array (invalid element name%s)',
1325 defined $_->[0] ? ' at "'.$_->[0].'"' : '')
1326 if not defined $_->[0] or $_->[0] ne $name;
1327 28 $_->[1];
1328 },
1329 pairs @keys_and_values
1330 ];
1331  
1332 66 ▶ if (not @errors) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@errors) 54 12 66
1333 54 ▶ $self->_coerce_object_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} }) if $type eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "object" 46 8 54
1334 54 ▶ $self->_coerce_array_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} }) if $type eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "array" 8 46 54
1335 54 return \$data;
1336 }
1337 }
1338  
1339 # process matrix prefix for primitives, and for array and object when explode=false
1340 384 ▶ if ($style eq 'matrix'
Branch: 1 branch
BranchTrueFalseTotal
if ($style eq "matrix" and !$explode || elem(["string", "number", "boolean", "null"], \@types) and !($data =~ s/^([^{}=]+)(?:=(?=.)|$)//u) || uri_decode($1) ne $name) 2 382 384
Condition83%10/12
$style eq "matrix" and !$explode || elem(["string", "number", "boolean", "null"], \@types) and !($data =~ s/^([^{}=]+)(?:=(?=.)|$)//u) || uri_decode($1) ne $name
!ll&&!rl&&r
345372
$style eq "matrix" and !$explode || elem(["string", "number", "boolean", "null"], \@types)
!ll&&!rl&&r
341439
not $explode or elem(["string", "number", "boolean", "null"], \@types)
l!l&&r!l&&!r
3904
not $data =~ s/^([^{}=]+)(?:=(?=.)|$)//u or uri_decode($1) ne $name
l!l&&r!l&&!r
2037
MC/DC60%3/5
$style eq "matrix" and !$explode || elem(["string", "number", "boolean", "null"], \@types) and !($data =~ s/^([^{}=]+)(?:=(?=.)|$)//u) || uri_decode($1) ne $name
$style eq "matrix" not $explode elem(["string", "number", "boolean", "null"], \@types) not $data =~ s/^([^{}=]+)(?:=(?=.)|$)//u uri_decode($1) ne $name
Truth table50%4/8
A and not(B) or C and not(D) or E
A= $style eq "matrix"B= not $explodeC= elem(["string", "number", "boolean", "null"], \@types)D= not $data =~ s/^([^{}=]+)(?:=(?=.)|$)//uE= uri_decode($1) ne $name
ABCDEresult
0XXXX0
100XX0
11X000
101000
11X1X1
11X011
1011X1
101011
1341 and (not $explode or elem([qw(string number boolean null)], \@types))
1342 # '=' is included after the name iff the variable's value is not empty; name is still encoded
1343 and ($data !~ s/^([^{}=]+)(?:=(?=.)|$)// or uri_decode($1) ne $name)) {
1344 2 ()= E({ %$state, keyword => 'style', errors => \@errors },
1345 'data does not match indicated style "matrix" (invalid prefix)');
1346 2 push $state->{errors}->@*, @errors;
1347 2 return;
1348 }
1349  
1350 # this block is for:
1351 # all styles, explode=false, objects
1352 # style=simple or label, explode=false, array
1353 # style=simple or label, explode=true, array
1354 # style=matrix, explode=false, array
1355  
1356 382 ▶ if (@types != 6 and elem([qw(array object)], \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@types != 6 and elem(["array", "object"], \@types)) 154 228 382
Condition100%3/3
@types != 6 and elem(["array", "object"], \@types)
!ll&&!rl&&r
28200154
MC/DC100%2/2
@types != 6 and elem(["array", "object"], \@types)
@types != 6 elem(["array", "object"], \@types)
Truth table100%3/3
A and B
A= @types != 6B= elem(["array", "object"], \@types)
ABresult
0X0
100
111
1357 154 my @values = map uri_decode($_), split($delimiter, $data, -1);
1358  
1359 154 ▶ if (not $explode and elem('object', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $explode and elem("object", \@types)) 59 95 154
Condition100%3/3
not $explode and elem("object", \@types)
!ll&&!rl&&r
346159
MC/DC100%2/2
not $explode and elem("object", \@types)
not $explode elem("object", \@types)
Truth table100%3/3
not(A) and B
A= not $explodeB= elem("object", \@types)
ABresult
0X0
100
111
1360 59 ▶ if (not @values % 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@values % 2) 49 10 59
1361 49 $data = +{ @values };
1362 49 $self->_coerce_object_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1363 49 return \$data;
1364 }
1365 # fall through to primitive
1366 }
1367  
1368 105 ▶ if (elem('array', \@types)
Branch: 1 branch
BranchTrueFalseTotal
if (elem("array", \@types) and elem($style, ["simple", "label"]) || $style eq "matrix" && !$explode) 88 17 105
Condition88%8/9
elem("array", \@types) and elem($style, ["simple", "label"]) || $style eq "matrix" && !$explode
!ll&&!rl&&r
14388
elem($style, ["simple", "label"]) or $style eq "matrix" and not $explode
l!l&&r!l&&!r
7993
$style eq "matrix" and not $explode
!ll&&!rl&&r
039
MC/DC75%3/4
elem("array", \@types) and elem($style, ["simple", "label"]) || $style eq "matrix" && !$explode
elem("array", \@types) elem($style, ["simple", "label"]) $style eq "matrix" not $explode
Truth table80%4/5
A and B or C and not(D)
A= elem("array", \@types)B= elem($style, ["simple", "label"])C= $style eq "matrix"D= not $explode
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1369 and (elem($style, [qw(simple label)]) or ($style eq 'matrix' and not $explode))) {
1370 88 $data = \@values;
1371 88 $self->_coerce_array_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1372 88 return \$data;
1373 }
1374 }
1375  
1376 245 $data = uri_decode($data);
1377 245 ▶ return \$data if @types == 6 or coerce_primitive(\$data, \@types);
Branch: 1 branch
BranchTrueFalseTotal
if @types == 6 or coerce_primitive(\$data, \@types) 215 30 245
Condition100%3/3
@types == 6 or coerce_primitive(\$data, \@types)
l!l&&r!l&&!r
2818730
MC/DC100%2/2
@types == 6 or coerce_primitive(\$data, \@types)
@types == 6 coerce_primitive(\$data, \@types)
Truth table100%3/3
A or B
A= @types == 6B= coerce_primitive(\$data, \@types)
ABresult
1X1
011
000
1378  
1379 30 ▶ if (@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) 8 22 30
1380 8 push $state->{errors}->@*, @errors;
1381 8 return;
1382 }
1383 }
1384  
1385 elsif ($style eq 'form') {
1386 # "in" can be "query", "cookie" or "form"
1387 349 ▶ croak '"', $style, '" style in "', $in, '" requires a Mojo::Parameters object'
Branch: 1 branch
BranchTrueFalseTotal
if elem($in, ["query", "cookie"]) and ref $data ne "Mojo::Parameters" 0 349 349
Condition66%2/3
elem($in, ["query", "cookie"]) and ref $data ne "Mojo::Parameters"
!ll&&!rl&&r
143350
MC/DC0%0/2
elem($in, ["query", "cookie"]) and ref $data ne "Mojo::Parameters"
elem($in, ["query", "cookie"]) ref $data ne "Mojo::Parameters"
Truth table66%2/3
A and B
A= elem($in, ["query", "cookie"])B= ref $data ne "Mojo::Parameters"
ABresult
0X0
100
111
1388 if elem($in, [qw(query cookie)]) and ref $data ne 'Mojo::Parameters';
1389  
1390 # if all types are acceptable, fall through to returning string immediately
1391  
1392 349 ▶ if ($explode and @types != 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explode and @types != 6) 236 113 349
Condition100%3/3
$explode and @types != 6
!ll&&!rl&&r
8231236
MC/DC100%2/2
$explode and @types != 6
$explode @types != 6
Truth table100%3/3
A and B
A= $explodeB= @types != 6
ABresult
0X0
100
111
1393 236 ▶ if (elem('object', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (elem("object", \@types)) 58 178 236
1394 58 ▶ return E({ %$state, keyword => 'explode' }, 'explode=true is not supported for objects using style=form in forms') if $in eq 'form';
Branch: 1 branch
BranchTrueFalseTotal
if $in eq "form" 2 56 58
1395  
1396 # treat the entire querystring as the hash of keys and values; if duplicate, last entry wins
1397 56 $data = +{ $data->pairs->@* };
1398 56 ▶ delete $data->@{grep +(!length $data->{$_}), keys %$data} if $allowEmptyValue;
Branch: 1 branch
BranchTrueFalseTotal
if $allowEmptyValue 4 52 56
1399 56 $self->_coerce_object_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1400 54 ▶ return keys %$data ? \$data : ();
Branch: 1 branch
BranchTrueFalseTotal
keys %$data ? : 45 9 54
1401 }
1402  
1403 178 ▶ if (elem('array', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (elem("array", \@types)) 44 134 178
1404 44 ▶ return E({ %$state, keyword => 'explode' }, 'explode=true is not supported for arrays using style=form in forms') if $in eq 'form';
Branch: 1 branch
BranchTrueFalseTotal
if $in eq "form" 2 42 44
1405  
1406 42 $data = $data->every_param($name);
1407 42 ▶ $data = [ grep length, @$data ] if $allowEmptyValue;
Branch: 1 branch
BranchTrueFalseTotal
if $allowEmptyValue 6 36 42
1408 42 $self->_coerce_array_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1409 42 ▶ return @$data ? \$data : ();
Branch: 1 branch
BranchTrueFalseTotal
@$data ? : 29 13 42
1410 }
1411 }
1412  
1413 # single parameter value used for primitives, and for array and object when explode=false
1414 # (explode=false is not valid with array, object for cookies)
1415 # if the parameter name appears more than once, the last value will be used
1416 247 ▶ $data = $in eq 'form' ? Encode::decode('UTF-8', $data, Encode::DIE_ON_ERR) : $data->param($name);
Branch: 1 branch
BranchTrueFalseTotal
$in eq 'form' ? : 10 237 247
1417 247 ▶ return if not defined $data or $allowEmptyValue and not length $data;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data or $allowEmptyValue and not length $data 69 178 247
Condition100%6/6
not defined $data or $allowEmptyValue and not length $data
l!l&&r!l&&!r
609178
$allowEmptyValue and not length $data
!ll&&!rl&&r
17719
MC/DC100%3/3
not defined $data or $allowEmptyValue and not length $data
not defined $data $allowEmptyValue not length $data
Truth table100%4/4
not(A) or B and not(C)
A= not defined $dataB= $allowEmptyValueC= not length $data
ABCresult
1XX1
0111
00X0
0100
1418  
1419 178 ▶ if ($in ne 'cookie' and not $explode and @types != 6 and elem([qw(array object)], \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in ne "cookie" and not $explode and @types != 6 and elem(["array", "object"], \@types)) 45 133 178
Condition88%8/9
$in ne "cookie" and not $explode and @types != 6 and elem(["array", "object"], \@types)
!ll&&!rl&&r
133045
$in ne "cookie" and not $explode and @types != 6
!ll&&!rl&&r
132145
$in ne "cookie" and not $explode
!ll&&!rl&&r
468646
MC/DC75%3/4
$in ne "cookie" and not $explode and @types != 6 and elem(["array", "object"], \@types)
$in ne "cookie" not $explode @types != 6 elem(["array", "object"], \@types)
Truth table80%4/5
A and not(B) and C and D
A= $in ne "cookie"B= not $explodeC= @types != 6D= elem(["array", "object"], \@types)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1420 # note: all ',' characters will be seen as delimiters, unless double encoding is done (and an
1421 # extra encoding pass done in the application). If this is a problem, switch from
1422 # explode=false to explode=true.
1423 45 my @values = split /,/, $data, -1;
1424 45 ▶ if (not @values % 2 and elem('object', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @values % 2 and elem("object", \@types)) 21 24 45
Condition100%3/3
not @values % 2 and elem("object", \@types)
!ll&&!rl&&r
15921
MC/DC100%2/2
not @values % 2 and elem("object", \@types)
not @values % 2 elem("object", \@types)
Truth table100%3/3
not(A) and B
A= not @values % 2B= elem("object", \@types)
ABresult
0X0
100
111
1425 21 $data = +{ @values };
1426 21 $self->_coerce_object_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1427 21 return \$data;
1428 }
1429 24 ▶ if (elem('array', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (elem("array", \@types)) 22 2 24
1430 22 $data = \@values;
1431 22 $self->_coerce_array_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1432 22 return \$data;
1433 }
1434 }
1435  
1436 135 ▶ return \$data if @types == 6 or coerce_primitive(\$data, \@types);
Branch: 1 branch
BranchTrueFalseTotal
if @types == 6 or coerce_primitive(\$data, \@types) 126 9 135
Condition100%3/3
@types == 6 or coerce_primitive(\$data, \@types)
l!l&&r!l&&!r
221049
MC/DC100%2/2
@types == 6 or coerce_primitive(\$data, \@types)
@types == 6 coerce_primitive(\$data, \@types)
Truth table100%3/3
A or B
A= @types == 6B= coerce_primitive(\$data, \@types)
ABresult
1X1
011
000
1437 }
1438  
1439 ▶ elsif ($style eq 'spaceDelimited' or $style eq 'pipeDelimited') {
Condition100%3/3
$style eq "spaceDelimited" or $style eq "pipeDelimited"
l!l&&r!l&&!r
515197
MC/DC100%2/2
$style eq "spaceDelimited" or $style eq "pipeDelimited"
$style eq "spaceDelimited" $style eq "pipeDelimited"
Truth table100%3/3
A or B
A= $style eq "spaceDelimited"B= $style eq "pipeDelimited"
ABresult
1X1
011
000
1440 # "in" can be "query" or "form"
1441 102 ▶ croak '"', $style, '" style in "', $in, '" requires a Mojo::Parameters object'
Branch: 1 branch
BranchTrueFalseTotal
if $in eq "query" and ref $data ne "Mojo::Parameters" 0 102 102
Condition66%2/3
$in eq "query" and ref $data ne "Mojo::Parameters"
!ll&&!rl&&r
8940
MC/DC0%0/2
$in eq "query" and ref $data ne "Mojo::Parameters"
$in eq "query" ref $data ne "Mojo::Parameters"
Truth table66%2/3
A and B
A= $in eq "query"B= ref $data ne "Mojo::Parameters"
ABresult
0X0
100
111
1442 if $in eq 'query' and ref $data ne 'Mojo::Parameters';
1443  
1444 102 ▶ return E({ %$state, keyword => 'explode' }, 'explode=true is not supported for style=%s', $style)
Branch: 1 branch
BranchTrueFalseTotal
if $explode 4 98 102
1445 if $explode;
1446  
1447 98 ▶ return E({ %$state, keyword => 'style' }, '%s style can only deserialize to arrays or objects', $style)
Branch: 1 branch
BranchTrueFalseTotal
unless elem(["array", "object"], \@types) 6 92 98
1448 if not elem([qw(array object)], \@types);
1449  
1450 92 ▶ $data = $in eq 'form' ? Encode::decode('UTF-8', $data, Encode::DIE_ON_ERR) : $data->param($name);
Branch: 1 branch
BranchTrueFalseTotal
$in eq 'form' ? : 8 84 92
1451 92 ▶ return if not defined $data or $allowEmptyValue and not length $data;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data or $allowEmptyValue and not length $data 12 80 92
Condition83%5/6
not defined $data or $allowEmptyValue and not length $data
l!l&&r!l&&!r
4880
$allowEmptyValue and not length $data
!ll&&!rl&&r
8008
MC/DC66%2/3
not defined $data or $allowEmptyValue and not length $data
not defined $data $allowEmptyValue not length $data
Truth table75%3/4
not(A) or B and not(C)
A= not defined $dataB= $allowEmptyValueC= not length $data
ABCresult
1XX1
0111
00X0
0100
1452  
1453 # we do NOT perform another decoding pass here:
1454 # v3.2.0 §E.6 "Percent-Encoding and Illegal or Reserved Delimiters": For maximum
1455 # interoperability, it is RECOMMENDED to either define and document an additional escape
1456 # convention while percent-encoding the delimiters for these styles [deepObject, pipeDelimited,
1457 # and spaceDelimited], or to avoid these styles entirely. The exact method of additional
1458 # encoding/escaping is left to the API designer, and is expected to be performed before
1459 # serialization and encoding described in this specification, and reversed after this
1460 # specification’s encoding and serialization steps are reversed. This keeps it outside of the
1461 # processes governed by this specification.
1462  
1463 # if the parameter name appears more than once, the last value will be used
1464 80 ▶ my $delimiter = $style eq 'spaceDelimited' ? ' ' : $style eq 'pipeDelimited' ? '\|' : die;
Branch: 2 branches
BranchTrueFalseTotal
$style eq 'spaceDelimited' ? : 40 40 80
$style eq 'pipeDelimited' ? : 40 0 40
1465 80 my @values = split /$delimiter/, $data, -1;
1466  
1467 80 ▶ if (not @values % 2 and elem('object', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @values % 2 and elem("object", \@types)) 28 52 80
Condition100%3/3
not @values % 2 and elem("object", \@types)
!ll&&!rl&&r
381428
MC/DC100%2/2
not @values % 2 and elem("object", \@types)
not @values % 2 elem("object", \@types)
Truth table100%3/3
not(A) and B
A= not @values % 2B= elem("object", \@types)
ABresult
0X0
100
111
1468 28 $data = +{ @values };
1469 28 $self->_coerce_object_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1470 28 return \$data;
1471 }
1472 52 ▶ if (elem('array', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (elem("array", \@types)) 48 4 52
1473 48 $data = \@values;
1474 48 $self->_coerce_array_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1475 48 return \$data;
1476 }
1477 }
1478  
1479 elsif ($style eq 'deepObject') {
1480 42 ▶ croak '"', $style, '" style in "', $in, '" requires a Mojo::Parameters object'
Branch: 1 branch
BranchTrueFalseTotal
if $in eq "query" and ref $data ne "Mojo::Parameters" 0 42 42
Condition66%2/3
$in eq "query" and ref $data ne "Mojo::Parameters"
!ll&&!rl&&r
2400
MC/DC0%0/2
$in eq "query" and ref $data ne "Mojo::Parameters"
$in eq "query" ref $data ne "Mojo::Parameters"
Truth table66%2/3
A and B
A= $in eq "query"B= ref $data ne "Mojo::Parameters"
ABresult
0X0
100
111
1481 if $in eq 'query' and ref $data ne 'Mojo::Parameters';
1482  
1483 # v3.1.1 §4.8.12.2.2: "Note that despite false being the default for deepObject, the combination
1484 # of false with deepObject is undefined."
1485 # v3.2.0 §4.12.2.2: "...when style is "deepObject", [explode] has no effect."
1486 return E({ %$state, keyword => 'explode' }, '"explode" cannot be false with style=deepObject')
1487 42 ▶ if not $explode and $state->{document}->oas_version < '3.2';
Branch: 1 branch
BranchTrueFalseTotal
if not $explode and $$state{"document"}->oas_version < "3.2" 2 40 42
Condition100%3/3
not $explode and $$state{"document"}->oas_version < "3.2"
!ll&&!rl&&r
16242
MC/DC100%2/2
not $explode and $$state{"document"}->oas_version < "3.2"
not $explode $$state{"document"}->oas_version < "3.2"
Truth table100%3/3
not(A) and B
A= not $explodeB= $$state{"document"}->oas_version < "3.2"
ABresult
0X0
100
111
1488  
1489 40 ▶ return E({ %$state, keyword => 'style' }, 'deepObject style can only deserialize to objects')
Branch: 1 branch
BranchTrueFalseTotal
unless elem("object", \@types) 4 36 40
1490 if not elem('object', \@types);
1491  
1492 36 ▶ return E({ %$state, keyword => 'style' }, 'deepObject style cannot be used in forms')
Branch: 1 branch
BranchTrueFalseTotal
if $in eq "form" 2 34 36
1493 if $in eq 'form';
1494  
1495 34 my $params = $data;
1496 34 $data = {};
1497 34 foreach my $pair (pairs $params->pairs->@*) {
1498 111 ▶ if ($pair->[0] =~ /^([^\[]*)\[([^\]]*)\]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$pair[0] =~ /^([^\[]*)\[([^\]]*)\]\z/u) 91 20 111
1499 # we do NOT perform another decoding pass here: see v3.2.0 §E.6 (as above).
1500 91 ▶ $data->{$2} = $pair->[1] if $1 eq $name and (not $allowEmptyValue or length $pair->[1]);
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq $name and !$allowEmptyValue || length $$pair[1] 58 33 91
Condition100%6/6
$1 eq $name and !$allowEmptyValue || length $$pair[1]
!ll&&!rl&&r
25858
not $allowEmptyValue or length $$pair[1]
l!l&&r!l&&!r
5718
MC/DC100%3/3
$1 eq $name and !$allowEmptyValue || length $$pair[1]
$1 eq $name not $allowEmptyValue length $$pair[1]
Truth table100%4/4
A and not(B) or C
A= $1 eq $nameB= not $allowEmptyValueC= length $$pair[1]
ABCresult
0XX0
1000
11X1
1011
1501 }
1502 }
1503  
1504 34 $self->_coerce_object_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1505 34 ▶ return keys %$data ? \$data : ();
Branch: 1 branch
BranchTrueFalseTotal
keys %$data ? : 28 6 34
1506 }
1507  
1508 elsif ($style eq 'cookie') {
1509 # v3.2.0 §4.12.3 "Analogous to form, but following RFC6265 Cookie syntax rules, meaning that
1510 # name-value pairs are separated by a semicolon followed by a single space (e.g. n1=v1; n2=v2),
1511 # and no percent-encoding or other escaping is applied; data values that require any sort of
1512 # escaping MUST be provided in escaped form."
1513  
1514 55 my @pairs = map [ split /=/, $_, 2 ], split /; /, $data;
1515  
1516 55 ▶ if (my @missing_values = grep !defined $_->[1], @pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing_values) = grep((!defined($our $_[1])), @pairs)) 0 55 55
1517 ()= E({ %$state, keyword => 'style' }, 'cookie-string "%s" is missing a value', $_->[0])
1518 0 foreach @missing_values;
1519 0 return;
1520 }
1521  
1522 # if all types are acceptable, fall through to returning string immediately
1523  
1524 55 ▶ if ($explode and @types != 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explode and @types != 6) 51 4 55
Condition66%2/3
$explode and @types != 6
!ll&&!rl&&r
0451
MC/DC50%1/2
$explode and @types != 6
$explode @types != 6
Truth table66%2/3
A and B
A= $explodeB= @types != 6
ABresult
0X0
100
111
1525 51 ▶ if (elem('object', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (elem("object", \@types)) 18 33 51
1526 # treat the entire header string as the hash of keys and values; if duplicate, last entry wins
1527 18 $data = +{ map @$_, @pairs };
1528 18 $self->_coerce_object_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1529 18 ▶ return keys %$data ? \$data : ();
Branch: 1 branch
BranchTrueFalseTotal
keys %$data ? : 18 0 18
1530 }
1531  
1532 33 ▶ if (elem('array', \@types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (elem("array", \@types)) 5 28 33
1533 5 ▶ $data = [ map +($_->[0] eq $name ? $_->[1] : ()), @pairs ];
Branch: 1 branch
BranchTrueFalseTotal
$our $_[0] eq $name ? : 13 6 19
1534 5 $self->_coerce_array_elements($data, $schema, { %$state, keyword_path => $state->{schema_path} });
1535 5 ▶ return @$data ? \$data : ();
Branch: 1 branch
BranchTrueFalseTotal
@$data ? : 5 0 5
1536 }
1537 }
1538  
1539 # single parameter value used for primitives; explode=false is not valid with array, object
1540 # if the parameter name appears more than once, the last value will be used
1541  
1542 32 my @every_param = grep +($_->[0] eq $name), @pairs;
1543 32 ▶ $data = ($every_param[-1]//[])->[1];
Condition100%2/2
$every_param[-1] // []
l!l
293
MC/DC100%1/1
$every_param[-1] // []
$every_param[-1]
Truth table100%2/2
A
A= $every_param[-1]
Aresult
11
00
1544  
1545 32 ▶ return if not defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 3 29 32
1546 29 ▶ return \$data if @types == 6 or coerce_primitive(\$data, \@types);
Branch: 1 branch
BranchTrueFalseTotal
if @types == 6 or coerce_primitive(\$data, \@types) 29 0 29
Condition66%2/3
@types == 6 or coerce_primitive(\$data, \@types)
l!l&&r!l&&!r
4250
MC/DC0%0/2
@types == 6 or coerce_primitive(\$data, \@types)
@types == 6 coerce_primitive(\$data, \@types)
Truth table66%2/3
A or B
A= @types == 6B= coerce_primitive(\$data, \@types)
ABresult
1X1
011
000
1547 }
1548  
1549 else {
1550 0 die 'unsupported style ', $style;
1551 }
1552  
1553 35 ▶ return E({ %$state, keyword => 'schema' }, 'cannot deserialize%s to %s type%s%s',
Branch: 4 branches
BranchTrueFalseTotal
$in eq 'header' ? : 11 24 35
!@types ? : 7 28 35
@types > 1 ? : 0 35 35
@types ? : 28 7 35
1554 ($in eq 'header' ? '' : ' as '.$style.' style'),
1555 !@types ? 'any' : 'requested', @types > 1 ? 's' : '', @types ? ' ('.join(', ', @types).')' : '');
1556 }
1557  
1558 413 ▶sub _validate_body_content ($self, $state, $content_obj, $message) {
Subroutine _validate_body_content: called CC=13 SCAR=25.6
1559 413 my $content_type = $message->headers->content_type;
1560  
1561 413 ▶ return E({ %$state, data_path => $state->{data_path} =~ s{body\z}{header}r, keyword => 'content' },
Branch: 1 branch
BranchTrueFalseTotal
unless length $content_type 4 409 413
1562 'missing header: Content-Type')
1563 if not length $content_type;
1564  
1565 # find the best-matching entry under content/ to get the media-type object
1566 409 my $media_type = match_media_type($content_type, [ keys $content_obj->%* ]);
1567 409 ▶ return E({ %$state, keyword => 'content', recommended_response => [ 415 ] },
Branch: 1 branch
BranchTrueFalseTotal
unless defined $media_type 4 405 409
1568 'incorrect Content-Type "%s"', $content_type)
1569 if not defined $media_type;
1570  
1571 # multipart/* messages will be decoded using its Mojo::Content::MultiPart object, not the raw string
1572 405 ▶ my ($content_ref, $multipart_headers) = $self->_deserialize_content(
Branch: 1 branch
BranchTrueFalseTotal
$message->content->is_multipart ? : 164 241 405
1573 $message->content->is_multipart ? $message->content : \ $message->body,
1574 { %$state }, $content_obj, $media_type, $content_type);
1575  
1576 395 ▶ return if not $content_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $content_ref 14 381 395
1577  
1578 381 jsonp_set($state->{data}, $state->{data_path}.'/content', $content_ref->$*);
1579 381 ▶ jsonp_set($state->{data}, $state->{data_path}.'/header', $multipart_headers)
Branch: 1 branch
BranchTrueFalseTotal
if defined $multipart_headers and @$multipart_headers 142 239 381
Condition100%3/3
defined $multipart_headers and @$multipart_headers
!ll&&!rl&&r
22118142
MC/DC100%2/2
defined $multipart_headers and @$multipart_headers
defined $multipart_headers @$multipart_headers
Truth table100%3/3
A and B
A= defined $multipart_headersB= @$multipart_headers
ABresult
0X0
100
111
1580 if defined $multipart_headers and $multipart_headers->@*;
1581  
1582 381 my $media_type_obj = $content_obj->{$media_type};
1583 381 $state->{data_path} .= '/content';
1584 381 $state->{keyword_path} = jsonp($state->{keyword_path}, 'content', $media_type);
1585 381 ▶ while (defined(my $ref = $media_type_obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$media_type_obj{"\$ref"})) 4 381 385
1586 4 $media_type_obj = $self->_resolve_ref('media-type', $ref, $state);
1587 }
1588  
1589 381 my $valid = 1;
1590  
1591 381 ▶ if (exists $media_type_obj->{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$media_type_obj{"schema"}) 303 78 381
1592 $valid = $self->_evaluate_subschema($content_ref, $media_type_obj->{schema},
1593 303 { %$state, depth => $state->{depth}+1, keyword_path => $state->{keyword_path}.'/schema' });
1594 }
1595  
1596 381 ▶ if (exists $media_type_obj->{itemSchema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$media_type_obj{"itemSchema"}) 30 351 381
1597 30 ▶ return E({ %$state, keyword_path => $state->{keyword_path}.'/itemSchema' },
Branch: 1 branch
BranchTrueFalseTotal
if ref $$content_ref ne "ARRAY" 2 28 30
1598 'deserialized message content is not an array')
1599 if ref $content_ref->$* ne 'ARRAY';
1600  
1601 28 foreach my $idx (0..$content_ref->$*->$#*) {
1602 $valid = 0 if not $self->_evaluate_subschema(\ $content_ref->$*->[$idx],
1603 $media_type_obj->{itemSchema},
1604 { %$state, depth => $state->{depth}+1, data_path => $state->{data_path}.'/'.$idx,
1605 68 ▶ keyword_path => $state->{keyword_path}.'/itemSchema' });
Branch: 1 branch
BranchTrueFalseTotal
unless 8 60 68
1606 }
1607 }
1608  
1609 379 return $valid;
1610 }
1611  
1612 # $content_ref is either a reference to a string, or a Mojo::Content::MultiPart object
1613 # $media_type is the media-type property to be used under the content object;
1614 # $content_type is what is used for the content decoding (the Content-Type header of the message)
1615 # returns false or reference to deserialized data in scalar context;
1616 # returns (false or reference to deserialized data, multipart headers or undef) in list context
1617 594 ▶sub _deserialize_content ($self, $content_ref, $state, $content_obj, $media_type, $content_type) {
Subroutine _deserialize_content: called CC=18 SCAR=28.9
1618 594 $state->{keyword_path} = jsonp($state->{keyword_path}, 'content', $media_type);
1619  
1620 594 my ($deserialized_content_ref, $headers_ref);
1621 594 try {
1622 594 ▶ if (match_media_type($content_type, ['multipart/*'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (match_media_type($content_type, ['multipart/*'])) { } 166 428 594
1623 166 ($deserialized_content_ref, $headers_ref) = \ deserialize_multipart($content_ref);
1624 }
1625 else {
1626 # TODO: handle Content-Encoding header(s)
1627  
1628 # case-insensitive, wildcard lookup; text/* supports charset;
1629 # returns undef if no suitable decoder can be found
1630 428 $deserialized_content_ref = decode_media_type($content_type, $content_ref);
1631 }
1632 }
1633 catch ($e) {
1634 24 return E($state, 'could not decode content as %s: %s', $content_type, $e =~ s/^(.*)\n/$1/r);
1635 }
1636  
1637 570 my $saved_state = { %$state };
1638 570 my $media_type_obj = $content_obj->{$media_type};
1639 570 ▶ while (defined(my $ref = $media_type_obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$media_type_obj{"\$ref"})) 36 570 606
1640 36 $media_type_obj = $self->_resolve_ref('media-type', $ref, $state);
1641 }
1642  
1643 570 ▶ if (not $deserialized_content_ref and not match_media_type($content_type, ['multipart/*'])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($deserialized_content_ref or match_media_type($content_type, ["multipart/*"])) 22 548 570
Condition66%2/3
$deserialized_content_ref or match_media_type($content_type, ["multipart/*"])
l!l&&r!l&&!r
548022
MC/DC50%1/2
$deserialized_content_ref or match_media_type($content_type, ["multipart/*"])
$deserialized_content_ref match_media_type($content_type, ["multipart/*"])
Truth table66%2/3
A or B
A= $deserialized_content_refB= match_media_type($content_type, ["multipart/*"])
ABresult
1X1
011
000
1644 # don't fail, and return the original data, if the best-matching media-type object is under */*
1645 # or the schema would pass on any input
1646 return $content_ref
1647 if $media_type eq '*/*'
1648 14 ▶ or all { ref $_ eq 'HASH' ? !keys %$_ : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 8 6 14
Condition100%6/6
$$media_type_obj{"schema"} // ()
l!l&&r!l&&!r
1222
$$media_type_obj{"itemSchema"} // ()
l!l&&r!l&&!r
2122
MC/DC100%2/2
$$media_type_obj{"schema"} // ()
$$media_type_obj{"schema"} ()
MC/DC100%2/2
$$media_type_obj{"itemSchema"} // ()
$$media_type_obj{"itemSchema"} ()
Truth table100%3/3
A // B
A= $$media_type_obj{"schema"}B= ()
ABresult
1X1
011
000
Truth table100%3/3
A // B
A= $$media_type_obj{"itemSchema"}B= ()
ABresult
1X1
011
000
1649 22 ▶ ($media_type_obj->{schema}//(), $media_type_obj->{itemSchema}//());
Branch: 1 branch
BranchTrueFalseTotal
if $media_type eq "*/*" or CORE::all {ref $_ eq "HASH" ? !keys(%our $_) : $_;} $$media_type_obj{"schema"} // (), $$media_type_obj{"itemSchema"} // () 12 10 22
Condition100%3/3
$media_type eq "*/*" or CORE::all {ref $_ eq "HASH" ? !keys(%our $_) : $_;} $$media_type_obj{"schema"} // (), $$media_type_obj{"itemSchema"} // ()
l!l&&r!l&&!r
6610
MC/DC100%2/2
$media_type eq "*/*" or CORE::all {ref $_ eq "HASH" ? !keys(%our $_) : $_;} $$media_type_obj{"schema"} // (), $$media_type_obj{"itemSchema"} // ()
$media_type eq "*/*" CORE::all {ref $_ eq "HASH" ? !keys(%our $_) : $_;} $$media_type_obj{"schema"} // (), $$media_type_obj{"itemSchema"} // ()
Truth table100%3/3
A or B
A= $media_type eq "*/*"B= CORE::all {ref $_ eq "HASH" ? !keys(%our $_) : $_;} $$media_type_obj{"schema"} // (), $$media_type_obj{"itemSchema"} // ()
ABresult
1X1
011
000
1650  
1651 10 abort($saved_state, 'EXCEPTION: unsupported media type "%s": add support with JSON::Schema::Modern::Utilities::add_media_type(...)', $content_type =~ s/;.*\z//r);
1652 }
1653  
1654 548 ▶ return wantarray ? ($deserialized_content_ref, undef) : $deserialized_content_ref
Branch: 2 branches
BranchTrueFalseTotal
unless match_media_type($content_type, ["application/x-www-form-urlencoded", "multipart/*"]) 284 264 548
wantarray ? : 129 155 284
1655 if not match_media_type($content_type, ['application/x-www-form-urlencoded', 'multipart/*']);
1656  
1657 264 $state->{data_path} .= '/content';
1658  
1659 ()= $self->_decode_content(
1660 $deserialized_content_ref, $headers_ref,
1661 exists $media_type_obj->{itemSchema} # schema_state, schema
1662 ? ({ %$state, keyword_path => $state->{keyword_path}.'/itemSchema' }, $media_type_obj)
1663 : ({ %$state, keyword_path => $state->{keyword_path}.'/schema' }, $media_type_obj->{schema}),
1664 { %$state, # encoding_state
1665 $headers_ref ? (header_path => $state->{data_path} =~ s{/content\z}{/header}r) : () },
1666 # v3.1.2 §4.8.14.1: "The encoding field SHALL only apply to Request Body Objects"
1667 264 ▶ $state->{data_path} =~ m{^/request/body/} || $state->{document}->oas_version >= '3.2'
Branch: 3 branches
BranchTrueFalseTotal
exists $$media_type_obj{'itemSchema'} ? : 22 242 264
$headers_ref ? : 162 102 264
$$state{'data_path'} =~ m[^/request/body/]u || $$state{'document'}->oas_version >= 3.2 ? : 250 14 264
Condition100%3/3
$$state{"data_path"} =~ m[^/request/body/]u or $$state{"document"}->oas_version >= "3.2"
l!l&&r!l&&!r
2401014
MC/DC100%2/2
$$state{"data_path"} =~ m[^/request/body/]u or $$state{"document"}->oas_version >= "3.2"
$$state{"data_path"} =~ m[^/request/body/]u $$state{"document"}->oas_version >= "3.2"
Truth table100%3/3
A or B
A= $$state{"data_path"} =~ m[^/request/body/]uB= $$state{"document"}->oas_version >= "3.2"
ABresult
1X1
011
000
1668 ? $media_type_obj : undef, # encoding_parent
1669 $content_type, # message Content-Type
1670 );
1671  
1672 258 ▶ return wantarray ? ($deserialized_content_ref, $headers_ref ? $headers_ref->$* : undef) : $deserialized_content_ref;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 244 14 258
$headers_ref ? : 160 84 244
1673 }
1674  
1675 # Use the encoding object for application/x-www-form-urlencoded and multipart/* messages to
1676 # deserialize encoded content
1677 # - $schema represents the schema for the content being passed in $content_ref (or may be the
1678 # media-type object if it contains 'itemSchema')
1679 # - $encoding_parent contains either the 'encoding' or 'prefixEncoding' and/or 'itemEncoding'
1680 # keywords (which is a media-type object at the first level, and an encoding object thereafter)
1681 # - $content_type is the type of this part or element, from the header on the message or individual
1682 # part, or as determined by the encoding object for that element
1683 # This is highly recursive, but we have defined conditions for termination:
1684 # - $state->{depth} exceeds max_depth
1685 # - value (of any type) has neither a corresponding encoding object nor a schema
1686 # - value is a primitive with no further decoding indicated
1687 # No return value; decoded content overwrites in place the referenced data that was decoded
1688 1118 ▶sub _decode_content ($self, $content_ref, $headers_ref, $schema_state, $schema, $encoding_state, $encoding_parent, $content_type) {
Subroutine _decode_content: called CC=39 SCAR=36.7
1689 1118 foreach my $state ($schema_state, $encoding_state) {
1690 abort($state, 'EXCEPTION: maximum evaluation depth (%d) exceeded', $self->max_depth)
1691 2236 ▶ if $state->{depth}++ > $self->evaluator->max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"depth"}++ > $self->evaluator->max_depth 0 2236 2236
1692 }
1693  
1694 1118 $encoding_state->{is_form} = match_media_type($content_type, [qw(application/x-www-form-urlencoded multipart/form-data)]);
1695  
1696 1118 my $header_map = {}; # form names to array indices of their originating part
1697  
1698 1118 ▶ if (match_media_type($content_type, ['multipart/form-data'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (match_media_type($content_type, ["multipart/form-data"])) 165 953 1118
1699 # RFC7578 §4.6: respect parts named '_charset_'
1700 165 foreach my $idx (reverse 0..$content_ref->$*->$#*) {
1701 400 my ($name, $value) = $content_ref->$*->[$idx]->%*;
1702 400 ▶ if ($name eq '_charset_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "_charset_") 22 378 400
1703 22 $encoding_state->{charset} = $value;
1704 22 splice($content_ref->$*->@*, $idx, 1);
1705 22 splice($headers_ref->$*->@*, $idx, 1);
1706 }
1707 }
1708  
1709 # multipart/form-data content can be presented as either an array of objects, or an object with
1710 # names as the keys and values of the same name collapsed as an array value.
1711 # If no schema is present indicating the desire for an array, we default to deserializing
1712 # multipart/form-data as an object.
1713 165 ▶ if (ref $schema ne 'HASH' or (not exists $schema->{itemSchema}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema ne "HASH" or not exists $$schema{"itemSchema"} and elem("object", [$self->_type_in_schema($schema, {%$schema_state})])) 117 48 165
Condition100%6/6
ref $schema ne "HASH" or not exists $$schema{"itemSchema"} and elem("object", [$self->_type_in_schema($schema, {%$schema_state})])
l!l&&r!l&&!r
298848
not exists $$schema{"itemSchema"} and elem("object", [$self->_type_in_schema($schema, {%$schema_state})])
!ll&&!rl&&r
103888
MC/DC100%3/3
ref $schema ne "HASH" or not exists $$schema{"itemSchema"} and elem("object", [$self->_type_in_schema($schema, {%$schema_state})])
ref $schema ne "HASH" not exists $$schema{"itemSchema"} elem("object", [$self->_type_in_schema($schema, {%$schema_state})])
Truth table100%4/4
A or not(B) and C
A= ref $schema ne "HASH"B= not exists $$schema{"itemSchema"}C= elem("object", [$self->_type_in_schema($schema, {%$schema_state})])
ABCresult
1XX1
0111
00X0
0100
1714 and elem('object', [$self->_type_in_schema($schema, { %$schema_state })]))) {
1715 117 my $part_hash = {};
1716  
1717 117 foreach my $idx (0..$content_ref->$*->$#*) {
1718 246 my ($name, $value) = $content_ref->$*->[$idx]->%*;
1719  
1720 246 ▶ if (not exists $part_hash->{$name}) { # single string value
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $$part_hash{$name}) { } 208 38 246
1721 208 $part_hash->{$name} = $value;
1722 208 $header_map->{$name} = $idx;
1723 }
1724 else { # array of multiple string values
1725 38 ▶ if (ref $part_hash->{$name} ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$part_hash{$name} ne "ARRAY") 32 6 38
1726 32 $part_hash->{$name} = [ $part_hash->{$name} ];
1727 32 $header_map->{$name} = [ $header_map->{$name} ];
1728 }
1729  
1730 38 push $part_hash->{$name}->@*, $value;
1731 38 push $header_map->{$name}->@*, $idx;
1732 }
1733 }
1734  
1735 117 $content_ref->$* = $part_hash;
1736 }
1737 }
1738  
1739 1118 ▶ my $headers = $headers_ref->$* if $headers_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $headers_ref 226 892 1118
1740  
1741 # used for handling of objects-in-array content (encoding by name with multipart/form-data)
1742 # and top-level object content (application/x-www-form-urlencoded)
1743 810 ▶ state sub _adjust_state_for_object ($self, $property, $schema_state, $schema) {
Subroutine _adjust_state_for_object: called CC=10 SCAR=23.1
1744 $schema_state = { %$schema_state, depth => $schema_state->{depth}+1,
1745 810 data_path => jsonp($schema_state->{data_path}, $property) };
1746  
1747 # this is not exhaustive: if a keyword is hidden in an 'allOf', we will not find it
1748 SCHEMA_LOOP: {
1749 810 ▶ undef $schema, last SCHEMA_LOOP if not defined $schema or ref $schema ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $schema or ref $schema ne "HASH" 106 822 928
Condition100%3/3
not defined $schema or ref $schema ne "HASH"
l!l&&r!l&&!r
9412822
MC/DC100%2/2
not defined $schema or ref $schema ne "HASH"
not defined $schema ref $schema ne "HASH"
Truth table100%3/3
not(A) or B
A= not defined $schemaB= ref $schema ne "HASH"
ABresult
1X1
011
000
1750  
1751 822 ▶ if (exists(($schema->{properties}//{})->{$property})) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists(($$schema{'properties'} // {})->{$property})) { } 450 372 822
elsif (my $pattern = &first(sub { $property =~ /(?:$_)/u; } , keys %{$$schema{'patternProperties'} // {}})) { } 2 370 372
elsif (exists $$schema{'additionalProperties'}) { } 166 204 370
Condition100%2/2
$$schema{"properties"} // {}
l!l
486336
MC/DC100%1/1
$$schema{"properties"} // {}
$$schema{"properties"}
Truth table100%2/2
A
A= $$schema{"properties"}
Aresult
11
00
1752 450 $schema_state->{keyword_path} = jsonp($schema_state->{keyword_path}, 'properties', $property);
1753 450 $schema = $schema->{properties}{$property};
1754 }
1755 4 ▶ elsif (my $pattern = first { $property =~ m/(?:$_)/ } keys(($schema->{patternProperties}//{})->%*)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition100%2/2
$$schema{"patternProperties"} // {}
l!l
4368
MC/DC100%1/1
$$schema{"patternProperties"} // {}
$$schema{"patternProperties"}
Truth table100%2/2
A
A= $$schema{"patternProperties"}
Aresult
11
00
1756 2 $schema_state->{keyword_path} = jsonp($schema_state->{keyword_path}, 'patternProperties', $pattern);
1757 2 $schema = $schema->{patternProperties}{$pattern};
1758 }
1759 elsif (exists($schema->{additionalProperties})) {
1760 166 $schema_state->{keyword_path} = $schema_state->{keyword_path}.'/additionalProperties';
1761 166 $schema = $schema->{additionalProperties};
1762 }
1763 else {
1764 204 ▶ if (defined(my $ref = $schema->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$ref"})) 118 86 204
1765 118 $schema = $self->_resolve_ref('schema', $ref, $schema_state);
1766 118 redo SCHEMA_LOOP;
1767 }
1768 86 ▶ if (defined(my $ref = $schema->{'$dynamicRef'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$dynamicRef"})) 0 86 86
1769 0 $schema = $self->_resolve_dynamicRef('schema', $ref, $schema_state);
1770 0 redo SCHEMA_LOOP;
1771 }
1772  
1773 86 undef $schema;
1774 }
1775 }
1776  
1777 810 return ($schema_state, $schema);
1778 }
1779  
1780 # used for handling of arrays-in-object content when encoding by name (duplicate names for values
1781 # in application/x-www-form-urlencoded and for parts in multipart/form-data) and top-level array
1782 # content
1783 494 ▶ state sub _adjust_state_for_array ($self, $idx, $schema_state, $schema) {
Subroutine _adjust_state_for_array: called CC=9 SCAR=22.5
1784 $schema_state = { %$schema_state, depth => $schema_state->{depth}+1,
1785 494 data_path => $schema_state->{data_path}.'/'.$idx };
1786  
1787 # this is not exhaustive: if a keyword is hidden in an 'allOf', we will not find it
1788 SCHEMA_LOOP: {
1789 494 ▶ undef $schema, last SCHEMA_LOOP if not defined $schema or ref $schema ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $schema or ref $schema ne "HASH" 88 406 494
Condition100%3/3
not defined $schema or ref $schema ne "HASH"
l!l&&r!l&&!r
826406
MC/DC100%2/2
not defined $schema or ref $schema ne "HASH"
not defined $schema ref $schema ne "HASH"
Truth table100%3/3
not(A) or B
A= not defined $schemaB= ref $schema ne "HASH"
ABresult
1X1
011
000
1790  
1791 406 ▶ if (exists $schema->{itemSchema}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $$schema{'itemSchema'}) { } 58 348 406
elsif (defined(($$schema{'prefixItems'} // [])->[$idx])) { } 32 316 348
elsif (exists $$schema{'items'}) { } 280 36 316
1792 # keyword_path is already .../itemSchema
1793 58 $schema = $schema->{itemSchema};
1794 }
1795 ▶ elsif (defined(($schema->{prefixItems}//[])->[$idx])) {
Condition100%2/2
$$schema{"prefixItems"} // []
l!l
74274
MC/DC100%1/1
$$schema{"prefixItems"} // []
$$schema{"prefixItems"}
Truth table100%2/2
A
A= $$schema{"prefixItems"}
Aresult
11
00
1796 32 $schema_state->{keyword_path} = $schema_state->{keyword_path}.'/prefixItems/'.$idx;
1797 32 $schema = $schema->{prefixItems}[$idx];
1798 }
1799 elsif (exists $schema->{items}) {
1800 280 $schema_state->{keyword_path} = $schema_state->{keyword_path}.'/items';
1801 280 $schema = $schema->{items};
1802 }
1803 else {
1804 36 ▶ if (defined(my $ref = $schema->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$ref"})) 0 36 36
1805 0 $schema = $self->_resolve_ref('schema', $ref, $schema_state);
1806 0 redo SCHEMA_LOOP;
1807 }
1808 36 ▶ if (defined(my $ref = $schema->{'$dynamicRef'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$dynamicRef"})) 0 36 36
1809 0 $schema = $self->_resolve_dynamicRef('schema', $ref, $schema_state);
1810 0 redo SCHEMA_LOOP;
1811 }
1812  
1813 36 undef $schema;
1814 }
1815 }
1816  
1817 494 return ($schema_state, $schema);
1818 }
1819  
1820 1118 ▶ if (ref $content_ref->$* eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $$content_ref eq 'HASH') { } 357 761 1118
elsif (ref $$content_ref eq 'ARRAY') { } 157 604 761
1821 # v3.2.0 §4.14.5.1: "For application/x-www-form-urlencoded, the encoding keys MUST map to
1822 # parameter names, with the values produced according to the rules of the Encoding Object.
1823 # For multipart, the encoding keys MUST map to the name parameter of the `Content-Disposition:
1824 # form-data` header of each part, as is defined for multipart/form-data in RFC7578."
1825 357 foreach my $property (sort keys $content_ref->$*->%*) {
1826 678 my ($schema_state, $schema) = _adjust_state_for_object($self, $property, $schema_state, $schema);
1827  
1828 my $encoding_state = { %$encoding_state, depth => $encoding_state->{depth}+1,
1829 data_path => jsonp($encoding_state->{data_path}, $property),
1830 678 keyword_path => jsonp($encoding_state->{keyword_path}, 'encoding', $property),
1831 };
1832 678 ▶ my $encoding_obj = (($encoding_parent//{})->{encoding}//{})->{$property};
Condition100%4/4
($encoding_parent // {})->{"encoding"} // {}
l!l
214464
$encoding_parent // {}
l!l
434244
MC/DC100%1/1
($encoding_parent // {})->{"encoding"} // {}
$encoding_parent
Truth table100%2/2
A
A= $encoding_parent
Aresult
11
00
1833  
1834 # v3.2.0 §4.15.5 1: "Array properties MUST be handled by applying the given Encoding Object to
1835 # produce one encoded value per array item, each with the same name..."
1836 678 ▶ if ($encoding_state->{is_form}
Branch: 2 branches
BranchTrueFalseTotal
if ($$encoding_state{'is_form'} and ref((match_media_type($content_type, ['multipart/form-data']) ? $header_map : $$content_ref)->{$property}) eq 'ARRAY') { } 46 632 678
match_media_type($content_type, ['multipart/form-data']) ? : 208 184 392
Condition100%3/3
$$encoding_state{"is_form"} and ref((match_media_type($content_type, ["multipart/form-data"]) ? $header_map : $$content_ref)->{$property}) eq "ARRAY"
!ll&&!rl&&r
28634646
MC/DC100%2/2
$$encoding_state{"is_form"} and ref((match_media_type($content_type, ["multipart/form-data"]) ? $header_map : $$content_ref)->{$property}) eq "ARRAY"
$$encoding_state{"is_form"} ref((match_media_type($content_type, ["multipart/form-data"]) ? $header_map : $$content_ref)->{$property}) eq "ARRAY"
Truth table100%3/3
A and B
A= $$encoding_state{"is_form"}B= ref((match_media_type($content_type, ["multipart/form-data"]) ? $header_map : $$content_ref)->{$property}) eq "ARRAY"
ABresult
0X0
100
111
1837 and ref((match_media_type($content_type, ['multipart/form-data'])
1838 ? $header_map : $content_ref->$*)->{$property}) eq 'ARRAY') {
1839  
1840 46 foreach my $idx (0 .. $content_ref->$*->{$property}->$#*) {
1841 98 my ($schema_state, $schema) = _adjust_state_for_array($self, $idx, $schema_state, $schema);
1842  
1843 my $encoding_state = { %$encoding_state, depth => $encoding_state->{depth}+1,
1844 data_path => $encoding_state->{data_path}.'/'.$idx,
1845 match_media_type($content_type, ['multipart/form-data'])
1846 98 ▶ ? (header_path => $encoding_state->{header_path}.'/'.$header_map->{$property}[$idx]) : ()
Branch: 1 branch
BranchTrueFalseTotal
match_media_type($content_type, ['multipart/form-data']) ? : 70 28 98
1847 };
1848  
1849 ()= $self->_decode_content_element(\ $content_ref->$*->{$property}[$idx],
1850 98 ▶ $headers ? $headers->[$header_map->{$property}[$idx]] : undef,
Branch: 1 branch
BranchTrueFalseTotal
$headers ? : 70 28 98
1851 $property, $schema_state, $schema, $encoding_state, $encoding_obj);
1852 }
1853 }
1854 else {
1855 # we are parsing object-based form data with a string value, or object-based data from some
1856 # other decoding
1857 # v3.2.0 §4.15.5 1: "... For all other value types for both top-level non-array properties
1858 # and for values, including array values, within a top-level array, the Encoding Object
1859 # MUST be applied to the entire value."
1860 my $encoding_state = { %$encoding_state,
1861 match_media_type($content_type, ['multipart/*'])
1862 632 ▶ ? (header_path => $encoding_state->{header_path}.'/'.$header_map->{$property}) : () };
Branch: 1 branch
BranchTrueFalseTotal
match_media_type($content_type, ['multipart/*']) ? : 176 456 632
1863  
1864 ()= $self->_decode_content_element(\ $content_ref->$*->{$property},
1865 632 ▶ $headers && $encoding_state->{is_form} ? $headers->[$header_map->{$property}] : undef,
Branch: 1 branch
BranchTrueFalseTotal
$headers && $$encoding_state{'is_form'} ? : 176 456 632
Condition66%2/3
$headers and $$encoding_state{"is_form"}
!ll&&!rl&&r
4560176
MC/DC50%1/2
$headers and $$encoding_state{"is_form"}
$headers $$encoding_state{"is_form"}
Truth table66%2/3
A and B
A= $headersB= $$encoding_state{"is_form"}
ABresult
0X0
100
111
1866 $property, $schema_state, $schema, $encoding_state, $encoding_obj);
1867 }
1868 } # end foreach property
1869 } # end HASH
1870  
1871 elsif (ref $content_ref->$* eq 'ARRAY') {
1872 157 foreach my $idx (0 .. $content_ref->$*->$#*) {
1873 396 my ($schema_state, $schema) = _adjust_state_for_array($self, $idx, $schema_state, $schema);
1874 my $encoding_state = { %$encoding_state, depth => $encoding_state->{depth}+1,
1875 data_path => $encoding_state->{data_path}.'/'.$idx,
1876 396 ▶ match_media_type($content_type, ['multipart/*']) ? (header_path => $encoding_state->{header_path}.'/'.$idx) : (),
Branch: 1 branch
BranchTrueFalseTotal
match_media_type($content_type, ['multipart/*']) ? : 272 124 396
1877 };
1878 396 my $encoding_obj;
1879  
1880 396 ▶ if ((($encoding_parent//{})->{prefixEncoding}//[])->[$idx]) {
Branch: 2 branches
BranchTrueFalseTotal
if ((($encoding_parent // {})->{'prefixEncoding'} // [])->[$idx]) { } 12 384 396
elsif (($encoding_parent // {})->{'itemEncoding'}) { } 110 274 384
Condition100%4/4
($encoding_parent // {})->{"prefixEncoding"} // []
l!l
40356
$encoding_parent // {}
l!l
274122
MC/DC100%1/1
($encoding_parent // {})->{"prefixEncoding"} // []
$encoding_parent
Truth table100%2/2
A
A= $encoding_parent
Aresult
11
00
1881 12 $encoding_state->{keyword_path} = $encoding_state->{keyword_path}.'/prefixEncoding/'.$idx;
1882 12 $encoding_obj = $encoding_parent->{prefixEncoding}[$idx];
1883 }
1884 ▶ elsif (($encoding_parent//{})->{itemEncoding}) {
Condition100%2/2
$encoding_parent // {}
l!l
262122
MC/DC100%1/1
$encoding_parent // {}
$encoding_parent
Truth table100%2/2
A
A= $encoding_parent
Aresult
11
00
1885 110 $encoding_state->{keyword_path} = $encoding_state->{keyword_path}.'/itemEncoding';
1886 110 $encoding_obj = $encoding_parent->{itemEncoding};
1887 }
1888  
1889 396 ▶ if (match_media_type($content_type, ['multipart/form-data'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (match_media_type($content_type, ['multipart/form-data'])) { } 132 264 396
1890 # we are parsing array-based multipart/form-data parts, where the items are hashrefs with a
1891 # single property
1892 132 my $property = (keys($content_ref->$*->[$idx]->%*))[0];
1893 132 ($schema_state, $schema) = _adjust_state_for_object($self, $property, $schema_state, $schema);
1894  
1895 $encoding_state = { %$encoding_state,
1896 data_path => jsonp($encoding_state->{data_path}, $property),
1897 132 keyword_path => jsonp($encoding_state->{keyword_path}, 'encoding', $property),
1898 };
1899  
1900 132 ▶ $encoding_obj = (($encoding_obj//{})->{encoding}//{})->{$property};
Condition100%4/4
($encoding_obj // {})->{"encoding"} // {}
l!l
4884
$encoding_obj // {}
l!l
4884
MC/DC100%1/1
($encoding_obj // {})->{"encoding"} // {}
$encoding_obj
Truth table100%2/2
A
A= $encoding_obj
Aresult
11
00
1901  
1902 132 ()= $self->_decode_content_element(\ $content_ref->$*->[$idx]{$property},
1903 $headers->[$idx], $property, $schema_state, $schema, $encoding_state, $encoding_obj);
1904 }
1905 else {
1906 # we are parsing array-based multipart data (other than multipart/form-data), or data from
1907 # some other decoding
1908 264 ▶ ()= $self->_decode_content_element(\ $content_ref->$*->[$idx],
Branch: 1 branch
BranchTrueFalseTotal
$headers && match_media_type($content_type, ['multipart/*']) ? : 140 124 264
Condition66%2/3
$headers and match_media_type($content_type, ["multipart/*"])
!ll&&!rl&&r
1240140
MC/DC50%1/2
$headers and match_media_type($content_type, ["multipart/*"])
$headers match_media_type($content_type, ["multipart/*"])
Truth table66%2/3
A and B
A= $headersB= match_media_type($content_type, ["multipart/*"])
ABresult
0X0
100
111
1909 $headers && match_media_type($content_type, ['multipart/*']) ? $headers->[$idx] : undef,
1910 $idx, $schema_state, $schema, $encoding_state, $encoding_obj);
1911 }
1912 } # end foreach array item
1913 } # end ARRAY
1914  
1915 else {
1916 604 my @types = $self->_type_in_schema($schema, { %$schema_state });
1917 604 coerce_primitive($content_ref, \@types);
1918 }
1919 }
1920  
1921 # decode one object property value, or one array item value, while iterating over the entire object
1922 # or array, and continue to recurse on the decoded content
1923 1126 ▶sub _decode_content_element ($self, $element_ref, $headers, $name, $schema_state, $schema, $encoding_state, $encoding_obj) {
Subroutine _decode_content_element: called CC=64 SCAR=41.6
1924 # validate all encoding headers
1925 1126 ▶ if (($encoding_obj//{})->{headers} and defined $encoding_state->{header_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (($encoding_obj // {})->{"headers"} and defined $$encoding_state{"header_path"}) 52 1074 1126
Condition100%5/5
($encoding_obj // {})->{"headers"} and defined $$encoding_state{"header_path"}
!ll&&!rl&&r
1072252
$encoding_obj // {}
l!l
314812
MC/DC100%2/2
($encoding_obj // {})->{"headers"} and defined $$encoding_state{"header_path"}
$encoding_obj defined $$encoding_state{"header_path"}
Truth table100%3/3
A and B
A= $encoding_objB= defined $$encoding_state{"header_path"}
ABresult
0X0
100
111
1926 52 my $h;
1927 52 foreach my $header_name (sort keys $encoding_obj->{headers}->%*) {
1928 # v3.2.0 §4.15.1.1: "Content-Type is described separately and SHALL be ignored in this section."
1929 84 ▶ next if fc $header_name eq fc 'Content-Type';
Branch: 1 branch
BranchTrueFalseTotal
if fc $header_name eq "content-type" 24 60 84
1930  
1931 60 my $header_obj = $encoding_obj->{headers}{$header_name};
1932 my $state = { %$encoding_state, data_path => $encoding_state->{header_path},
1933 60 keyword_path => jsonp($encoding_state->{keyword_path}, 'headers', $header_name) };
1934 60 ▶ while (defined(my $ref = $header_obj->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$header_obj{"\$ref"})) 36 60 96
1935 36 $header_obj = $self->_resolve_ref('header', $ref, $state);
1936 }
1937  
1938 60 ▶ if (not $h) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($h) 52 8 60
1939 52 $h = Mojo::Headers->new;
1940 $h->add($_ => ref $headers->{$_} eq 'ARRAY' ? $headers->{$_}->@* : $headers->{$_})
1941 52 ▶ foreach keys(($headers//{})->%*);
Branch: 1 branch
BranchTrueFalseTotal
ref $$headers{$_} eq 'ARRAY' ? : 4 146 150
Condition50%1/2
$headers // {}
l!l
520
MC/DC0%0/1
$headers // {}
$headers
Truth table50%1/2
A
A= $headers
Aresult
11
00
1942 }
1943  
1944 60 ▶ if ($self->_validate_parameter({ %$state, depth => $state->{depth}+1 }, $header_obj,
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_validate_parameter({%$state, "depth", $$state{"depth"} + 1}, $header_obj, "name", $header_name, "headers", $h)) 36 24 60
1945 name => $header_name, headers => $h)) {
1946 36 my $path = jsonp($state->{data_path}, $header_name);
1947 $headers->{$header_name} = jsonp_get($state->{data}, $state->{data_path})->{$header_name}
1948 36 ▶ if any { m{^$path(?:/|\z)} } keys jsonp_elements($state->{data})->%*;
Branch: 1 branch
BranchTrueFalseTotal
if CORE::any {m[^$path(?:/|\z)]u;} keys %{jsonp_elements($$state{"data"})} 28 8 36
1949 }
1950 }
1951 }
1952  
1953 1126 my ($element_decoded_ref, $content_type);
1954  
1955 # if this element is not a string, we assume it was already correctly decoded into the correct
1956 # type (e.g. as or from a nested json structure), and skip the decoding step
1957 1126 ▶ goto RECURSE if not is_type('string', $element_ref->$*);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $$element_ref) 132 994 1126
1958  
1959 994 my @content_types; # we will try to decode with these type(s)
1960  
1961 # v3.2.0 §4.15.1.2: "[These fields] SHALL be ignored if the media type is not
1962 # application/x-www-form-urlencoded or multipart/form-data."
1963 994 ▶ if ($encoding_state->{is_form} and $encoding_obj
Branch: 1 branch
BranchTrueFalseTotal
if ($$encoding_state{'is_form'} and $encoding_obj and CORE::any {exists $$encoding_obj{$_};} 'style', 'explode', 'allowReserved') { } 56 938 994
Condition100%6/6
$$encoding_state{"is_form"} and $encoding_obj and CORE::any {exists $$encoding_obj{$_};} "style", "explode", "allowReserved"
!ll&&!rl&&r
77616256
$$encoding_state{"is_form"} and $encoding_obj
!ll&&!rl&&r
462314218
MC/DC100%3/3
$$encoding_state{"is_form"} and $encoding_obj and CORE::any {exists $$encoding_obj{$_};} "style", "explode", "allowReserved"
$$encoding_state{"is_form"} $encoding_obj CORE::any {exists $$encoding_obj{$_};} "style", "explode", "allowReserved"
Truth table100%4/4
A and B and C
A= $$encoding_state{"is_form"}B= $encoding_objC= CORE::any {exists $$encoding_obj{$_};} "style", "explode", "allowReserved"
ABCresult
0XX0
10X0
1100
1111
1964 554 and any { exists $encoding_obj->{$_} } qw(style explode allowReserved)) {
1965 56 ▶ my $style = $encoding_obj->{style} // 'form';
Condition100%2/2
$$encoding_obj{"style"} // "form"
l!l
4412
MC/DC100%1/1
$$encoding_obj{"style"} // "form"
$$encoding_obj{"style"}
Truth table100%2/2
A
A= $$encoding_obj{"style"}
Aresult
11
00
1966  
1967 # 3.2.0 §C: "When using style and similar keywords to produce a multipart/form-data body, the
1968 # query string names are placed in the name parameter of the Content-Disposition part header,
1969 # and the values are placed in the corresponding part body; the ?, =, and & characters are not
1970 # used, and URI percent encoding is not applied"
1971 $element_decoded_ref = $self->_deserialize_style(
1972 $encoding_state->{is_form} eq 'application/x-www-form-urlencoded'
1973 ? Mojo::Parameters->new($element_ref->$*) : $element_ref->$*,
1974 { %$encoding_state, schema_path => $schema_state->{keyword_path}, errors => my $errors = [] },
1975 in => ($encoding_state->{is_form} eq 'application/x-www-form-urlencoded' ? 'query' : 'form'),
1976 style => $style,
1977 56 ▶ explode => $encoding_obj->{explode} // ($style eq 'form' ? true : false),
Branch: 3 branches
BranchTrueFalseTotal
$$encoding_state{'is_form'} eq 'application/x-www-form-urlencoded' ? : 32 24 56
$$encoding_state{'is_form'} eq 'application/x-www-form-urlencoded' ? : 32 24 56
$style eq 'form' ? : 22 6 28
Condition100%4/4
$$encoding_obj{"explode"} // ($style eq "form" ? bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ) : bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ))
l!l
2828
$schema // bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
l!l
506
MC/DC100%1/1
$$encoding_obj{"explode"} // ($style eq "form" ? bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ) : bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ))
$$encoding_obj{"explode"}
MC/DC100%1/1
$schema // bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
$schema
Truth table100%2/2
A
A= $$encoding_obj{"explode"}
Aresult
11
00
Truth table100%2/2
A
A= $schema
Aresult
11
00
1978 name => $name,
1979 schema => $schema // true,
1980 );
1981  
1982 54 ▶ if (@$errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$errors) 10 44 54
1983 10 push $encoding_state->{errors}->@*, @$errors;
1984 10 return;
1985 }
1986  
1987 # if false but no error, then no content was extracted
1988 44 ▶ $element_decoded_ref = '' if not $element_decoded_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $element_decoded_ref 2 42 44
1989 }
1990 else {
1991 938 my $local_state; # used for media-type decoding
1992  
1993 # prefer Content-Type over encoding/contentType
1994 938 ▶ if (defined(($headers//{})->{'Content-Type'})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined(($headers // {})->{'Content-Type'})) { } 110 828 938
elsif (defined(($encoding_obj // {})->{'contentType'})) { } 114 714 828
elsif (ref $schema eq 'HASH') { } 496 218 714
Condition100%2/2
$headers // {}
l!l
380558
MC/DC100%1/1
$headers // {}
$headers
Truth table100%2/2
A
A= $headers
Aresult
11
00
1995 ()= E({ %$encoding_state, data_path => $encoding_state->{header_path}.'/Content-Type',
1996 keyword_path => $encoding_state->{keyword_path}.'/contentType',
1997 recommended_response => [ 415 ] },
1998 'incorrect Content-Type "%s"', $headers->{'Content-Type'})
1999 if defined(($encoding_obj//{})->{contentType})
2000 and not match_media_type($headers->{'Content-Type'},
2001 110 ▶ $encoding_state->{document}->encoding_contentTypes($encoding_obj->{contentType}));
Branch: 1 branch
BranchTrueFalseTotal
if defined(($encoding_obj // {})->{"contentType"}) and not match_media_type($$headers{"Content-Type"}, $$encoding_state{"document"}->encoding_contentTypes($$encoding_obj{"contentType"})) 18 92 110
Condition100%5/5
defined(($encoding_obj // {})->{"contentType"}) and not match_media_type($$headers{"Content-Type"}, $$encoding_state{"document"}->encoding_contentTypes($$encoding_obj{"contentType"}))
!ll&&!rl&&r
563618
$encoding_obj // {}
l!l
8228
MC/DC100%2/2
defined(($encoding_obj // {})->{"contentType"}) and not match_media_type($$headers{"Content-Type"}, $$encoding_state{"document"}->encoding_contentTypes($$encoding_obj{"contentType"}))
$encoding_obj not match_media_type($$headers{"Content-Type"}, $$encoding_state{"document"}->encoding_contentTypes($$encoding_obj{"contentType"}))
Truth table100%3/3
A and not(B)
A= $encoding_objB= not match_media_type($$headers{"Content-Type"}, $$encoding_state{"document"}->encoding_contentTypes($$encoding_obj{"contentType"}))
ABresult
0X0
100
111
2002  
2003 110 @content_types = $headers->{'Content-Type'};
2004 110 $local_state = $encoding_state;
2005 }
2006 ▶ elsif (defined(($encoding_obj//{})->{contentType})) {
Condition100%2/2
$encoding_obj // {}
l!l
164664
MC/DC100%1/1
$encoding_obj // {}
$encoding_obj
Truth table100%2/2
A
A= $encoding_obj
Aresult
11
00
2007 # no way to determine which media-type is the correct one; we will try them all
2008 114 @content_types = $encoding_state->{document}->encoding_contentTypes($encoding_obj->{contentType})->@*;
2009 114 $local_state = { %$encoding_state, keyword_path => $encoding_state->{keyword_path}.'/contentType' };
2010 }
2011 elsif (ref $schema eq 'HASH') {
2012 # v3.2.0 §4.14.1: "If no Encoding Object is provided for a property or item, the behavior is
2013 # determined by the default values documented for the Encoding Object."
2014 496 $local_state = { %$schema_state }; # ends in /schema iff at root
2015 496 my @types = $self->_type_in_schema($schema, { %$local_state });
2016 @content_types =
2017 @types == 6 || elem([qw(null boolean number)], \@types) ? 'application/octet-stream'
2018 : elem([qw(object array)], \@types) ? 'application/json'
2019 496 ▶ : exists(($schema//{})->{contentEncoding}) ? 'application/octet-stream' : 'text/plain';
Branch: 3 branches
BranchTrueFalseTotal
@types == 6 || elem(['null', 'boolean', 'number'], \@types) ? : 132 364 496
elem(['object', 'array'], \@types) ? : 112 252 364
exists(($schema // {})->{'contentEncoding'}) ? : 0 252 252
Condition80%4/5
@types == 6 or elem(["null", "boolean", "number"], \@types)
l!l&&r!l&&!r
6126364
$schema // {}
l!l
2520
MC/DC100%2/2
@types == 6 or elem(["null", "boolean", "number"], \@types)
@types == 6 elem(["null", "boolean", "number"], \@types)
MC/DC0%0/1
$schema // {}
$schema
Truth table100%3/3
A or B
A= @types == 6B= elem(["null", "boolean", "number"], \@types)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $schema
Aresult
11
00
2020  
2021 # v3.2.0 §4.15.4.2: "Using contentEncoding for a multipart field is equivalent to specifying
2022 # an Encoding Object with a headers field containing Content-Transfer-Encoding with a schema
2023 # that requires the value used in contentEncoding. If contentEncoding is used for a
2024 # multipart field that has an Encoding Object with a headers field containing
2025 # Content-Transfer-Encoding with a schema that disallows the value from contentEncoding, the
2026 # result is undefined for serialization and parsing."
2027 }
2028 else {
2029 # no schema, so leave property value alone (the default media-type for unspecified schemas is
2030 # application/octet-stream, which is an identity function)
2031 218 return;
2032 }
2033  
2034 720 my (@errors, @unsupported);
2035 720 foreach my $ct (@content_types) {
2036 730 try {
2037 $ct .= '; charset='.$encoding_state->{charset}
2038 730 ▶ if fc($ct) eq 'text/plain' and exists $encoding_state->{charset};
Branch: 1 branch
BranchTrueFalseTotal
if fc $ct eq "text/plain" and exists $$encoding_state{"charset"} 32 698 730
Condition100%3/3
fc $ct eq "text/plain" and exists $$encoding_state{"charset"}
!ll&&!rl&&r
44225632
MC/DC100%2/2
fc $ct eq "text/plain" and exists $$encoding_state{"charset"}
fc $ct eq "text/plain" exists $$encoding_state{"charset"}
Truth table100%3/3
A and B
A= fc $ct eq "text/plain"B= exists $$encoding_state{"charset"}
ABresult
0X0
100
111
2039  
2040 730 $element_decoded_ref = decode_media_type($ct, $element_ref);
2041  
2042 720 ▶ if (defined $element_decoded_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $element_decoded_ref) { } 708 12 720
2043 708 $content_type = $ct;
2044 708 last;
2045 }
2046 else {
2047 12 push @unsupported, $ct;
2048 }
2049 }
2050 catch ($e) {
2051 10 ()= E({ %$local_state, errors => \@errors },
2052 'could not decode content as %s: %s', $ct, $e =~ s/^(.*)\n/$1/r);
2053 }
2054 }
2055  
2056 720 ▶ push $local_state->{errors}->@*, @errors if not defined $content_type and @errors;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $content_type and @errors 8 712 720
Condition100%3/3
not defined $content_type and @errors
!ll&&!rl&&r
70848
MC/DC100%2/2
not defined $content_type and @errors
not defined $content_type @errors
Truth table100%3/3
not(A) and B
A= not defined $content_typeB= @errors
ABresult
0X0
100
111
2057  
2058 # don't fail, and use the original data, if the schema would pass on any input
2059 720 ▶ abort($local_state, 'EXCEPTION: unsupported media type%s %s: add support with JSON::Schema::Modern::Utilities::add_media_type(...)',
Branch: 3 branches
BranchTrueFalseTotal
if not defined $content_type and @unsupported and defined $schema and not ref $schema eq "HASH" ? !keys(%$schema) : $schema 4 716 720
ref $schema eq 'HASH' ? : 4 0 4
@unsupported > 1 ? : 2 2 4
Condition88%8/9
not defined $content_type and @unsupported and defined $schema and not ref $schema eq "HASH" ? !keys(%$schema) : $schema
!ll&&!rl&&r
71604
not defined $content_type and @unsupported and defined $schema
!ll&&!rl&&r
71424
not defined $content_type and @unsupported
!ll&&!rl&&r
70866
MC/DC75%3/4
not defined $content_type and @unsupported and defined $schema and not ref $schema eq "HASH" ? !keys(%$schema) : $schema
not defined $content_type @unsupported defined $schema not ref $schema eq "HASH" ? !keys(%$schema) : $schema
Truth table80%4/5
not(A) and B and C and not(D)
A= not defined $content_typeB= @unsupportedC= defined $schemaD= not ref $schema eq "HASH" ? !keys(%$schema) : $schema
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2060 @unsupported > 1 ? 's' : '', join(', ', map '"'.$_.'"', @unsupported))
2061 if not defined $content_type and @unsupported
2062 and defined $schema and not (ref $schema eq 'HASH' ? !keys %$schema : $schema);
2063  
2064 716 ▶ return if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 8 708 716
2065 }
2066  
2067 752 ▶ $element_ref->$* = $element_decoded_ref->$* if $element_decoded_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $element_decoded_ref 748 4 752
2068  
2069 RECURSE:
2070 884 ▶ if (defined $schema or defined $encoding_obj
Branch: 1 branch
BranchTrueFalseTotal
if (defined $schema or defined $encoding_obj or $headers and match_media_type($$headers{"Content-Type"}, ["multipart/*"])) 854 30 884
Condition100%9/9
defined $schema or defined $encoding_obj or $headers and match_media_type($$headers{"Content-Type"}, ["multipart/*"])
l!l&&r!l&&!r
8381630
defined $schema or defined $encoding_obj
l!l&&r!l&&!r
7865246
$headers and match_media_type($$headers{"Content-Type"}, ["multipart/*"])
!ll&&!rl&&r
181216
MC/DC100%4/4
defined $schema or defined $encoding_obj or $headers and match_media_type($$headers{"Content-Type"}, ["multipart/*"])
defined $schema defined $encoding_obj $headers match_media_type($$headers{"Content-Type"}, ["multipart/*"])
Truth table100%5/5
A or B or C and D
A= defined $schemaB= defined $encoding_objC= $headersD= match_media_type($$headers{"Content-Type"}, ["multipart/*"])
ABCDresult
1XXX1
01XX1
00111
000X0
00100
2071 or $headers and match_media_type($headers->{'Content-Type'}, ['multipart/*'])) {
2072  
2073 # do not apply _charset_ to nested strings
2074 854 delete $encoding_state->{charset};
2075  
2076 my @charset_indices = pairkeys
2077 796 ▶ pairgrep { $a =~ /^[0-9]+\z/ && ($b->{'Content-Disposition'}//'') eq 'form-data; name="_charset_"' }
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /^[0-9]+\z/u and ($our $b{"Content-Disposition"} // "") eq "form-data; name=\"_charset_\"" 132 664 796
Condition100%2/2
$our $b{"Content-Disposition"} // ""
l!l
9240
MC/DC100%1/1
$our $b{"Content-Disposition"} // ""
$our $b{"Content-Disposition"}
Truth table100%2/2
A
A= $our $b{"Content-Disposition"}
Aresult
11
00
2078 854 ▶ ($headers//{})->%*;
Condition100%2/2
$headers // {}
l!l
384470
MC/DC100%1/1
$headers // {}
$headers
Truth table100%2/2
A
A= $headers
Aresult
11
00
2079  
2080 ()= $self->_decode_content(
2081 $element_ref, # this may be the original data, if nothing was decoded
2082 $headers && match_media_type($headers->{'Content-Type'}, ['multipart/*'])
2083 ? \[ map +(/^[0-9]+\z/ ? $headers->{$_} : ()), sort keys $headers->%* ] # nested headers
2084 : undef,
2085 $schema_state, $schema, $encoding_state, $encoding_obj,
2086 854 ▶ $content_type // ($headers//{})->{'Content-Type'});
Branch: 2 branches
BranchTrueFalseTotal
$headers && match_media_type($$headers{'Content-Type'}, ['multipart/*']) ? : 64 790 854
/^[0-9]+\z/u ? : 132 172 304
Condition100%8/8
$headers and match_media_type($$headers{"Content-Type"}, ["multipart/*"])
!ll&&!rl&&r
47032064
$content_type // ($headers // {})->{"Content-Type"}
l!l&&r!l&&!r
6946496
$headers // {}
l!l
8278
MC/DC100%2/2
$headers and match_media_type($$headers{"Content-Type"}, ["multipart/*"])
$headers match_media_type($$headers{"Content-Type"}, ["multipart/*"])
MC/DC100%2/2
$content_type // ($headers // {})->{"Content-Type"}
$content_type $headers
Truth table100%3/3
A and B
A= $headersB= match_media_type($$headers{"Content-Type"}, ["multipart/*"])
ABresult
0X0
100
111
Truth table100%3/3
A // B
A= $content_typeB= $headers
ABresult
1X1
011
000
2087  
2088 # find all _charset_ headers from the original headers hash and splice them out
2089 0 foreach my $idx (sort { $b <=> $a } @charset_indices) {
2090 4 my $max_idx = max(grep /^[0-9]+\z/, keys $headers->%*);
2091 4 delete $headers->{$idx}; # remove header for _charset_ part
2092 4 foreach my $idx ($idx+1 .. $max_idx) {
2093 4 $headers->{$idx-1} = delete $headers->{$idx}; # renumber all subsequent part headers
2094 }
2095 }
2096 }
2097 }
2098  
2099 # wrap a result object around the errors
2100 648 ▶sub _result ($self, $state, $is_exception = 0, $is_response = 0) {
Subroutine _result: called CC=10 SCAR=23.4
2101 648 ▶ croak 'no errors provided for exception' if $is_exception and not $state->{errors}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $is_exception and not @{$$state{"errors"}} 0 648 648
Condition66%2/3
$is_exception and not @{$$state{"errors"}}
!ll&&!rl&&r
632160
MC/DC0%0/2
$is_exception and not @{$$state{"errors"}}
$is_exception not @{$$state{"errors"}}
Truth table66%2/3
A and not(B)
A= $is_exceptionB= not @{$$state{"errors"}}
ABresult
0X0
100
111
2102 return JSON::Schema::Modern::Result->new(
2103 output_format => $self->evaluator->output_format,
2104 formatted_annotations => 0,
2105 valid => !$state->{errors}->@*,
2106 $is_exception ? (exception => 1) : (), # -> recommended_response: [ 500, 'Internal Server Error' ]
2107 !$state->{errors}->@*
2108 ? (annotations => $state->{annotations}//[])
2109 : (errors => $state->{errors}),
2110 $is_response ? (recommended_response => undef) : (), # responses don't have responses
2111 $state->%{data},
2112 648 ▶ $state->{defaults} ? $state->%{defaults} : (),
Branch: 4 branches
BranchTrueFalseTotal
$is_exception ? : 16 632 648
!@{$$state{'errors'}} ? : 362 286 648
$is_response ? : 89 559 648
$$state{'defaults'} ? : 28 620 648
Condition50%1/2
$$state{"annotations"} // []
l!l
3620
MC/DC0%0/1
$$state{"annotations"} // []
$$state{"annotations"}
Truth table50%1/2
A
A= $$state{"annotations"}
Aresult
11
00
2113 );
2114 }
2115  
2116 541 ▶sub _resolve_ref ($self, $entity_type, $ref, $state, $keyword = '$ref') {
Subroutine _resolve_ref: called CC=6 SCAR=17.9
2117 541 $state->{document}->__entity_type->($entity_type);
2118 541 my $uri = Mojo::URL->new($ref)->to_abs($state->{initial_schema_uri});
2119  
2120 541 my $schema_info = $self->evaluator->_fetch_from_uri($uri);
2121 541 ▶ abort({ %$state, keyword => $keyword }, 'EXCEPTION: unable to find resource "%s"', $uri)
Branch: 1 branch
BranchTrueFalseTotal
unless $schema_info 16 525 541
2122 if not $schema_info;
2123  
2124 abort({ %$state, keyword => $keyword }, 'EXCEPTION: maximum evaluation depth exceeded')
2125 525 ▶ if $state->{depth}++ > $self->evaluator->max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"depth"}++ > $self->evaluator->max_depth 2 523 525
2126  
2127 abort({ %$state, keyword => $keyword }, 'EXCEPTION: bad %s to %s: not a "%s"', $keyword, $schema_info->{canonical_uri}, $entity_type)
2128 523 ▶ if $schema_info->{document}->get_entity_at_location($schema_info->{document_path}) ne $entity_type;
Branch: 1 branch
BranchTrueFalseTotal
if $$schema_info{"document"}->get_entity_at_location($$schema_info{"document_path"}) ne $entity_type 2 521 523
2129  
2130 521 my $scope_uri = $schema_info->{canonical_uri}->clone->fragment(undef);
2131 521 ▶ push $state->{dynamic_scope}->@*, $scope_uri if $state->{dynamic_scope}->[-1] ne $scope_uri;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"dynamic_scope"}[-1] ne $scope_uri 48 473 521
2132  
2133 521 $state->@{qw(document specification_version vocabularies)} = $schema_info->@{qw(document specification_version vocabularies)};
2134 521 $state->{initial_schema_uri} = $schema_info->{canonical_uri};
2135 521 $state->{traversed_keyword_path} = $state->{traversed_keyword_path}.$state->{keyword_path}.'/'.$keyword;
2136 521 $state->{keyword_path} = '';
2137  
2138 521 return $schema_info->{schema};
2139 }
2140  
2141 # as _resolve_ref, but uses dynamic scope resolution, and only handles schema entities
2142 3 ▶sub _resolve_dynamicRef ($self, $ref, $state) {
Subroutine _resolve_dynamicRef: called CC=1 SCAR=0.0
2143 3 JSON::Schema::Modern::Vocabulary::Core->VERSION('0.630');
2144 3 my $uri = JSON::Schema::Modern::Vocabulary::Core->__resolve_dynamicRef($ref, $state);
2145 3 return $self->_resolve_ref('schema', $uri, $state, '$dynamicRef');
2146 }
2147  
2148 # determines the type(s) expected in a schema: array, object, null, boolean, string, number
2149 # (integers will be treated as numbers as they are not a distinct core type)
2150 # cache lookup (which may fail for a non-existent schema) can be bypassed by passing boolean true
2151 2871 ▶sub _type_in_schema ($self, $schema, $state) {
Subroutine _type_in_schema: called CC=28 SCAR=33.4
2152 2871 ▶ return $schema ? (qw(array object boolean string number), $state->{vocabularies}[0] =~ /::OpenAPI_3_0\z/ ? () : 'null') : ('string')
Branch: 3 branches
BranchTrueFalseTotal
if ref $schema ne "HASH" 93 2778 2871
$schema ? : 35 58 93
$$state{'vocabularies'}[0] =~ /::OpenAPI_3_0\z/u ? : 0 35 35
2153 if ref $schema ne 'HASH';
2154  
2155 2778 my $schema_info = $self->evaluator->_fetch_from_uri(my $uri = canonical_uri($state));
2156 2778 ▶ abort($state, 'EXCEPTION: unable to find resource "%s"', $uri) if not $schema_info;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema_info 0 2778 2778
2157  
2158 2778 ▶ if (my $types = ($schema_info->{document}{_type_in_schema}//={})->{$schema_info->{document_path}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $types = ($$schema_info{"document"}{"_type_in_schema"} //= {})->{$$schema_info{"document_path"}}) 1254 1524 2778
Condition100%2/2
$$schema_info{"document"}{"_type_in_schema"} //= {}
l!l
2580198
MC/DC100%1/1
$$schema_info{"document"}{"_type_in_schema"} //= {}
$$schema_info{"document"}{"_type_in_schema"}
Truth table100%2/2
A
A= $$schema_info{"document"}{"_type_in_schema"}
Aresult
11
00
2159 1254 return @$types;
2160 }
2161  
2162 # as in __eval_keyword_id...
2163 1524 ▶ my $id_keyword = $state->{specification_version} eq 'draft4' ? 'id' : '$id';
Branch: 1 branch
BranchTrueFalseTotal
$$state{'specification_version'} eq 'draft4' ? : 15 1509 1524
2164 1524 ▶ if (exists $schema->{$id_keyword} and $schema->{$id_keyword} !~ /^#/) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $$schema{$id_keyword} and not $$schema{$id_keyword} =~ /^#/u) { } 4 1520 1524
elsif (exists $$schema{'$schema'}) { } 4 1516 1520
Condition66%2/3
exists $$schema{$id_keyword} and not $$schema{$id_keyword} =~ /^#/u
!ll&&!rl&&r
152004
MC/DC50%1/2
exists $$schema{$id_keyword} and not $$schema{$id_keyword} =~ /^#/u
exists $$schema{$id_keyword} not $$schema{$id_keyword} =~ /^#/u
Truth table66%2/3
A and not(B)
A= exists $$schema{$id_keyword}B= not $$schema{$id_keyword} =~ /^#/u
ABresult
0X0
100
111
2165 # these will all be correct when we are at the schema root, or if we are here via a $ref,
2166 # but not if we are organically passing through this subschema and pass an '$id'.
2167 4 $state->{initial_schema_uri} = $schema_info->{canonical_uri};
2168 4 $state->{traversed_keyword_path} = $state->{traversed_keyword_path}.$state->{keyword_path};
2169 4 $state->{keyword_path} = '';
2170 4 $state->@{qw(specification_version vocabularies)} = $schema_info->@{qw(specification_version vocabularies)};
2171 push $state->{dynamic_scope}->@*, $state->{initial_schema_uri}
2172 4 ▶ if $state->{dynamic_scope}->[-1] ne $schema_info->{canonical_uri};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"dynamic_scope"}[-1] ne $$schema_info{"canonical_uri"} 0 4 4
2173 }
2174 elsif (exists $schema->{'$schema'}) {
2175 4 $state->@{qw(specification_version vocabularies)} = $self->evaluator->_get_metaschema_vocabulary_classes($schema->{'$schema'})->@*;
2176 }
2177  
2178 1524 my @types;
2179  
2180 1524 ▶ if (defined(my $ref = $schema->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$ref"})) 56 1468 1524
2181 {
2182 56 my $schema = $self->_resolve_ref('schema', $ref, my $state = { %$state });
2183 50 push @types, [ $self->_type_in_schema($schema, $state) ];
2184 }
2185  
2186 # no other keywords are valid adjacent to '$ref' in drafts 4-7
2187 50 ▶ return $types[0]->@* if $state->{specification_version} =~ /^draft[467]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"specification_version"} =~ /^draft[467]\z/u 8 42 50
2188 }
2189  
2190 1510 ▶ if (defined(my $ref = $schema->{'$dynamicRef'}) and $state->{specification_version} !~ /^draft(?:[467]|2019-09)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u) 1 1509 1510
Condition66%2/3
defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
!ll&&!rl&&r
150901
MC/DC50%1/2
defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
defined(my $ref = $$schema{"\$dynamicRef"}) not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
Truth table66%2/3
A and not(B)
A= defined(my $ref = $$schema{"\$dynamicRef"})B= not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
ABresult
0X0
100
111
2191 1 my $schema = $self->_resolve_dynamicRef($ref, my $state = { %$state });
2192 1 push @types, [ $self->_type_in_schema($schema, $state) ];
2193 }
2194  
2195 # v3.2.0 §4.24.4.2: "When inspecting schemas, given a starting point schema, implementations MUST
2196 # examine that schema and all schemas that can be reached from it by following only $ref and allOf
2197 # keywords... When searching schemas for type, if the type keyword’s value is a list of types and
2198 # the serialized value can be successfully parsed as more than one of the types in the list, and
2199 # no other findable type keyword disambiguates the actual required type, the behavior is
2200 # implementation-defined."
2201 # "Schema Objects that do not contain type MUST be considered to allow all types.."
2202  
2203 1510 ▶ if (exists $schema->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$schema{'type'}) { } 1362 148 1510
2204 push @types, [ ref $schema->{type} eq 'ARRAY' ? ($schema->{type}->@*) : ($schema->{type}),
2205 1362 ▶ $state->{vocabularies}[0] =~ /::OpenAPI_3_0\z/ && $schema->{nullable} ? 'null' : () ]
Branch: 2 branches
BranchTrueFalseTotal
ref $$schema{'type'} eq 'ARRAY' ? : 70 1292 1362
$$state{'vocabularies'}[0] =~ /::OpenAPI_3_0\z/u && $$schema{'nullable'} ? : 2 1360 1362
Condition100%3/3
$$state{"vocabularies"}[0] =~ /::OpenAPI_3_0\z/u and $$schema{"nullable"}
!ll&&!rl&&r
135642
MC/DC100%2/2
$$state{"vocabularies"}[0] =~ /::OpenAPI_3_0\z/u and $$schema{"nullable"}
$$state{"vocabularies"}[0] =~ /::OpenAPI_3_0\z/u $$schema{"nullable"}
Truth table100%3/3
A and B
A= $$state{"vocabularies"}[0] =~ /::OpenAPI_3_0\z/uB= $$schema{"nullable"}
ABresult
0X0
100
111
2206 }
2207 else {
2208 push @types, [ qw(array object boolean string number),
2209 148 ▶ $state->{vocabularies}[0] =~ /::OpenAPI_3_0\z/ ? () : 'null' ];
Branch: 1 branch
BranchTrueFalseTotal
$$state{'vocabularies'}[0] =~ /::OpenAPI_3_0\z/u ? : 5 143 148
2210 }
2211  
2212 1510 ▶ push @types, [ get_type($schema->{const}) ] if exists $schema->{const};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"const"} 117 1393 1510
2213  
2214 1510 ▶ push @types, [ map get_type($_), $schema->{enum}->@* ] if exists $schema->{enum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"enum"} 10 1500 1510
2215  
2216 push @types, map [ $self->_type_in_schema($schema->{allOf}[$_],
2217 { %$state, keyword_path => $state->{keyword_path}.'/allOf/'.$_ }) ], 0..$schema->{allOf}->$#*
2218 1510 ▶ if exists $schema->{allOf};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"allOf"} 18 1492 1510
2219  
2220 push @types, [ map $self->_type_in_schema($schema->{anyOf}[$_],
2221 { %$state, keyword_path => $state->{keyword_path}.'/anyOf/'.$_ }), 0..$schema->{anyOf}->$#* ]
2222 1510 ▶ if exists $schema->{anyOf};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"anyOf"} 1 1509 1510
2223  
2224 push @types, [ map $self->_type_in_schema($schema->{oneOf}[$_],
2225 { %$state, keyword_path => $state->{keyword_path}.'/oneOf/'.$_ }), 0..$schema->{oneOf}->$#* ]
2226 1510 ▶ if exists $schema->{oneOf};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"oneOf"} 1 1509 1510
2227  
2228 1510 ▶ if (exists $schema->{not}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$schema{"not"}) 5 1505 1510
2229 5 my %not_types; @not_types{qw(array object boolean string number null)} = ()x6;
2230  
2231 5 delete $not_types{$_} foreach $self->_type_in_schema($schema->{not},
2232 { %$state, keyword_path => $state->{keyword_path}.'/not' });
2233  
2234 5 push @types, [ keys %not_types ];
2235 }
2236  
2237 1510 my @final_types = intersect_types(@types);
2238 1510 $schema_info->{document}{_type_in_schema}{$schema_info->{document_path}} = \@final_types;
2239  
2240 1510 return @final_types;
2241 }
2242  
2243 # given an object, use the subschema for each value to determine the correct type for that value
2244 281 ▶sub _coerce_object_elements ($self, $data, $schema, $state) {
Subroutine _coerce_object_elements: called CC=28 SCAR=33.4
2245 281 ▶ return if ref $data ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "HASH" 3 278 281
2246 278 ▶ return if ref $schema ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $schema ne "HASH" 4 274 278
2247 274 ▶ return if not keys %$data;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$data 31 243 274
2248  
2249 243 ▶ $state->{_level} //= 0;
Condition100%2/2
$$state{"_level"} //= 0
l!l
18225
MC/DC100%1/1
$$state{"_level"} //= 0
$$state{"_level"}
Truth table100%2/2
A
A= $$state{"_level"}
Aresult
11
00
2250 243 my @object_coercions;
2251  
2252 243 ▶ if (defined(my $ref = $schema->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$ref"})) 12 231 243
2253 {
2254 12 my $schema = $self->_resolve_ref('schema', $ref, my $state = { %$state });
2255 12 push @object_coercions, $self->_coerce_object_elements($data, $schema, { %$state, _level => $state->{_level}+1 });
2256 }
2257  
2258 # no other keywords are valid adjacent to '$ref' in drafts 4-7
2259 12 ▶ return $object_coercions[0] if $state->{specification_version} =~ /^draft[467]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"specification_version"} =~ /^draft[467]\z/u 0 12 12
2260 }
2261  
2262 243 ▶ if (defined(my $ref = $schema->{'$dynamicRef'}) and $state->{specification_version} !~ /^draft(?:[467]|2019-09)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u) 1 242 243
Condition66%2/3
defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
!ll&&!rl&&r
24201
MC/DC50%1/2
defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
defined(my $ref = $$schema{"\$dynamicRef"}) not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
Truth table66%2/3
A and not(B)
A= defined(my $ref = $$schema{"\$dynamicRef"})B= not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
ABresult
0X0
100
111
2263 1 my $schema = $self->_resolve_dynamicRef($ref, my $state = { %$state });
2264 1 push @object_coercions, $self->_coerce_object_elements($data, $schema, { %$state, _level => $state->{_level}+1 });
2265 }
2266  
2267 243 ▶ if (exists $schema->{allOf}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$schema{"allOf"}) 2 241 243
2268 2 foreach my $idx (0..$schema->{allOf}->$#*) {
2269 push @object_coercions, $self->_coerce_object_elements($data, $schema->{allOf}[$idx],
2270 5 { %$state, _level => $state->{_level}+1, keyword_path => $state->{keyword_path}.'/allOf/'.$idx });
2271 }
2272 }
2273  
2274 # we do not support anyOf, oneOf etc here to combine the sets of property constraints, as the work
2275 # involved in resolving ambiguities for each subschema as its own dataset is too great.
2276  
2277 243 my $property_coercions = {};
2278 243 foreach my $property (sort keys $data->%*) {
2279 657 ▶ next if ref $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$data{$property} 2 655 657
2280 655 my @types;
2281 655 my $state = { %$state, data_path => jsonp($state->{data_path}, $property) };
2282  
2283 push @types, [ $self->_type_in_schema($schema->{properties}{$property},
2284 { %$state, keyword_path => jsonp($state->{keyword_path}, 'properties', $property) }) ]
2285 655 ▶ if exists(($schema->{properties}//{})->{$property});
Branch: 1 branch
BranchTrueFalseTotal
if exists(($$schema{"properties"} // {})->{$property}) 94 561 655
Condition100%2/2
$$schema{"properties"} // {}
l!l
126529
MC/DC100%1/1
$$schema{"properties"} // {}
$$schema{"properties"}
Truth table100%2/2
A
A= $$schema{"properties"}
Aresult
11
00
2286  
2287 push @types, [ $self->_type_in_schema($schema->{patternProperties},
2288 { %$state, keyword_path => $state->{keyword_path}.'/patternProperties' }) ]
2289 655 ▶ if exists $schema->{patternProperties} and $property =~ m/$schema->{patternProperties}/;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"patternProperties"} and $property =~ /$$schema{"patternProperties"}/u 0 655 655
Condition66%2/3
exists $$schema{"patternProperties"} and $property =~ /$$schema{"patternProperties"}/u
!ll&&!rl&&r
644110
MC/DC0%0/2
exists $$schema{"patternProperties"} and $property =~ /$$schema{"patternProperties"}/u
exists $$schema{"patternProperties"} $property =~ /$$schema{"patternProperties"}/u
Truth table66%2/3
A and B
A= exists $$schema{"patternProperties"}B= $property =~ /$$schema{"patternProperties"}/u
ABresult
0X0
100
111
2290  
2291 push @types, [ $self->_type_in_schema($schema->{additionalProperties},
2292 { %$state, keyword_path => $state->{keyword_path}.'/additionalProperties' }) ]
2293 655 ▶ if exists $schema->{additionalProperties} and @types == 0;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"additionalProperties"} and @types == 0 51 604 655
Condition100%3/3
exists $$schema{"additionalProperties"} and @types == 0
!ll&&!rl&&r
5921251
MC/DC100%2/2
exists $$schema{"additionalProperties"} and @types == 0
exists $$schema{"additionalProperties"} @types == 0
Truth table100%3/3
A and B
A= exists $$schema{"additionalProperties"}B= @types == 0
ABresult
0X0
100
111
2294  
2295 653 ▶ if (@types) {
Branch: 1 branch
BranchTrueFalseTotal
if (@types) 143 510 653
2296 143 $property_coercions->{$property} = [ intersect_types(@types) ];
2297 }
2298 }
2299  
2300 241 push @object_coercions, $property_coercions;
2301  
2302 # combine hashes together by performing an intersection of types for each individual property
2303 # consider unevaluatedProperties now for each property that doesn't have representation already.
2304 241 my %final_object_coercions;
2305 241 foreach my $property (sort keys $data->%*) {
2306 655 ▶ next if ref $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$data{$property} 2 653 655
2307 653 ▶ if (my @property_coercions = map $_->{$property} // (), @object_coercions) {
Branch: 2 branches
BranchTrueFalseTotal
if (my(@property_coercions) = map(($our $_{$property} // ()), @object_coercions)) { } 189 464 653
elsif (exists $$schema{'unevaluatedProperties'}) { } 4 460 464
Condition66%2/3
$our $_{$property} // ()
l!l&&r!l&&!r
1975210
MC/DC0%0/2
$our $_{$property} // ()
$our $_{$property} ()
Truth table66%2/3
A // B
A= $our $_{$property}B= ()
ABresult
1X1
011
000
2308 189 ▶ $final_object_coercions{$property} = [ intersect_types(map $_->{$property} // (), @object_coercions) ];
Condition66%2/3
$our $_{$property} // ()
l!l&&r!l&&!r
197540
MC/DC0%0/2
$our $_{$property} // ()
$our $_{$property} ()
Truth table66%2/3
A // B
A= $our $_{$property}B= ()
ABresult
1X1
011
000
2309 }
2310 elsif (exists $schema->{unevaluatedProperties}) {
2311 $final_object_coercions{$property} = [ $self->_type_in_schema($schema->{unevaluatedProperties},
2312 4 { %$state, keyword_path => $state->{keyword_path}.'/unevaluatedProperties' }) ];
2313 }
2314 }
2315  
2316 241 ▶ return \%final_object_coercions if delete $state->{_level}; # unwind the recursion by one level
Branch: 1 branch
BranchTrueFalseTotal
if delete $$state{"_level"} 18 223 241
2317  
2318 # we are at the top of the recursion stack.
2319 223 foreach my $property (keys %final_object_coercions) {
2320 # incoercible elements will be left as-is
2321 139 coerce_primitive(\$data->{$property}, $final_object_coercions{$property});
2322 }
2323 }
2324  
2325 # given an array, use the subschema for each item to determine the correct type for that value
2326 252 ▶sub _coerce_array_elements ($self, $data, $schema, $state) {
Subroutine _coerce_array_elements: called CC=28 SCAR=33.4
2327 252 ▶ return if ref $data ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "ARRAY" 3 249 252
2328 249 ▶ return if ref $schema ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $schema ne "HASH" 2 247 249
2329 247 ▶ return if not @$data;
Branch: 1 branch
BranchTrueFalseTotal
unless @$data 28 219 247
2330  
2331 219 ▶ $state->{_level} //= 0;
Condition100%2/2
$$state{"_level"} //= 0
l!l
26193
MC/DC100%1/1
$$state{"_level"} //= 0
$$state{"_level"}
Truth table100%2/2
A
A= $$state{"_level"}
Aresult
11
00
2332 219 my @array_coercions;
2333  
2334 219 ▶ if (defined(my $ref = $schema->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$ref"})) 18 201 219
2335 {
2336 18 my $schema = $self->_resolve_ref('schema', $ref, my $state = { %$state });
2337 18 push @array_coercions, $self->_coerce_array_elements($data, $schema, { %$state, _level => $state->{_level}+1 });
2338 }
2339  
2340 # no other keywords are valid adjacent to '$ref' in drafts 4-7
2341 18 ▶ return $array_coercions[0] if $state->{specification_version} =~ /^draft[467]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"specification_version"} =~ /^draft[467]\z/u 0 18 18
2342 }
2343  
2344 219 ▶ if (defined(my $ref = $schema->{'$dynamicRef'}) and $state->{specification_version} !~ /^draft(?:[467]|2019-09)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u) 1 218 219
Condition66%2/3
defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
!ll&&!rl&&r
21801
MC/DC50%1/2
defined(my $ref = $$schema{"\$dynamicRef"}) and not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
defined(my $ref = $$schema{"\$dynamicRef"}) not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
Truth table66%2/3
A and not(B)
A= defined(my $ref = $$schema{"\$dynamicRef"})B= not $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u
ABresult
0X0
100
111
2345 1 my $schema = $self->_resolve_dynamicRef($ref, my $state = { %$state });
2346 1 push @array_coercions, $self->_coerce_array_elements($data, $schema, { %$state, _level => $state->{_level}+1 });
2347 }
2348  
2349 219 ▶ if (exists $schema->{allOf}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$schema{"allOf"}) 4 215 219
2350 4 foreach my $idx (0..$schema->{allOf}->$#*) {
2351 push @array_coercions, $self->_coerce_array_elements($data, $schema->{allOf}[$idx],
2352 9 { %$state, _level => $state->{_level}+1, keyword_path => $state->{keyword_path}.'/allOf/'.$idx });
2353 }
2354 }
2355  
2356 # we do not support anyOf, oneOf etc here to combine the sets of property constraints, as the work
2357 # involved in resolving ambiguities for each subschema as its own dataset is too great.
2358  
2359 219 my $item_coercions = [];
2360 219 foreach my $idx (0..$data->$#*) {
2361 620 ▶ next if ref $data->[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if ref $$data[$idx] 2 618 620
2362 618 my @types;
2363 618 my $state = { %$state, data_path => $state->{data_path}.'/'.$idx };
2364  
2365 618 ▶ my ($array_items, $schema_items) = $state->{specification_version} !~ /^draft(?:[467]|2019-09)\z/
Branch: 1 branch
BranchTrueFalseTotal
!($$state{'specification_version'} =~ /^draft(?:[467]|2019-09)\z/u) ? : 618 0 618
2366 ? qw(prefixItems items)
2367 : qw(items additionalItems);
2368  
2369 push @types, [ $self->_type_in_schema($schema->{$array_items}[$idx],
2370 { %$state, keyword_path => $state->{keyword_path}.'/'.$array_items.'/'.$idx }) ]
2371 618 ▶ if exists $schema->{$array_items} and $idx <= $schema->{$array_items}->$#*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{$array_items} and $idx <= $$schema{$array_items}->$#* 86 532 618
Condition100%3/3
exists $$schema{$array_items} and $idx <= $$schema{$array_items}->$#*
!ll&&!rl&&r
4983486
MC/DC100%2/2
exists $$schema{$array_items} and $idx <= $$schema{$array_items}->$#*
exists $$schema{$array_items} $idx <= $$schema{$array_items}->$#*
Truth table100%3/3
A and B
A= exists $$schema{$array_items}B= $idx <= $$schema{$array_items}->$#*
ABresult
0X0
100
111
2372  
2373 push @types, [ $self->_type_in_schema($schema->{$schema_items},
2374 { %$state, keyword_path => $state->{keyword_path}.'/'.$schema_items }) ]
2375 618 ▶ if exists $schema->{$schema_items} and @types == 0;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{$schema_items} and @types == 0 96 522 618
Condition100%3/3
exists $$schema{$schema_items} and @types == 0
!ll&&!rl&&r
5031996
MC/DC100%2/2
exists $$schema{$schema_items} and @types == 0
exists $$schema{$schema_items} @types == 0
Truth table100%3/3
A and B
A= exists $$schema{$schema_items}B= @types == 0
ABresult
0X0
100
111
2376  
2377 618 ▶ if (@types) {
Branch: 1 branch
BranchTrueFalseTotal
if (@types) 182 436 618
2378 182 $item_coercions->[$idx] = [ intersect_types(@types) ];
2379 }
2380 }
2381  
2382 219 push @array_coercions, $item_coercions;
2383  
2384 # combine arrayrefs together by performing an intersection of types for each individual item
2385 # consider unevaluatedItems now for each property that doesn't have representation already.
2386 219 my @final_array_coercions;
2387 219 foreach my $idx (0..$data->$#*) {
2388 620 ▶ next if ref $data->[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if ref $$data[$idx] 2 618 620
2389 618 ▶ if (my @item_coercions = map $_->[$idx] // (), @array_coercions) {
Branch: 2 branches
BranchTrueFalseTotal
if (my(@item_coercions) = map(($our $_[$idx] // ()), @array_coercions)) { } 247 371 618
elsif (exists $$schema{'unevaluatedItems'}) { } 3 368 371
Condition66%2/3
$our $_[$idx] // ()
l!l&&r!l&&!r
2594460
MC/DC0%0/2
$our $_[$idx] // ()
$our $_[$idx] ()
Truth table66%2/3
A // B
A= $our $_[$idx]B= ()
ABresult
1X1
011
000
2390 247 ▶ $final_array_coercions[$idx] = [ intersect_types(map $_->[$idx] // (), @array_coercions) ];
Condition66%2/3
$our $_[$idx] // ()
l!l&&r!l&&!r
259690
MC/DC0%0/2
$our $_[$idx] // ()
$our $_[$idx] ()
Truth table66%2/3
A // B
A= $our $_[$idx]B= ()
ABresult
1X1
011
000
2391 }
2392 elsif (exists $schema->{unevaluatedItems}) {
2393 $final_array_coercions[$idx] = [ $self->_type_in_schema($schema->{unevaluatedItems},
2394 3 { %$state, keyword_path => $state->{keyword_path}.'/unevaluatedItems' }) ];
2395 }
2396 }
2397  
2398 219 ▶ return \@final_array_coercions if delete $state->{_level}; # unwind the recursion by one level
Branch: 1 branch
BranchTrueFalseTotal
if delete $$state{"_level"} 26 193 219
2399  
2400 # we are at the top of the recursion stack.
2401 193 foreach my $idx (0..$data->$#*) {
2402 # incoercible elements will be left as-is
2403 532 ▶ coerce_primitive(\$data->[$idx], $final_array_coercions[$idx])
Branch: 1 branch
BranchTrueFalseTotal
if defined $final_array_coercions[$idx] 173 359 532
2404 if defined $final_array_coercions[$idx];
2405 }
2406 }
2407  
2408 # evaluates data against the subschema at the current state location
2409 892 ▶sub _evaluate_subschema ($self, $dataref, $schema, $state) {
Subroutine _evaluate_subschema: called CC=17 SCAR=28.5
2410 # boolean schema
2411 892 ▶ if (ref $schema ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema ne "HASH") 65 827 892
2412 65 ▶ return 1 if $schema;
Branch: 1 branch
BranchTrueFalseTotal
if $schema 30 35 65
2413  
2414 35 my @location = unjsonp($state->{data_path});
2415 35 ▶ my $location =
Branch: 7 branches
BranchTrueFalseTotal
$location[-1] eq 'content' ? : 6 29 35
$location[-1] =~ /^[0-9]+\z/u ? : 4 25 29
$location[-2] eq 'query' ? : 4 21 25
$location[-2] eq 'path' ? : 4 17 21
$location[-2] eq 'header' ? : 11 6 17
$location[-3] eq 'header' && $location[-2] eq 'Cookie' ? : 4 2 6
$location[-1] eq 'query' ? : 2 0 2
Condition66%2/3
$location[-3] eq "header" and $location[-2] eq "Cookie"
!ll&&!rl&&r
204
MC/DC50%1/2
$location[-3] eq "header" and $location[-2] eq "Cookie"
$location[-3] eq "header" $location[-2] eq "Cookie"
Truth table66%2/3
A and B
A= $location[-3] eq "header"B= $location[-2] eq "Cookie"
ABresult
0X0
100
111
2416 $location[-1] eq 'content' ? join(' ', @location[-3..-2]) # request|response body
2417 : $location[-1] =~ /^[0-9]+\z/ ? 'item' # body item
2418 : $location[-2] eq 'query' ? 'query parameter' # query
2419 : $location[-2] eq 'path' ? 'path parameter' # path
2420 : $location[-2] eq 'header' ? join(' ', @location[-3..-2]) # header
2421 : $location[-3] eq 'header' && $location[-2] eq 'Cookie' ? 'cookie parameter' # cookie
2422 : $location[-1] eq 'query' ? 'query parameter' # querystring
2423 : die 'unknown location';
2424 35 return E($state, '%s not permitted', $location);
2425 }
2426  
2427 827 ▶ return 1 if !keys(%$schema); # schema is {}
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$schema 16 811 827
2428  
2429 # this is not necessarily the canonical uri of the location, but it is still a valid location
2430 811 my $uri = $state->{initial_schema_uri}->clone;
2431 811 ▶ $uri->fragment(($uri->fragment//'').$state->{keyword_path});
Condition100%2/2
$uri->fragment // ""
l!l
82729
MC/DC100%1/1
$uri->fragment // ""
$uri->fragment
Truth table100%2/2
A
A= $uri->fragment
Aresult
11
00
2432  
2433 my $result = $self->evaluator->evaluate(
2434 $dataref->$*,
2435 # reference by uri ensures all schema information is available to the evaluator, e.g. dialect
2436 $uri,
2437 {
2438 data_path => $state->{data_path},
2439 traversed_keyword_path => $state->{traversed_keyword_path}.$state->{keyword_path},
2440 $state->{stringy_numbers} ? (stringy_numbers => 1) : (),
2441 811 ▶ $state->{with_defaults} ? (with_defaults => 1) : (),
Branch: 2 branches
BranchTrueFalseTotal
$$state{'stringy_numbers'} ? : 0 811 811
$$state{'with_defaults'} ? : 0 811 811
2442 },
2443 );
2444  
2445 811 push $state->{errors}->@*, $result->errors;
2446 811 push $state->{annotations}->@*, $result->annotations;
2447  
2448 811 jsonp_set($state->{data}, $state->{data_path}, jsonp_get($result->data, $state->{data_path}));
2449  
2450 $state->{defaults}->%* = (
2451 $state->{defaults}->%*, $result->defaults->%*
2452 811 ▶ ) if $state->{defaults} and $result->defaults;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"defaults"} and $result->defaults 62 749 811
Condition66%2/3
$$state{"defaults"} and $result->defaults
!ll&&!rl&&r
749062
MC/DC50%1/2
$$state{"defaults"} and $result->defaults
$$state{"defaults"} $result->defaults
Truth table66%2/3
A and B
A= $$state{"defaults"}B= $result->defaults
ABresult
0X0
100
111
2453  
2454 811 return $result->valid;
2455 }
2456  
2457 # callback hook for Sereal::Encoder
2458 1 ▶sub FREEZE ($self, $serializer) { +{ %$self } }
Subroutine FREEZE: called CC=1 SCAR=0.0
Pod undocumented
2459  
2460 # callback hook for Sereal::Decoder
2461 2 ▶sub THAW ($class, $serializer, $data) {
Subroutine THAW: called CC=5 SCAR=16.3
Pod undocumented
2462 2 my $self = bless($data, $class);
2463  
2464 $self->{openapi_documents} = [ delete $self->{openapi_document} ]
2465 2 ▶ if exists $self->{openapi_document};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$self{"openapi_document"} 0 2 2
2466  
2467 2 foreach my $attr (qw(evaluator openapi_documents)) {
2468 croak "serialization missing attribute '$attr': perhaps your serialized data was produced for an older version of $class?"
2469 4 ▶ if not exists $self->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$self{$attr} 0 4 4
2470 }
2471  
2472 my @versions = uniq map $_->oas_version,
2473 grep $_->isa('JSON::Schema::Modern::Document::OpenAPI'),
2474 map $_->{document},
2475 2 $self->evaluator->_canonical_resources;
2476  
2477 2 delete $self->evaluator->@{ grep /^__openapi_/, keys $self->evaluator->%* };
2478 2 add_formats($self->evaluator, $_) foreach @versions;
2479  
2480 2 return $self;
2481 }
2482  
2483 18 1;
2484  
2485 __END__
« JSON/Schema/Modern/Document/OpenAPI.pm ↑ Summary JSON/Schema/Modern/Vocabulary/OpenAPI_3_0.pm »