line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenAPI::Render::HTMLForms; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14478
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.2.0'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4078
|
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); |
|
1
|
|
|
|
|
39120
|
|
|
1
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1414
|
use parent qw(OpenAPI::Render); |
|
1
|
|
|
|
|
331
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub header |
13
|
|
|
|
|
|
|
{ |
14
|
1
|
|
|
1
|
0
|
5
|
my( $self ) = @_; |
15
|
|
|
|
|
|
|
return start_html( -title => $self->{api}{info}{title} . ' v' . |
16
|
|
|
|
|
|
|
$self->{api}{info}{version}, |
17
|
1
|
|
|
|
|
38
|
-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
|
|
|
1
|
0
|
8
|
return end_html; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub path_header |
42
|
|
|
|
|
|
|
{ |
43
|
3
|
|
|
3
|
0
|
11
|
my( $self, $path ) = @_; |
44
|
3
|
|
|
|
|
11
|
return h1( $path ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub operation_header |
48
|
|
|
|
|
|
|
{ |
49
|
10
|
|
|
10
|
0
|
21
|
my( $self, $path, $operation ) = @_; |
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
|
50
|
|
|
|
38
|
? ': ' . $self->{api}{paths}{$path}{$operation}{description} : '' ) ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub operation_footer |
59
|
|
|
|
|
|
|
{ |
60
|
10
|
|
|
10
|
0
|
24
|
my( $self, $path, $operation ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
10
|
|
|
|
|
14
|
my %submit_options; |
63
|
10
|
100
|
100
|
|
|
40
|
if( $operation eq 'get' || $operation eq 'post' ) { |
64
|
5
|
|
|
|
|
14
|
$submit_options{-onclick} = 'replace_url_parameters( this.form )'; |
65
|
|
|
|
|
|
|
} else { |
66
|
|
|
|
|
|
|
$submit_options{-name} = |
67
|
5
|
|
|
|
|
30
|
sprintf 'Submit Query (cannot be handled for %s)', |
68
|
|
|
|
|
|
|
uc $operation; |
69
|
5
|
|
|
|
|
11
|
$submit_options{-disabled} = 'disabled'; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
10
|
|
|
|
|
31
|
return submit( %submit_options ) . end_fieldset . end_form; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub parameter |
76
|
|
|
|
|
|
|
{ |
77
|
74
|
|
|
74
|
0
|
133
|
my( $self, $parameter ) = @_; |
78
|
74
|
|
|
|
|
108
|
my @parameter; |
79
|
74
|
100
|
|
|
|
188
|
return @parameter if $parameter->{'x-is-pattern'}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
push @parameter, |
82
|
|
|
|
|
|
|
h3( $parameter->{name} ), |
83
|
68
|
100
|
|
|
|
155
|
$parameter->{description} ? p( $parameter->{description} ) : (); |
84
|
68
|
100
|
100
|
|
|
3437
|
if( $parameter->{schema} && $parameter->{schema}{enum} ) { |
|
|
100
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
85
|
6
|
|
|
|
|
22
|
my @values = @{$parameter->{schema}{enum}}; |
|
6
|
|
|
|
|
20
|
|
86
|
6
|
50
|
|
|
|
15
|
if( !$parameter->{required} ) { |
87
|
6
|
|
|
|
|
14
|
unshift @values, ''; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
push @parameter, |
90
|
|
|
|
|
|
|
popup_menu( -name => $parameter->{name}, |
91
|
|
|
|
|
|
|
-values => \@values, |
92
|
6
|
50
|
|
|
|
33
|
($parameter->{in} eq 'path' |
93
|
|
|
|
|
|
|
? ( '-data-in-path' => 1 ) : ()) ); |
94
|
|
|
|
|
|
|
} elsif( ($parameter->{schema}{type} && |
95
|
|
|
|
|
|
|
$parameter->{schema}{type} eq 'object') || |
96
|
|
|
|
|
|
|
($parameter->{schema}{format} && |
97
|
|
|
|
|
|
|
$parameter->{schema}{format} eq 'binary') ) { |
98
|
|
|
|
|
|
|
push @parameter, |
99
|
36
|
|
|
|
|
99
|
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
|
100
|
66
|
|
|
185
|
? ( -required => 'required' ) : ()) } ); |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
68
|
|
|
|
|
16109
|
return @parameter; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |