| 1 | #!perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | #PODNAME: Raisin::Plugin::Swagger | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | #ABSTRACT: Generates API description in Swagger 2/OpenAPI compatible format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # vim:ts=4:shiftwidth=4:expandtab:syntax=perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package Raisin::Plugin::Swagger; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | $Raisin::Plugin::Swagger::VERSION = '0.94'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use parent 'Raisin::Plugin'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use Digest::MD5 qw/md5_hex/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use JSON::MaybeXS qw/encode_json/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use List::Util qw/pairmap/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | my %DEFAULTS; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | my %SETTINGS; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | my $HTTP_OK = 200; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | $self->register( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 19 | ▶ | swagger_build_spec => sub { $self->_spec_20 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | swagger_setup => sub { %SETTINGS = @_ }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | swagger_security => \&swagger_security, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub swagger_security { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
swagger_security: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my %p = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | croak 'Invalid `type`' unless grep { $p{type} eq $_ } qw/basic api_key oauth2/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my %security; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($p{type} eq 'basic') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $security{ $p{name} } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | type => 'basic', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | elsif ($p{type} eq 'api_key') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | croak 'Invalid `in`' unless grep { $p{in} eq $_ } qw/query header/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | $security{ $p{name} } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | type => 'apiKey', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | name => $p{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | in => $p{in}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | elsif ($p{type} eq 'oauth2') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | croak 'Invalid `flow`' unless grep { $p{flow} eq $_ } qw/implicit password application accessCode/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $security{ $p{name} } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | type => 'oauth2', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | flow => $p{flow}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | scopes => $p{scopes}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (grep { $p{flow} eq $_ } qw/implicit accessCode/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $security{ $p{name} }{authorizationUrl} = $p{authorization_url}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (grep { $p{flow} eq $_ } qw/password application accessCode/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $security{ $p{name} }{tokenUrl} = $p{token_url}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $SETTINGS{security} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | %{ $SETTINGS{security} || {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$SETTINGS{'security'} || {}
MC/DC0%0/1
$SETTINGS{'security'} || {}
$SETTINGS{'security'}
Truth table0%0/2
A
A= $SETTINGS{'security'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | %security, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 20 | ▶ | sub _spec_20 { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spec_20: called CC=7 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 20 | ▶ | return 1 if $self->{built}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | my $app = $self->app; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | my $req = $app->req; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my $routes = $app->routes->routes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | my @content_types = $app->format | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ? $app->format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | : qw(application/x-yaml application/json); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my $base_path = $req->base->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ### Respect proxied requests | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # A proxy map is used to fill the "basePath" attribute. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | my $_base = $req->env->{HTTP_X_FORWARDED_SCRIPT_NAME} || q(/); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$req->env->{'HTTP_X_FORWARDED_SCRIPT_NAME'} || '/'
MC/DC0%0/1
$req->env->{'HTTP_X_FORWARDED_SCRIPT_NAME'} || '/'
$req->env->{'HTTP_X_FORWARDED_SCRIPT_NAME'}
Truth table50%1/2
A
A= $req->env->{'HTTP_X_FORWARDED_SCRIPT_NAME'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | $base_path =~ s#http(?:s?)://[^/]+/#$_base#msix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | $DEFAULTS{consumes} = \@content_types; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | $DEFAULTS{produces} = \@content_types; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | my %spec = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | swagger => '2.0', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | info => _info_object($app), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ### Respect proxied requests | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # The frontend hostname is used if set. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | host => $req->env->{HTTP_X_FORWARDED_HOST} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | || $req->env->{SERVER_NAME} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | || $req->env->{HTTP_HOST}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | basePath => $base_path, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$req->env->{'HTTP_X_FORWARDED_HOST'} || $req->env->{'SERVER_NAME'} || $req->env->{'HTTP_HOST'}
$req->env->{"HTTP_X_FORWARDED_HOST"} or $req->env->{"SERVER_NAME"}
MC/DC0%0/3
$req->env->{'HTTP_X_FORWARDED_HOST'} || $req->env->{'SERVER_NAME'} || $req->env->{'HTTP_HOST'}
$req->env->{"HTTP_X_FORWARDED_HOST"}
$req->env->{"SERVER_NAME"}
$req->env->{'HTTP_HOST'}
Truth table25%1/4
A or B || C
A= $req->env->{"HTTP_X_FORWARDED_HOST"}B= $req->env->{"SERVER_NAME"}C= $req->env->{'HTTP_HOST'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | schemes => [$req->scheme], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | consumes => \@content_types, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | produces => \@content_types, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | paths => _paths_object($routes), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | definitions => _definitions_object($routes), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | #parameters => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | #responses => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | securityDefinitions => _security_definitions_object(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | security => _security_object(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | #tags => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | #externalDocs => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | my $tags = _tags_object($self->app); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | if (scalar @$tags) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $spec{tags} = $tags; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # routes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | $self->app->add_route( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | method => 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | path => '/swagger', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | code => sub { \%spec } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # mark as built | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | $self->{built} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | \%spec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | sub _contact_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_contact_object: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | my $contact = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | my %obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | for (qw(name url email)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | ▶ | $obj{$_} = $contact->{$_} if $contact->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | \%obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | ▶ | sub _license_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_license_object: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | my $license = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | my %obj = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | name => $license->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | $obj{url} = $license->{url} if $license->{url}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | \%obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | ▶ | sub _info_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_info_object: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | my $app = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | my %obj = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | ▶ | title => $SETTINGS{title} || 'API', | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$SETTINGS{'title'} || 'API'
$app->api_version || '0.0.1'
MC/DC100%1/1
$SETTINGS{'title'} || 'API'
$SETTINGS{'title'}
MC/DC100%1/1
$app->api_version || '0.0.1'
$app->api_version
Truth table100%2/2
A
A= $SETTINGS{'title'}
Truth table100%2/2
A
A= $app->api_version
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | version => $app->api_version || '0.0.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | $obj{description} = $SETTINGS{description} if $SETTINGS{description}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | ▶ | $obj{termsOfService} = $SETTINGS{terms_of_service} if $SETTINGS{terms_of_service}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | ▶ | $obj{contact} = _contact_object($SETTINGS{contact}) if keys %{ $SETTINGS{contact} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | $obj{license} = _license_object($SETTINGS{license}) if keys %{ $SETTINGS{license} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | \%obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | sub _security_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_security_object: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my @obj = map { { $_->{name} => $_->{scopes} || [] } } values %{ $SETTINGS{security} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_->{'scopes'} || []
MC/DC0%0/1
$_->{'scopes'} || []
$_->{'scopes'}
Truth table0%0/2
A
A= $_->{'scopes'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | \@obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | sub _security_definitions_object { $SETTINGS{security} || {} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_security_definitions_object: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | ▶ | sub _paths_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paths_object: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | my $routes = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | my %obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | for my $r (sort { $a->path cmp $b->path } @$routes) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 26 | ▶ | next if lc($r->method) eq 'options'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 20 | my $path = $r->path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 20 | $path =~ s#:([^/]+)#{$1}#msixg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 20 | $obj{ $path }{ lc($r->method) } = _operation_object($r); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | \%obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 20 | ▶ | sub _operation_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_operation_object: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 20 | my $r = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 20 | my $path = $r->path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 20 | $path =~ tr#/:#_#; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 20 | my $operation_id = lc($r->method) . $path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | my %obj = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | consumes => $DEFAULTS{consumes}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | #deprecated => 'false', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | description => $r->desc || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | #externalDocs => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | operationId => $operation_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | produces => $r->produces || $DEFAULTS{produces}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | responses => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | default => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | description => 'Unexpected error', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | #examples => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | #headers => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | #schema => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Adds a response object from route's entity if it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 20 | ▶ | %{ _response_object($r) }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition57%4/7
$r->desc || ''
$r->produces || $DEFAULTS{'produces'}
$r->summary || ''
MC/DC0%0/1
$r->desc || ''
$r->desc
MC/DC0%0/2
$r->produces || $DEFAULTS{'produces'}
$r->produces
$DEFAULTS{'produces'}
MC/DC100%1/1
$r->summary || ''
$r->summary
Truth table50%1/2
A
A= $r->desc
Truth table33%1/3
A || B
A= $r->producesB= $DEFAULTS{'produces'}
Truth table100%2/2
A
A= $r->summary
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | #schemes => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | #security => {}, # TODO per operation permissions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | summary => $r->summary || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | tags => $r->tags, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 20 | my $params = _parameters_object($r->method, $r->params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 20 | ▶ | $obj{parameters} = $params if scalar @$params; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 20 | \%obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 21 | ▶ | sub _response_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_response_object: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 21 | my $r = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 21 | ▶ | return {} unless $r->entity; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | my $name = $r->entity; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | my %obj = ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$r->desc || $r->summary || ''
$r->desc or $r->summary
MC/DC0%0/2
$r->desc || $r->summary || ''
$r->desc
$r->summary
Truth table33%1/3
A or B
A= $r->descB= $r->summary
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | $HTTP_OK => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | description => $r->desc || $r->summary || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | '$ref' => sprintf('#/definitions/%s', _name_for_object($name)), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | \%obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 28 | ▶ | sub _parameters_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parameters_object: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 28 | my ($method, $pp) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 28 | my @obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 28 | for my $p (@$pp) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 43 | my ($type) = _param_type($p->type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Available: query, header, path, formData or body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 43 | my $location = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 43 | ▶ | if ($p->in) { $p->in } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 14 | elsif ($p->named) { 'path' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | elsif ($type eq 'object') { 'body' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 17 | elsif ($method =~ /patch|post|put/i) { 'formData' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 9 | else { 'query' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 43 | my $ptype = _param_type_object($p); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 43 | ▶ | if (_type_name($p->type) =~ /^HashRef$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | $ptype->{schema}{'$ref'} = delete $ptype->{'$ref'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # If the type is an Enum, set type to string and give the enum values. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 43 | ▶ | if (_type_is_enum($p->type)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | $ptype->{type} = 'string'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | $ptype->{enum} = $p->type->values; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 43 | ▶ | my %param = ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$p->desc || ''
MC/DC100%1/1
$p->desc || ''
$p->desc
Truth table100%2/2
A
A= $p->desc
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | description => $p->desc || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | in => $location, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | name => $p->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | required => $p->required ? JSON::MaybeXS::true : JSON::MaybeXS::false, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | %$ptype, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 43 | ▶ | $param{default} = $p->default if defined $p->default; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 43 | push @obj, \%param; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 28 | \@obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | ▶ | sub _definitions_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_definitions_object: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 3 | my $routes = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 3 | my @objects; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | for my $r (@$routes) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 27 | ▶ | if ($r->entity) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | push @objects, $r->entity; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 27 | my @pp = @{ $r->params }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 27 | ▶ | while (my $p = pop @pp) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 41 | ▶ | next unless _type_name($p->type) =~ /^HashRef$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | ▶ | push @pp, @{ $p->enclosed || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$p->enclosed || []
MC/DC0%0/1
$p->enclosed || []
$p->enclosed
Truth table50%1/2
A
A= $p->enclosed
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | push @objects, $p; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 3 | my %definitions = map { %{ _schema_object($_) } } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | _collect_nested_definitions(@objects); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 3 | \%definitions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 5 | ▶ | sub _collect_nested_definitions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_collect_nested_definitions: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 5 | my @objects = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 5 | ▶ | return () unless scalar @objects; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | my @nested; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | for my $obj (@objects) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 4 | ▶ | if( $obj->can('enclosed') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 4 | ▶ | for my $expose ( @{ $obj->enclosed || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->enclosed || []
MC/DC0%0/1
$obj->enclosed || []
$obj->enclosed
Truth table50%1/2
A
A= $obj->enclosed
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 9 | ▶ | if (exists $expose->{'using'} ){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | push @nested, $expose->{using}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | push @objects, _collect_nested_definitions(@nested); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | return @objects; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 6 | ▶ | sub _schema_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_schema_object: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 6 | my $p = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 6 | ▶ | return unless _type_name($p->type) =~ /^HashRef$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 6 | my (@required, %properties); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 6 | ▶ | for my $pp (@{ $p->enclosed || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$p->enclosed || []
MC/DC0%0/1
$p->enclosed || []
$p->enclosed
Truth table50%1/2
A
A= $p->enclosed
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 14 | $properties{ _type_name($pp) } = _param_type_object($pp); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 14 | ▶ | push @required, _type_name($pp) if $pp->required; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 6 | my %object = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | _name_for_object($p) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | required => \@required, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | properties => \%properties, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 6 | \%object; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 2 | ▶ | sub _tags_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tags_object: called CC=6 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 2 | my $app = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 2 | my %tags; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 2 | for my $r (@{ $app->routes->routes }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 26 | ▶ | next unless $_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $tags{ $_ }++ for @{ $r->tags }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | my @tags; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | for my $t (keys %tags) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | my $tag = { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$app->resource_desc($t) || ''
MC/DC0%0/1
$app->resource_desc($t) || ''
$app->resource_desc($t)
Truth table0%0/2
A
A= $app->resource_desc($t)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | name => $t, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | description => $app->resource_desc($t) || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | #externalDocs => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # description => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # url => '', #R | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | #}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | push @tags, $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | \@tags; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # get the name of a type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 342 | ▶ | sub _type_name { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_type_name: called CC=5 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 342 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 342 | ▶ | if ($type && $type->can('display_name')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$type and $type->can("display_name")
MC/DC0%0/2
$type and $type->can("display_name")
$type
$type->can("display_name")
Truth table33%1/3
A and B
A= $typeB= $type->can("display_name")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 342 | return $type->display_name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | ▶ | elsif ($type && $type->can('name')) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type and $type->can("name")
MC/DC0%0/2
$type and $type->can("name")
$type
$type->can("name")
Truth table0%0/3
A and B
A= $typeB= $type->can("name")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # fall back to name() (e.g. Moose types do not have display_name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | return $type->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | return "$type"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 57 | ▶ | sub _param_type_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_param_type_object: called CC=19 SCAR=30.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 57 | my $p = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 57 | my %item; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 57 | my $tt = $p->type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 57 | ▶ | if (_type_name($tt) =~ /^Maybe\[/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | $item{nullable} = JSON::MaybeXS::true; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | $tt = $tt->type_parameter; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 57 | ▶ | if (_type_name($tt) =~ /^HashRef$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | ▶ | $item{'$ref'} = sprintf('#/definitions/%s', _name_for_object($p->can('using')?$p->using:$p)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | elsif (_type_name($tt) =~ /^HashRef\[.*\]$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $item{'type'} = 'object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $item{'additionalProperties'} = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | '$ref' => sprintf('#/definitions/%s', _name_for_object($p->using)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | elsif (_type_name($tt) =~ /^ArrayRef/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | $item{type} = 'array'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | my $type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | my $format; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # Loop down to find type beneath coercion. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 3 | ▶ | while (!defined $type) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | ▶ | if($tt->can('type_parameter')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 4 | ($type, $format) = _param_type($tt->type_parameter); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ($type, $format) = ('object', '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 4 | ▶ | $tt = $tt->parent if !defined $type; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | ▶ | if ($type eq 'object') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 2 | $item{items} = {}; # {} is the "any-type" schema. | |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 2 | ▶ | if ($p->can('using') && $p->using) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$p->can("using") and $p->using
MC/DC50%1/2
$p->can("using") and $p->using
$p->can("using")
$p->using
Truth table66%2/3
A and B
A= $p->can("using")B= $p->using
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 1 | $item{items}{'$ref'} = sprintf('#/definitions/%s', _name_for_object($p->using)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | elsif ($tt->can("type_parameter")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | my ($subscript_type, $subscript_format) = _param_type($tt->type_parameter); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | if (defined $subscript_type) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | $item{items}->{type} = $subscript_type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | ▶ | $item{items}->{format} = $subscript_format if defined $subscript_format; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | $item{items}->{type} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | ▶ | $item{items}->{format} = $format if $format; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | ▶ | $item{description} = $p->desc if $p->desc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 51 | my ($type, $format) = _param_type($tt); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 51 | $item{type} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 51 | ▶ | $item{format} = $format if $format; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 51 | ▶ | $item{description} = $p->desc if $p->desc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 57 | \%item; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 99 | ▶ | sub _param_type { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_param_type: called CC=15 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 99 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 99 | ▶ | if ($t && $t->can('name')) { # allow nested types as Str in ArrayRef[Str] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t and $t->can("name")
MC/DC50%1/2
$t and $t->can("name")
$t
$t->can("name")
Truth table66%2/3
A and B
A= $tB= $t->can("name")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 98 | ▶ | if ($t->name =~ /int/i) { 'integer', 'int32' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | elsif ($t->name =~ /long/i) { 'integer', 'int64' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | elsif ($t->name =~ /num|float|real/i) { 'number', 'float' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | elsif ($t->name =~ /double/i) { 'number', 'double' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 54 | elsif ($t->name =~ /str/i) { 'string', undef } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | elsif ($t->name =~ /byte/i) { 'string', 'byte' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | elsif ($t->name =~ /bool/i) { 'boolean', undef } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | elsif ($t->name =~ /datetime/i) { 'string', 'date-time' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | elsif ($t->name =~ /date/i) { 'string', 'date' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | elsif ($t->name =~ /password/i) { 'string', 'password' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 4 | elsif ($t->name =~ /hashref/i) { 'object', undef } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 6 | ▶ | if (_type_name($t) =~ /ArrayRef/) { 'array', undef } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 4 | else { 'object', undef } # fallback | |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | { $t, undef } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 12 | ▶ | sub _name_for_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name_for_object: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 12 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 12 | local $Data::Dumper::Deparse = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 12 | local $Data::Dumper::Indent = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 12 | local $Data::Dumper::Maxdepth = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 12 | local $Data::Dumper::Purity = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 12 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 12 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 12 | my $fingerprint = md5_hex(Data::Dumper->Dump([$obj], [qw/obj/])); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 12 | my $objname = ucfirst($obj->name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | #--- $ref values must be RFC3986 compliant URIs --- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 12 | $objname =~ s/::/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 12 | sprintf '%s-%s', $objname, uc(substr($fingerprint, 0, 10)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 43 | ▶ | sub _type_is_enum { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_type_is_enum: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 43 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 43 | ▶ | return 1 if $type->isa('Moose::Meta::TypeConstraint::Enum') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type->isa("Moose::Meta::TypeConstraint::Enum") or $type->isa("Type::Tiny::Enum")
MC/DC50%1/2
$type->isa("Moose::Meta::TypeConstraint::Enum") or $type->isa("Type::Tiny::Enum")
$type->isa("Moose::Meta::TypeConstraint::Enum")
$type->isa("Type::Tiny::Enum")
Truth table66%2/3
A or B
A= $type->isa("Moose::Meta::TypeConstraint::Enum")B= $type->isa("Type::Tiny::Enum")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | or $type->isa('Type::Tiny::Enum'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 42 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||