| 1 | package OpenAPI::Render::HTMLForms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | our $VERSION = '0.2.0'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use CGI qw(-nosticky -utf8 h1 h2 h3 p input filefield popup_menu legend submit start_div end_div start_fieldset end_fieldset start_form end_form start_html end_html); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use parent qw(OpenAPI::Render); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | sub header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | my( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | return start_html( -title => $self->{api}{info}{title} . ' v' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | $self->{api}{info}{version}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | -script => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | function replace_url_parameters( form ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | var url = form.getAttribute( "action" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | var inputs = form.getElementsByTagName( "input" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | for( var i = 0; i < inputs.length; i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | var data_in_path = inputs[i].getAttribute( "data-in-path" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | if( data_in_path ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | url = url.replace( "{" + inputs[i].name + "}", inputs[i].value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | inputs[i].disabled = "disabled"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | form.setAttribute( "action", url ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub footer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | return end_html; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
footer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | sub path_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | my( $self, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | return h1( $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub operation_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 10 | ▶ | my( $self, $path, $operation ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operation_header: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | return start_form( -action => $self->{base_url} . $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | -method => $operation ) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | start_fieldset . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | legend( uc( $operation ) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ( $self->{api}{paths}{$path}{$operation}{description} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 10 | ▶ | ? ': ' . $self->{api}{paths}{$path}{$operation}{description} : '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | sub operation_footer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | ▶ | my( $self, $path, $operation ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operation_footer: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 10 | my %submit_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 10 | ▶ | if( $operation eq 'get' || $operation eq 'post' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$operation eq "get" or $operation eq "post"
MC/DC100%2/2
$operation eq "get" or $operation eq "post"
$operation eq "get"
$operation eq "post"
Truth table100%3/3
A or B
A= $operation eq "get"B= $operation eq "post"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | $submit_options{-onclick} = 'replace_url_parameters( this.form )'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $submit_options{-name} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | sprintf 'Submit Query (cannot be handled for %s)', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | uc $operation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | $submit_options{-disabled} = 'disabled'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 10 | return submit( %submit_options ) . end_fieldset . end_form; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | sub parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 74 | ▶ | my( $self, $parameter ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parameter: called CC=15 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 74 | my @parameter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 74 | ▶ | return @parameter if $parameter->{'x-is-pattern'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | push @parameter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | h3( $parameter->{name} ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 68 | ▶ | $parameter->{description} ? p( $parameter->{description} ) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 68 | ▶ | if( $parameter->{schema} && $parameter->{schema}{enum} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$parameter->{"schema"} and $parameter->{"schema"}{"enum"}
MC/DC100%2/2
$parameter->{"schema"} and $parameter->{"schema"}{"enum"}
$parameter->{"schema"}
$parameter->{"schema"}{"enum"}
Truth table100%3/3
A and B
A= $parameter->{"schema"}B= $parameter->{"schema"}{"enum"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | my @values = @{$parameter->{schema}{enum}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | ▶ | if( !$parameter->{required} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | unshift @values, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | push @parameter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | popup_menu( -name => $parameter->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | -values => \@values, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | ▶ | ($parameter->{in} eq 'path' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ? ( '-data-in-path' => 1 ) : ()) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ▶ | } elsif( ($parameter->{schema}{type} && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
$parameter->{"schema"}{"type"} and $parameter->{"schema"}{"type"} eq "object" or $parameter->{"schema"}{"format"} and $parameter->{"schema"}{"format"} eq "binary"
$parameter->{"schema"}{"type"} and $parameter->{"schema"}{"type"} eq "object"
$parameter->{"schema"}{"format"} and $parameter->{"schema"}{"format"} eq "binary"
MC/DC75%3/4
$parameter->{"schema"}{"type"} and $parameter->{"schema"}{"type"} eq "object" or $parameter->{"schema"}{"format"} and $parameter->{"schema"}{"format"} eq "binary"
$parameter->{"schema"}{"type"}
$parameter->{"schema"}{"type"} eq "object"
$parameter->{"schema"}{"format"}
$parameter->{"schema"}{"format"} eq "binary"
Truth table57%4/7
A and B or C and D
A= $parameter->{"schema"}{"type"}B= $parameter->{"schema"}{"type"} eq "object"C= $parameter->{"schema"}{"format"}D= $parameter->{"schema"}{"format"} eq "binary"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | $parameter->{schema}{type} eq 'object') || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ($parameter->{schema}{format} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | $parameter->{schema}{format} eq 'binary') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | push @parameter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 36 | filefield( -name => $parameter->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | push @parameter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | input( { -type => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | -name => $parameter->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ($parameter->{in} eq 'path' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ? ( '-data-in-path' => 1 ) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | (exists $parameter->{example} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ? ( -placeholder => $parameter->{example} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ($parameter->{in} eq 'path' || $parameter->{required} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 26 | ▶ | ? ( -required => 'required' ) : ()) } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$parameter->{"in"} eq "path" or $parameter->{"required"}
MC/DC50%1/2
$parameter->{"in"} eq "path" or $parameter->{"required"}
$parameter->{"in"} eq "path"
$parameter->{"required"}
Truth table66%2/3
A or B
A= $parameter->{"in"} eq "path"B= $parameter->{"required"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 68 | return @parameter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||