Render.pm

filter: Statementstmt 90.9% 60 / 66 Branchbran 81.8% 18 / 22 Conditioncond 55.5% 5 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 64.7% 11 / 17 Podpod 0.0% 0 / 15 totaltotal 71.6% 96 / 134 SCAR 28.8
CC
17
Cov
86%
show
7.0
dereference
6.0
RequestBody2Parameters
5.8
CRAP 17.9
« Render/HTMLForms.pm ↑ Summary
1 package OpenAPI::Render;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Render OpenAPI specifications as documents
7 1 our $VERSION = '0.2.0'; # VERSION
8  
9 sub new
10 {
11 1 ▶ my( $class, $api ) = @_;
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
12  
13 1 my $self = { api => dereference( $api, $api ) };
14  
15 1 my( $base_url ) = map { $_->{url} } @{$api->{servers} };
16 1 ▶ $self->{base_url} = $base_url if $base_url;
Branch: 1 branch
BranchTrueFalseTotal
if $base_url 1 0 1
17  
18 1 return bless $self, $class;
19 }
20  
21 sub show
22 {
23 1 ▶ my( $self ) = @_;
Subroutine show: called CC=7 SCAR=19.5
Pod undocumented
24  
25 1 my $html = $self->header;
26  
27 1 my $api = $self->{api};
28  
29 1 for my $path (sort keys %{$api->{paths}}) {
30 3 $html .= $self->path_header( $path );
31 3 for my $operation ('get', 'post', 'patch', 'put', 'delete') {
32 15 ▶ next if !$api->{paths}{$path}{$operation};
Branch: 1 branch
BranchTrueFalseTotal
unless $api->{"paths"}{$path}{$operation} 5 10 15
33 my @parameters = (
34 exists $api->{paths}{$path}{parameters}
35 10 ▶ ? @{$api->{paths}{$path}{parameters}} : (),
Branch: 1 branch
BranchTrueFalseTotal
exists $api->{'paths'}{$path}{$operation}{'parameters'} ? : 2 8 10
36 exists $api->{paths}{$path}{$operation}{parameters}
37 2 ▶ ? @{$api->{paths}{$path}{$operation}{parameters}} : (),
Branch: 1 branch
BranchTrueFalseTotal
exists $api->{'paths'}{$path}{$operation}{'requestBody'} ? : 6 4 10
38 exists $api->{paths}{$path}{$operation}{requestBody}
39 10 ▶ ? RequestBody2Parameters( $api->{paths}{$path}{$operation}{requestBody} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
exists $api->{'paths'}{$path}{'parameters'} ? : 10 0 10
40 );
41 10 my $responses = $api->{paths}{$path}{$operation}{responses};
42  
43 $html .= $self->operation_header( $path, $operation ) .
44  
45 $self->parameters_header .
46 74 join( '', map { $self->parameter( $_ ) } @parameters ) .
47 $self->parameters_footer .
48  
49 $self->responses_header .
50 10 join( '', map { $self->response( $_, $responses->{$_} ) }
51 sort keys %$responses ) .
52 $self->responses_footer .
53  
54 $self->operation_footer( $path, $operation );
55 }
56 }
57  
58 1 $html .= $self->footer;
59 1 return $html;
60 }
61  
62 0 ▶sub header { return '' }
Subroutine header: not called CC=1 SCAR=6.9
Pod undocumented
63 0 ▶sub footer { return '' }
Subroutine footer: not called CC=1 SCAR=6.9
Pod undocumented
64 0 ▶sub path_header { return '' }
Subroutine path_header: not called CC=1 SCAR=6.9
Pod undocumented
65 0 ▶sub operation_header { return '' }
Subroutine operation_header: not called CC=1 SCAR=6.9
Pod undocumented
66  
67 10 ▶sub parameters_header { return '' };
Subroutine parameters_header: called CC=1 SCAR=0.0
Pod undocumented
68 0 ▶sub parameter { return '' }
Subroutine parameter: not called CC=1 SCAR=6.9
Pod undocumented
69 10 ▶sub parameters_footer { return '' };
Subroutine parameters_footer: called CC=1 SCAR=0.0
Pod undocumented
70  
71 10 ▶sub responses_header { return '' };
Subroutine responses_header: called CC=1 SCAR=0.0
Pod undocumented
72 20 ▶sub response { return '' };
Subroutine response: called CC=1 SCAR=0.0
Pod undocumented
73 10 ▶sub responses_footer { return '' };
Subroutine responses_footer: called CC=1 SCAR=0.0
Pod undocumented
74  
75 0 ▶sub operation_footer { return '' }
Subroutine operation_footer: not called CC=1 SCAR=6.9
Pod undocumented
76  
77 sub dereference
78 {
79 307 ▶ my( $node, $root ) = @_;
Subroutine dereference: called CC=6 SCAR=17.9
Pod undocumented
80  
81 307 ▶ if( ref $node eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $node eq 'ARRAY') { } 11 296 307
elsif (ref $node eq 'HASH') { } 162 134 296
82 11 @$node = map { dereference( $_, $root ) } @$node;
83 } elsif( ref $node eq 'HASH' ) {
84 162 my @keys = keys %$node;
85 162 ▶ if( scalar @keys == 1 && $keys[0] eq '$ref' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys == 1 and $keys[0] eq '$ref') { } 37 125 162
Condition100%3/3
scalar @keys == 1 and $keys[0] eq "\$ref"
!ll&&!rl&&r
1002537
MC/DC100%2/2
scalar @keys == 1 and $keys[0] eq "\$ref"
scalar @keys == 1 $keys[0] eq "\$ref"
Truth table100%3/3
A and B
A= scalar @keys == 1B= $keys[0] eq "\$ref"
ABresult
0X0
100
111
86 37 my @path = split '/', $node->{'$ref'};
87 37 shift @path;
88 37 $node = $root;
89 37 ▶ while( @path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 111 37 148
90 111 $node = $node->{shift @path};
91 }
92 } else {
93 125 %$node = map { $_ => dereference( $node->{$_}, $root ) } @keys;
94 }
95 }
96 307 return $node;
97 }
98  
99 sub RequestBody2Parameters
100 {
101 6 ▶ my( $requestBody ) = @_;
Subroutine RequestBody2Parameters: called CC=5 SCAR=17.6
Pod undocumented
102  
103 return if !exists $requestBody->{content} ||
104 !exists $requestBody->{content}{'multipart/form-data'} ||
105 6 ▶ !exists $requestBody->{content}{'multipart/form-data'}{schema};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $requestBody->{"content"} and exists $requestBody->{"content"}{"multipart/form-data"} and exists $requestBody->{"content"}{"multipart/form-data"}{"schema"} 0 6 6
Condition33%2/6
exists $requestBody->{"content"} and exists $requestBody->{"content"}{"multipart/form-data"} and exists $requestBody->{"content"}{"multipart/form-data"}{"schema"}
!ll&&!rl&&r
006
exists $requestBody->{"content"} and exists $requestBody->{"content"}{"multipart/form-data"}
!ll&&!rl&&r
006
MC/DC0%0/3
exists $requestBody->{"content"} and exists $requestBody->{"content"}{"multipart/form-data"} and exists $requestBody->{"content"}{"multipart/form-data"}{"schema"}
exists $requestBody->{"content"} exists $requestBody->{"content"}{"multipart/form-data"} exists $requestBody->{"content"}{"multipart/form-data"}{"schema"}
Truth table25%1/4
A and B and C
A= exists $requestBody->{"content"}B= exists $requestBody->{"content"}{"multipart/form-data"}C= exists $requestBody->{"content"}{"multipart/form-data"}{"schema"}
ABCresult
0XX0
10X0
1100
1111
106  
107 6 my $schema = $requestBody->{content}{'multipart/form-data'}{schema};
108  
109 6 ▶ return if $schema->{type} ne 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $schema->{"type"} ne "object" 0 6 6
110 return ( map { {
111 in => 'query',
112 name => $_,
113 36 schema => $schema->{properties}{$_} } }
114 6 sort keys %{$schema->{properties}} ),
115 ( map { {
116 in => 'query',
117 name => $_,
118 6 schema => $schema->{patternProperties}{$_},
119 'x-is-pattern' => 1 } }
120 6 sort keys %{$schema->{patternProperties}} );
121 }
122  
123 1 1;
« Render/HTMLForms.pm ↑ Summary