| 1 | package JSON::Validator::Schema::OpenAPIv3; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use Mojo::Base 'JSON::Validator::Schema::Draft201909'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use JSON::Validator::Util qw(E data_type negotiate_content_type schema_type); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Mojo::JSON qw(false true); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Mojo::Path; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | has moniker => 'openapiv3'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | has specification => 'https://spec.openapis.org/oas/3.0/schema/2021-09-28'; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | require JSON::Validator::Schema::OpenAPIv2; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | *coerce = \&JSON::Validator::Schema::OpenAPIv2::coerce; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | *errors = \&JSON::Validator::Schema::OpenAPIv2::errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | *routes = \&JSON::Validator::Schema::OpenAPIv2::routes; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | *validate_request = \&JSON::Validator::Schema::OpenAPIv2::validate_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | *validate_response = \&JSON::Validator::Schema::OpenAPIv2::validate_response; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | *_coerce_arrays = \&JSON::Validator::Schema::OpenAPIv2::_coerce_arrays; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | *_coerce_default_value = \&JSON::Validator::Schema::OpenAPIv2::_coerce_default_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | *_find_all_nodes = \&JSON::Validator::Schema::OpenAPIv2::_find_all_nodes; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | *_params_for_add_default_response = \&JSON::Validator::Schema::OpenAPIv2::_params_for_add_default_response; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 11 | *_prefix_error_path = \&JSON::Validator::Schema::OpenAPIv2::_prefix_error_path; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | *_validate_request_or_response = \&JSON::Validator::Schema::OpenAPIv2::_validate_request_or_response; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub add_default_response { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_default_response: called CC=8 SCAR=21.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my ($self, $params) = ($_[0], shift->_params_for_add_default_response(@_)); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | my $schemas = $self->data->{components}{schemas} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->data->{"components"}{"schemas"} ||= {}
MC/DC0%0/1
$self->data->{"components"}{"schemas"} ||= {}
$self->data->{"components"}{"schemas"}
Truth table50%1/2
A
A= $self->data->{"components"}{"schemas"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | $schemas->{$params->{name}} ||= $params->{schema}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$schemas{$params->{"name"}} ||= $params->{"schema"}
MC/DC0%0/2
$$schemas{$params->{"name"}} ||= $params->{"schema"}
$$schemas{$params->{"name"}}
$params->{"schema"}
Truth table33%1/3
A ||= B
A= $$schemas{$params->{"name"}}B= $params->{"schema"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | my $ref = {'$ref' => "#/components/schemas/$params->{name}"}; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | $self->_register_ref($ref, schema => $schemas->{$params->{name}}); | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | for my $route ($self->routes->each) { | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | my $op = $self->get([paths => @$route{qw(path method)}]); | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | for my $status (@{$params->{status}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 20 | ▶ | next if $self->get(['paths', @$route{qw(path method)}, 'responses', $status]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 18 | ▶ | $op->{responses}{$status}{content}{'application/json'} //= {schema => $ref}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$op->{"responses"}{$status}{"content"}{"application/json"} //= {"schema", $ref}
MC/DC0%0/1
$op->{"responses"}{$status}{"content"}{"application/json"} //= {"schema", $ref}
$op->{"responses"}{$status}{"content"}{"application/json"}
Truth table50%1/2
A
A= $op->{"responses"}{$status}{"content"}{"application/json"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 18 | ▶ | $op->{responses}{$status}{description} //= $params->{description}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$op->{"responses"}{$status}{"description"} //= $params->{"description"}
MC/DC0%0/2
$op->{"responses"}{$status}{"description"} //= $params->{"description"}
$op->{"responses"}{$status}{"description"}
$params->{"description"}
Truth table33%1/3
A //= B
A= $op->{"responses"}{$status}{"description"}B= $params->{"description"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | ▶ | sub base_url { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base_url: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | my ($self, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Get | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | ▶ | return Mojo::URL->new($self->get('/servers/0/url') || '') unless $url; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->get('/servers/0/url') || ''
MC/DC0%0/1
$self->get('/servers/0/url') || ''
$self->get('/servers/0/url')
Truth table50%1/2
A
A= $self->get('/servers/0/url')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Set | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | $url = Mojo::URL->new($url)->to_abs($self->base_url); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | $self->data->{servers}[0]{url} = $url->to_string; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1027 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1027 | my $self = shift->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1027 | $self->coerce; # make sure this attribute is built | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1027 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 97 | ▶ | sub parameters_for_request { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parameters_for_request: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 97 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 97 | my ($method, $path) = (lc $_[0][0], $_[0][1]); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 97 | my $cache_key = "parameters_for_request:$method:$path"; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 97 | ▶ | return $self->{cache}{$cache_key} if $self->{cache}{$cache_key}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 27 | ▶ | return undef unless $self->get([paths => $path, $method]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 26 | my @parameters = map {@$_} $self->_find_all_nodes([paths => $path, $method], 'parameters'); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 26 | ▶ | if (my $request_body = $self->get([paths => $path, $method, 'requestBody'])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | ▶ | my @accepts = sort keys %{$request_body->{content} || {}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$request_body->{'content'} || {}
MC/DC0%0/1
$request_body->{'content'} || {}
$request_body->{'content'}
Truth table50%1/2
A
A= $request_body->{'content'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | push @parameters, | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | accepts => \@accepts, | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | content => $request_body->{content}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | in => 'body', | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | name => 'body', | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | required => $request_body->{required}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 26 | return $self->{cache}{$cache_key} = \@parameters; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 23 | ▶ | sub parameters_for_response { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parameters_for_response: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | ▶ | my ($method, $path, $status) = (lc $_[0][0], $_[0][1], $_[0][2] || 200); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[0][2] || 200
MC/DC100%1/1
$_[0][2] || 200
$_[0][2]
Truth table100%2/2
A
A= $_[0][2]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 23 | ▶ | $status ||= 200; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$status ||= 200
MC/DC0%0/1
$status ||= 200
$status
Truth table50%1/2
A
A= $status
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | my $cache_key = "parameters_for_response:$method:$path:$status"; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 23 | ▶ | return $self->{cache}{$cache_key} if $self->{cache}{$cache_key}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 11 | ▶ | my $response = $self->get([paths => $path, $method, 'responses', $status]) | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->get(['paths', $path, $method, 'responses', $status]) || $self->get(['paths', $path, $method, 'responses', 'default'])
MC/DC100%2/2
$self->get(['paths', $path, $method, 'responses', $status]) || $self->get(['paths', $path, $method, 'responses', 'default'])
$self->get(['paths', $path, $method, 'responses', $status])
$self->get(['paths', $path, $method, 'responses', 'default'])
Truth table100%3/3
A || B
A= $self->get(['paths', $path, $method, 'responses', $status])B= $self->get(['paths', $path, $method, 'responses', 'default'])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | || $self->get([paths => $path, $method, 'responses', 'default']); | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 11 | ▶ | return undef unless $response; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 10 | my @parameters; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 10 | ▶ | if (my $headers = $response->{headers}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | push @parameters, map { +{%{$headers->{$_}}, in => 'header', name => $_} } sort keys %$headers; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 10 | ▶ | if (my @accepts = sort keys %{$response->{content} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$response->{'content'} || {}
MC/DC0%0/1
$response->{'content'} || {}
$response->{'content'}
Truth table50%1/2
A
A= $response->{'content'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 10 | push @parameters, {accepts => \@accepts, content => $response->{content}, in => 'body', name => 'body'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 10 | return $self->{cache}{$cache_key} = \@parameters; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | sub _build_formats { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_formats: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # TODO: Figure out if this is the correct list | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | return { | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | 'binary' => sub {undef}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 'byte' => JSON::Validator::Formats->can('check_byte'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 'date' => JSON::Validator::Formats->can('check_date'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 'date-time' => JSON::Validator::Formats->can('check_date_time'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 'double' => JSON::Validator::Formats->can('check_double'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 'duration' => JSON::Validator::Formats->can('check_duration'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 'email' => JSON::Validator::Formats->can('check_email'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 'float' => JSON::Validator::Formats->can('check_float'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 'hostname' => JSON::Validator::Formats->can('check_hostname'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 'idn-email' => JSON::Validator::Formats->can('check_idn_email'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 'idn-hostname' => JSON::Validator::Formats->can('check_idn_hostname'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 'int32' => JSON::Validator::Formats->can('check_int32'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'int64' => JSON::Validator::Formats->can('check_int64'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 'ipv4' => JSON::Validator::Formats->can('check_ipv4'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 'ipv6' => JSON::Validator::Formats->can('check_ipv6'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 'iri' => JSON::Validator::Formats->can('check_iri'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 'iri-reference' => JSON::Validator::Formats->can('check_iri_reference'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 'json-pointer' => JSON::Validator::Formats->can('check_json_pointer'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | 'password' => sub {undef}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | 'regex' => JSON::Validator::Formats->can('check_regex'), | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 'relative-json-pointer' => JSON::Validator::Formats->can('check_relative_json_pointer'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 'time' => JSON::Validator::Formats->can('check_time'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 'uri' => JSON::Validator::Formats->can('check_uri'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 'uri-reference' => JSON::Validator::Formats->can('check_uri_reference'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 'uri-template' => JSON::Validator::Formats->can('check_uri_template'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 'uuid' => JSON::Validator::Formats->can('check_uuid'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub _bundle_ref_path_expand { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bundle_ref_path_expand: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my ($self, $schema, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | return $ref =~ m!\bcomponents/([^/]+)/(.+)! ? ('components', $1, $2) : ('components', 'schemas', $ref); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 110 | ▶ | sub _coerce_parameter_format { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_parameter_format: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 110 | my ($self, $val, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 110 | ▶ | return unless $val->{exists}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 58 | state $in_style = {cookie => 'form', header => 'simple', path => 'simple', query => 'form'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 58 | ▶ | $param->{style} = $in_style->{$param->{in}} unless $param->{style}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 58 | ▶ | return $self->_coerce_parameter_style_object_deep($val, $param) if +($param->{style} // '') eq 'deepObject'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$param->{"style"} // ""
MC/DC0%0/1
$param->{"style"} // ""
$param->{"style"}
Truth table50%1/2
A
A= $param->{"style"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 47 | my $schema_type = schema_type $param->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 47 | ▶ | return $self->_coerce_parameter_style_array($val, $param) if $schema_type eq 'array'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 28 | ▶ | return $self->_coerce_parameter_style_object($val, $param) if $schema_type eq 'object'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 19 | ▶ | sub _coerce_parameter_style_array { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_parameter_style_array: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 19 | my ($self, $val, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 19 | my $style = $param->{style}; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 19 | ▶ | my $explode = $param->{explode} // $param->{style} eq 'form' ? true : false; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$param->{"explode"} // $param->{"style"} eq "form"
MC/DC100%1/1
$param->{"explode"} // $param->{"style"} eq "form"
$param->{"explode"}
Truth table100%2/2
A
A= $param->{"explode"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 19 | my $re; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 19 | ▶ | if ($style =~ m!^(form|pipeDelimited|spaceDelimited|simple)$!) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 11 | ▶ | return $val->{value} = ref $val->{value} eq 'ARRAY' ? $val->{value} : [$val->{value}] if $explode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | $re = $style eq 'pipeDelimited' ? qr{\|} : $style eq 'spaceDelimited' ? $re = qr{[ ]} : qr{,}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif ($style eq 'label') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | $re = qr{\.}; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | $re = qr{,} if $val->{value} =~ s/^$re// and !$explode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val->{"value"} =~ s/^$re//u and not $explode
MC/DC100%2/2
$val->{"value"} =~ s/^$re//u and not $explode
$val->{"value"} =~ s/^$re//u
not $explode
Truth table100%3/3
A and not(B)
A= $val->{"value"} =~ s/^$re//uB= not $explode
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | elsif ($style eq 'matrix') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | $re = qr{;\Q$param->{name}\E=}; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | $re = qr{,} if $val->{value} =~ s/^$re// and !$explode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$val->{"value"} =~ s/^$re//u and not $explode
MC/DC50%1/2
$val->{"value"} =~ s/^$re//u and not $explode
$val->{"value"} =~ s/^$re//u
not $explode
Truth table66%2/3
A and not(B)
A= $val->{"value"} =~ s/^$re//uB= not $explode
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 12 | return $val->{value} = [_split($re, $val->{value})]; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 24 | ▶ | sub _coerce_parameter_style_object { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_parameter_style_object: called CC=16 SCAR=30.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 24 | my ($self, $val, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 24 | my $style = $param->{style}; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my $explode = $param->{explode} // (grep { $style eq $_ } qw(cookie query)) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$param->{"explode"} // grep({$style eq $_;} "cookie", "query")
MC/DC0%0/2
$param->{"explode"} // grep({$style eq $_;} "cookie", "query")
$param->{"explode"}
grep({$style eq $_;} "cookie", "query")
Truth table33%1/3
A // B
A= $param->{"explode"}B= grep({$style eq $_;} "cookie", "query")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 24 | ▶ | if ($explode) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 15 | ▶ | return $self->_coerce_parameter_style_object_form($val, $param) if $style eq 'form'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | state $style_re = {label => qr{\.}, matrix => qr{;}, simple => qr{,}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | ▶ | return unless my $re = $style_re->{$style}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | ▶ | return if $style eq 'matrix' && $val->{value} !~ s/^;//; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$style eq "matrix" and not $val->{"value"} =~ s/^;//u
MC/DC0%0/2
$style eq "matrix" and not $val->{"value"} =~ s/^;//u
$style eq "matrix"
not $val->{"value"} =~ s/^;//u
Truth table66%2/3
A and not(B)
A= $style eq "matrix"B= not $val->{"value"} =~ s/^;//u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | ▶ | return if $style eq 'label' && $val->{value} !~ s/^\.//; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$style eq "label" and not $val->{"value"} =~ s/^\.//u
MC/DC0%0/2
$style eq "label" and not $val->{"value"} =~ s/^\.//u
$style eq "label"
not $val->{"value"} =~ s/^\.//u
Truth table66%2/3
A and not(B)
A= $style eq "label"B= not $val->{"value"} =~ s/^\.//u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | my $params = Mojo::Parameters->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | $params->append(Mojo::Parameters->new($_)) for _split($re, $val->{value}); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 3 | return $val->{value} = $params->to_hash; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 9 | state $style_re = { | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | form => qr{,}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | label => qr{\.}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | matrix => qr{,}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | pipeDelimited => qr{\|}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | simple => qr{,}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | spaceDelimited => qr{[ ]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 9 | ▶ | return unless my $re = $style_re->{$style}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 9 | ▶ | return if $style eq 'matrix' && $val->{value} !~ s/^;\Q$param->{name}\E=//; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$style eq "matrix" and not $val->{"value"} =~ s/^;\Q$param->{"name"}\E=//u
MC/DC0%0/2
$style eq "matrix" and not $val->{"value"} =~ s/^;\Q$param->{"name"}\E=//u
$style eq "matrix"
not $val->{"value"} =~ s/^;\Q$param->{"name"}\E=//u
Truth table66%2/3
A and not(B)
A= $style eq "matrix"B= not $val->{"value"} =~ s/^;\Q$param->{"name"}\E=//u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | ▶ | return if $style eq 'label' && $val->{value} !~ s/^\.//; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$style eq "label" and not $val->{"value"} =~ s/^\.//u
MC/DC0%0/2
$style eq "label" and not $val->{"value"} =~ s/^\.//u
$style eq "label"
not $val->{"value"} =~ s/^\.//u
Truth table66%2/3
A and not(B)
A= $style eq "label"B= not $val->{"value"} =~ s/^\.//u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | return $val->{value} = Mojo::Parameters->new->pairs([_split($re, $val->{value})])->to_hash; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 11 | ▶ | sub _coerce_parameter_style_object_deep { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_parameter_style_object_deep: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 11 | my ($self, $val, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 11 | my %res; | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 11 | for my $k (keys %{$val->{value}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 15 | ▶ | next unless $k =~ /^\Q$param->{name}\E\[(.*)\]/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 9 | my @path = $k =~ m!\[([^]]*)\]!g; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | 9 | ▶ | my $values = ref $val->{value}{$k} eq 'ARRAY' ? $val->{value}{$k} : [$val->{value}{$k}]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 9 | my $node = \%res; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | ▶ | while (defined(my $p = shift @path)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 17 | ▶ | if (@path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 8 | ▶ | my $next = $path[0] =~ m!^(|\d+)$! ? [] : {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | ▶ | $node = ref $node eq 'ARRAY' ? ($node->[$p] ||= $next) : ($node->{$p} ||= $next); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$node->[$p] ||= $next
$node->{$p} ||= $next
MC/DC0%0/2
$node->[$p] ||= $next
$node->[$p]
$next
MC/DC0%0/2
$node->{$p} ||= $next
$node->{$p}
$next
Truth table33%1/3
A ||= B
A= $node->[$p]B= $next
Truth table66%2/3
A ||= B
A= $node->{$p}B= $next
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | elsif ($p eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | @$node = @$values; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | elsif ($p =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | $node->[$p] = $values->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | ▶ | $node->{$p} = @$values > 1 ? $values : $values->[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 11 | ▶ | return $val->{value} = \%res if %res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 6 | return $val->{exists} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 12 | ▶ | sub _coerce_parameter_style_object_form { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_parameter_style_object_form: called CC=8 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 12 | my ($self, $val, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | 12 | ▶ | return unless my $properties = $param->{schema} && $param->{schema}{properties}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$param->{'schema'} && $param->{'schema'}{'properties'}
MC/DC0%0/2
$param->{'schema'} && $param->{'schema'}{'properties'}
$param->{'schema'}
$param->{'schema'}{'properties'}
Truth table33%1/3
A && B
A= $param->{'schema'}B= $param->{'schema'}{'properties'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 12 | for my $k (keys %{$val->{value}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 15 | ▶ | next unless my $type = $properties->{$k} && $properties->{$k}{type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$properties->{$k} && $properties->{$k}{'type'}
MC/DC50%1/2
$properties->{$k} && $properties->{$k}{'type'}
$properties->{$k}
$properties->{$k}{'type'}
Truth table66%2/3
A && B
A= $properties->{$k}B= $properties->{$k}{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | ▶ | $val->{value}{$k} = [$val->{value}{$k}] if $type eq 'array' and ref $val->{value}{$k} ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "array" and ref $val->{"value"}{$k} ne "ARRAY"
MC/DC0%0/2
$type eq "array" and ref $val->{"value"}{$k} ne "ARRAY"
$type eq "array"
ref $val->{"value"}{$k} ne "ARRAY"
Truth table33%1/3
A and B
A= $type eq "array"B= ref $val->{"value"}{$k} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 182 | ▶ | sub _get_parameter_value { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_parameter_value: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 182 | my ($self, $param, $get) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 182 | my $schema_type = schema_type $param->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 182 | my $name = $param->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 182 | ▶ | $name = undef if $schema_type eq 'object' && $param->{explode} && ($param->{style} || '') =~ m!^(form|deepObject)$!; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
$schema_type eq "object" and $param->{"explode"} and ($param->{"style"} || "") =~ /^(form|deepObject)$/u
$schema_type eq "object" and $param->{"explode"}
$param->{'style'} || ''
MC/DC66%2/3
$schema_type eq "object" and $param->{"explode"} and ($param->{"style"} || "") =~ /^(form|deepObject)$/u
$schema_type eq "object"
$param->{"explode"}
$param->{'style'}
Truth table75%3/4
A and B and C
A= $schema_type eq "object"B= $param->{"explode"}C= $param->{'style'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 182 | my $val = $get->{$param->{in}}->($name, $param); | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 182 | @$val{qw(in name)} = (@$param{qw(in name)}); | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | 182 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 24 | ▶ | sub _split { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 24 | my ($re, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | 24 | ▶ | $val = @$val ? $val->[-1] : '' if ref $val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 24 | return split /$re/, $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub _to_list { ref $_[0] eq 'ARRAY' ? @{$_[0]} : $_[0] ? ($_[0]) : () } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_list: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 68 | ▶ | sub _validate_body { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_body: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 68 | my ($self, $direction, $val, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 68 | ▶ | if ($val->{accept}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | $val->{content_type} = negotiate_content_type($param->{accepts}, $val->{accept}); | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 3 | ▶ | $val->{valid} = $val->{content_type} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 3 | ▶ | return E "/header/Accept", [join(', ', @{$param->{accepts}}), type => $val->{accept}] unless $val->{valid}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 67 | my $negotiated_content_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 67 | ▶ | if (@{$param->{accepts}} and $val->{content_type}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$param->{"accepts"};} and $val->{"content_type"}
MC/DC50%1/2
@{$param->{"accepts"};} and $val->{"content_type"}
@{$param->{"accepts"};}
$val->{"content_type"}
Truth table66%2/3
A and B
A= @{$param->{"accepts"};}B= $val->{"content_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 16 | $negotiated_content_type = negotiate_content_type($param->{accepts}, $val->{content_type}); | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 16 | ▶ | $val->{valid} = $negotiated_content_type ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 16 | ▶ | return E "/$param->{name}", [join(', ', @{$param->{accepts}}) => type => $val->{content_type}] unless $negotiated_content_type; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 63 | ▶ | if ($param->{required} and !$val->{exists}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$param->{"required"} and not $val->{"exists"}
MC/DC100%2/2
$param->{"required"} and not $val->{"exists"}
$param->{"required"}
not $val->{"exists"}
Truth table100%3/3
A and not(B)
A= $param->{"required"}B= not $val->{"exists"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 8 | $val->{valid} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 8 | return E "/$param->{name}", [qw(object required)]; | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 55 | ▶ | if ($val->{exists}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # Ensures we have a valid content-type so we can select a schema | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # This can happen if the negotiation fails (e.g. content-type is empty) | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 51 | ▶ | $negotiated_content_type //= $param->{accepts}[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$negotiated_content_type //= $param->{"accepts"}[0]
MC/DC0%0/2
$negotiated_content_type //= $param->{"accepts"}[0]
$negotiated_content_type
$param->{"accepts"}[0]
Truth table66%2/3
A //= B
A= $negotiated_content_typeB= $param->{"accepts"}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # Mutate request content-type if one was not set | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 51 | ▶ | $val->{content_type} //= $negotiated_content_type; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$val->{"content_type"} //= $negotiated_content_type
MC/DC0%0/2
$val->{"content_type"} //= $negotiated_content_type
$val->{"content_type"}
$negotiated_content_type
Truth table66%2/3
A //= B
A= $val->{"content_type"}B= $negotiated_content_type
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | local $self->{coerce}{arrays} = 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 51 | ▶ | if $val->{content_type} =~ m!^(application/x-www-form-urlencoded|multipart/form-data)\s*(;|$)!; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 51 | local $self->{"validate_$direction"} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 51 | my $body_params = $param->{content}{$negotiated_content_type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 22 | my @errors = map { $_->path(_prefix_error_path($param->{name}, $_->path)); $_ } | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | 51 | $self->validate($val->{value}, $body_params->{schema}); | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 51 | ▶ | $val->{valid} = @errors ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 51 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | sub _validate_id { } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_id: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 50 | ▶ | sub _validate_type_array { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_array: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 50 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 50 | ▶ | $_[0] = [$_[0]] if ref $_[0] ne 'ARRAY' and $self->{coerce}{arrays}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $_[0] ne "ARRAY" and $self->{"coerce"}{"arrays"}
MC/DC100%2/2
ref $_[0] ne "ARRAY" and $self->{"coerce"}{"arrays"}
ref $_[0] ne "ARRAY"
$self->{"coerce"}{"arrays"}
Truth table100%3/3
A and B
A= ref $_[0] ne "ARRAY"B= $self->{"coerce"}{"arrays"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 50 | ▶ | return $_[1]->{schema}{nullable} && !defined $_[0] ? () : $self->SUPER::_validate_type_array(@_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[1]{"schema"}{"nullable"} and not defined $_[0]
MC/DC100%2/2
$_[1]{"schema"}{"nullable"} and not defined $_[0]
$_[1]{"schema"}{"nullable"}
not defined $_[0]
Truth table100%3/3
A and not(B)
A= $_[1]{"schema"}{"nullable"}B= not defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 506 | ▶ | sub _validate_type_boolean { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_boolean: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 506 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | 506 | ▶ | return $_[1]->{schema}{nullable} && !defined $_[0] ? () : $self->SUPER::_validate_type_boolean(@_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[1]{"schema"}{"nullable"} and not defined $_[0]
MC/DC0%0/2
$_[1]{"schema"}{"nullable"} and not defined $_[0]
$_[1]{"schema"}{"nullable"}
not defined $_[0]
Truth table33%1/3
A and not(B)
A= $_[1]{"schema"}{"nullable"}B= not defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1111 | ▶ | sub _validate_type_enum { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_enum: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1111 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1111 | ▶ | return $_[1]->{schema}{nullable} && !defined $_[0] ? () : $self->SUPER::_validate_type_enum(@_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[1]{"schema"}{"nullable"} and not defined $_[0]
MC/DC50%1/2
$_[1]{"schema"}{"nullable"} and not defined $_[0]
$_[1]{"schema"}{"nullable"}
not defined $_[0]
Truth table66%2/3
A and not(B)
A= $_[1]{"schema"}{"nullable"}B= not defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 54 | ▶ | sub _validate_type_integer { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_integer: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 54 | ▶ | return $_[1]->{schema}{nullable} && !defined $_[0] ? () : $self->SUPER::_validate_type_integer(@_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[1]{"schema"}{"nullable"} and not defined $_[0]
MC/DC0%0/2
$_[1]{"schema"}{"nullable"} and not defined $_[0]
$_[1]{"schema"}{"nullable"}
not defined $_[0]
Truth table33%1/3
A and not(B)
A= $_[1]{"schema"}{"nullable"}B= not defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 54 | ▶ | sub _validate_type_number { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_number: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | 54 | ▶ | return $_[1]->{schema}{nullable} && !defined $_[0] ? () : $self->SUPER::_validate_type_number(@_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[1]{"schema"}{"nullable"} and not defined $_[0]
MC/DC0%0/2
$_[1]{"schema"}{"nullable"} and not defined $_[0]
$_[1]{"schema"}{"nullable"}
not defined $_[0]
Truth table33%1/3
A and not(B)
A= $_[1]{"schema"}{"nullable"}B= not defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 10621 | ▶ | sub _validate_type_object { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 10621 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | 10621 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | 10621 | ▶ | return if $schema->{nullable} && !defined $data; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$schema->{"nullable"} and not defined $data
MC/DC100%2/2
$schema->{"nullable"} and not defined $data
$schema->{"nullable"}
not defined $data
Truth table100%3/3
A and not(B)
A= $schema->{"nullable"}B= not defined $data
| |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 10620 | ▶ | return E $path, [object => type => data_type $data] if ref $data ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 10620 | ▶ | return shift->SUPER::_validate_type_object(@_) unless $self->{validate_request} or $self->{validate_response}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"validate_request"} or $self->{"validate_response"}
MC/DC100%2/2
$self->{"validate_request"} or $self->{"validate_response"}
$self->{"validate_request"}
$self->{"validate_response"}
Truth table100%3/3
A or B
A= $self->{"validate_request"}B= $self->{"validate_response"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # TODO: Support external URLs in "mapping" | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 89 | my $discriminator = $schema->{discriminator}; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | 89 | ▶ | if (ref $discriminator eq 'HASH' and $discriminator->{propertyName} and !$self->{inside_discriminator}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $discriminator eq "HASH" and $discriminator->{"propertyName"} and not $self->{"inside_discriminator"}
ref $discriminator eq "HASH" and $discriminator->{"propertyName"}
MC/DC66%2/3
ref $discriminator eq "HASH" and $discriminator->{"propertyName"} and not $self->{"inside_discriminator"}
ref $discriminator eq "HASH"
$discriminator->{"propertyName"}
not $self->{"inside_discriminator"}
Truth table75%3/4
A and B and not(C)
A= ref $discriminator eq "HASH"B= $discriminator->{"propertyName"}C= not $self->{"inside_discriminator"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 6 | my ($name, $mapping) = @$discriminator{qw(propertyName mapping)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | 6 | ▶ | return E $path, "Discriminator $name has no value." unless my $map_name = $data->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 5 | ▶ | return E $path, "No definition for discriminator $map_name." unless my $url = $mapping->{$map_name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | ▶ | return E $path, "TODO: Not yet supported: $url" unless $url =~ s!^#!!; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 4 | local $self->{inside_discriminator} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 4 | return $self->_validate($data, $self->_state($state, schema => $self->get($url))); | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | return $self->{validate_request} | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 83 | ▶ | ? $self->_validate_type_object_request($_[1], $state) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | : $self->_validate_type_object_response($_[1], $state); | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 68 | ▶ | sub _validate_type_object_request { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object_request: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 68 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | 68 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 68 | my (@errors, %ro); | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | 68 | ▶ | for my $name (keys %{$schema->{properties} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'properties'} || {}
MC/DC100%1/1
$schema->{'properties'} || {}
$schema->{'properties'}
Truth table100%2/2
A
A= $schema->{'properties'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 63 | ▶ | next unless $self->_get(['readOnly'], {path => [], schema => $schema->{properties}{$name}}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | ▶ | push @errors, E [@$path, $name], "Read-only." if exists $data->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | $ro{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 68 | ▶ | local $schema->{required} = [grep { !$ro{$_} } @{$schema->{required} || []}]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'required'} || []
MC/DC100%1/1
$schema->{'required'} || []
$schema->{'required'}
Truth table100%2/2
A
A= $schema->{'required'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 68 | @errors, | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | $self->_validate_type_object_min_max($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | $self->_validate_type_object_dependencies($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | $self->_validate_type_object_properties($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 15 | ▶ | sub _validate_type_object_response { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object_response: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 15 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | 15 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 15 | my (@errors, %rw); | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | 15 | ▶ | for my $name (keys %{$schema->{properties} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'properties'} || {}
MC/DC100%1/1
$schema->{'properties'} || {}
$schema->{'properties'}
Truth table100%2/2
A
A= $schema->{'properties'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 38 | ▶ | next unless $self->_get(['writeOnly'], {path => [], schema => $schema->{properties}{$name}}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | ▶ | push @errors, E [@$path, $name], "Write-only." if exists $data->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 3 | $rw{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 15 | ▶ | local $schema->{required} = [grep { !$rw{$_} } @{$schema->{required} || []}]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'required'} || []
MC/DC100%1/1
$schema->{'required'} || []
$schema->{'required'}
Truth table100%2/2
A
A= $schema->{'required'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 15 | @errors, | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | $self->_validate_type_object_min_max($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | $self->_validate_type_object_dependencies($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | $self->_validate_type_object_properties($_[1], $state), | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 2224 | ▶ | sub _validate_type_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_string: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | 2224 | my ($val, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 2224 | ▶ | return () if $state->{schema}{nullable} && !defined $val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$state->{"schema"}{"nullable"} and not defined $val
MC/DC50%1/2
$state->{"schema"}{"nullable"} and not defined $val
$state->{"schema"}{"nullable"}
not defined $val
Truth table66%2/3
A and not(B)
A= $state->{"schema"}{"nullable"}B= not defined $val
| |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2216 | ▶ | if (ref $val eq 'Mojo::Upload') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | return () if | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | defined $state->{schema}{format} && | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 2 | ▶ | $state->{schema}{format} eq 'binary'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $state->{"schema"}{"format"} and $state->{"schema"}{"format"} eq "binary"
MC/DC50%1/2
defined $state->{"schema"}{"format"} and $state->{"schema"}{"format"} eq "binary"
defined $state->{"schema"}{"format"}
$state->{"schema"}{"format"} eq "binary"
Truth table66%2/3
A and B
A= defined $state->{"schema"}{"format"}B= $state->{"schema"}{"format"} eq "binary"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | return E $state->{path}, [string => type => data_type $val]; | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # Pass @_ (not the lexical copies) so SUPER's in-place coercion of $_[1] | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # propagates back to the caller's aliased value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 2214 | return $self->SUPER::_validate_type_string(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | JSON::Validator::Schema::OpenAPIv3 - OpenAPI version 3 | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | See L<JSON::Validator::Schema::OpenAPIv2/SYNOPSIS>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | This class represents L<https://spec.openapis.org/oas/3.0/schema/2021-09-28>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | =head2 errors | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | my $array_ref = $schema->errors; | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | See L<JSON::Validator::Schema/errors>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | =head2 moniker | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | $str = $schema->moniker; | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | $schema = $schema->moniker("openapiv3"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | Used to get/set the moniker for the given schema. Default value is "openapiv3". | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | =head2 specification | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||
| 461 | my $str = $schema->specification; | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | my $schema = $schema->specification($str); | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | Defaults to "L<https://spec.openapis.org/oas/3.0/schema/2021-09-28>". | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | =head2 add_default_response | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | $schema = $schema->add_default_response(\%params); | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | See L<JSON::Validator::Schema::OpenAPIv2/add_default_response> for details. | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | =head2 base_url | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | $url = $schema->base_url; | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | $schema = $schema->base_url($url); | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | Can get or set the default URL for this schema. C<$url> can be either a | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | L<Mojo::URL> object or a plain string. | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||
| 482 | This method will read or write "/servers/0/url" in L</data>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | =head2 coerce | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | my $schema = $schema->coerce({booleans => 1, numbers => 1, strings => 1}); | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | my $hash_ref = $schema->coerce; | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | Coercion is enabled by default, since headers, path parts, query parameters, | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | ... are in most cases strings. | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||
| 494 | $schema = JSON::Validator::Schema::OpenAPIv2->new(\%attrs); | ||||||||||||||||||||||||||||||||||||||||||||||
| 495 | $schema = JSON::Validator::Schema::OpenAPIv2->new; | ||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | Same as L<JSON::Validator::Schema/new>, but will also build L/coerce>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | =head2 parameters_for_request | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | $parameters = $schema->parameters_for_request([$method, $path]); | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | Finds all the request parameters defined in the schema, including inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | parameters. Returns C<undef> if the C<$path> and C<$method> cannot be found. | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | Example return value: | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | {in => "query", name => "q"}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | {in => "body", name => "body", accepts => ["application/json"]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | The return value MUST not be mutated. | ||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||
| 515 | =head2 parameters_for_response | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | $array_ref = $schema->parameters_for_response([$method, $path, $status]); | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | Finds the response parameters defined in the schema. Returns C<undef> if the | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | C<$path>, C<$method> and C<$status> cannot be found. Will default to the | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | "default" response definition if C<$status> could not be found and "default" | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | exists. | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||
| 524 | Example return value: | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | {in => "header", name => "X-Foo"}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | {in => "body", name => "body", accepts => ["application/json"]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | The return value MUST not be mutated. | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | =head2 routes | ||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | $collection = $schema->routes; | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | Shares the same interface as L<JSON::Validator::Schema::OpenAPIv2/routes>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | =head2 validate_request | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||
| 541 | @errors = $schema->validate_request([$method, $path], \%req); | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | Shares the same interface as L<JSON::Validator::Schema::OpenAPIv2/validate_request>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||
| 545 | =head2 validate_response | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | @errors = $schema->validate_response([$method, $path], \%req); | ||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | Shares the same interface as L<JSON::Validator::Schema::OpenAPIv2/validate_response>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | L<JSON::Validator::Schema>, L<JSON::Validator::Schema::OpenAPIv2> and and | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | L<JSON::Validator>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||