line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenAPI::Render::HTMLForms; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
485
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Generate HTML forms for OpenAPI specifications. |
7
|
|
|
|
|
|
|
our $VERSION = '0.3.0'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
427
|
use OpenAPI::Render; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
10
|
1
|
|
|
1
|
|
443
|
use parent OpenAPI::Render::; |
|
1
|
|
|
|
|
284
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1023
|
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
|
|
|
|
|
32768
|
|
|
1
|
|
|
|
|
6
|
|
13
|
1
|
|
|
1
|
|
774
|
use List::Util qw( any ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
802
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub header |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
1
|
3
|
my( $self ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my %start_html_options = ( |
20
|
|
|
|
|
|
|
-title => $self->api->{info}{title} . ' v' . |
21
|
|
|
|
|
|
|
$self->api->{info}{version}, |
22
|
1
|
|
|
|
|
5
|
); |
23
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
1
|
|
13
|
if( any { $_->{in} eq 'path' } $self->parameters ) { |
|
1
|
|
|
|
|
5
|
|
25
|
|
|
|
|
|
|
$start_html_options{-script} = |
26
|
1
|
|
|
|
|
5
|
' |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
function replace_url_parameters( form ) { |
29
|
|
|
|
|
|
|
var url = form.getAttribute( "action" ); |
30
|
|
|
|
|
|
|
var inputs = form.getElementsByTagName( "input" ); |
31
|
|
|
|
|
|
|
for( var i = 0; i < inputs.length; i++ ) { |
32
|
|
|
|
|
|
|
var data_in_path = inputs[i].getAttribute( "data-in-path" ); |
33
|
|
|
|
|
|
|
if( data_in_path ) { |
34
|
|
|
|
|
|
|
url = url.replace( "{" + inputs[i].name + "}", inputs[i].value ); |
35
|
|
|
|
|
|
|
inputs[i].disabled = "disabled"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
form.setAttribute( "action", url ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
' |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
19
|
return start_html( %start_html_options ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub footer |
48
|
|
|
|
|
|
|
{ |
49
|
1
|
|
|
1
|
1
|
4
|
return end_html; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub path_header |
53
|
|
|
|
|
|
|
{ |
54
|
3
|
|
|
3
|
1
|
9
|
my( $self, $path ) = @_; |
55
|
3
|
|
|
|
|
10
|
return h1( $path ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub operation_header |
59
|
|
|
|
|
|
|
{ |
60
|
10
|
|
|
10
|
1
|
25
|
my( $self, $path, $operation ) = @_; |
61
|
|
|
|
|
|
|
return start_form( -action => $self->{base_url} . $path, |
62
|
|
|
|
|
|
|
-method => $operation ) . |
63
|
|
|
|
|
|
|
start_fieldset . |
64
|
|
|
|
|
|
|
legend( uc( $operation ) . |
65
|
|
|
|
|
|
|
( $self->api->{paths}{$path}{$operation}{description} |
66
|
10
|
50
|
|
|
|
41
|
? ': ' . $self->api->{paths}{$path}{$operation}{description} : '' ) ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub operation_footer |
70
|
|
|
|
|
|
|
{ |
71
|
10
|
|
|
10
|
1
|
23
|
my( $self, $path, $operation ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
10
|
|
|
|
|
20
|
my %submit_options; |
74
|
10
|
100
|
100
|
|
|
40
|
if( $operation eq 'get' || $operation eq 'post' ) { |
75
|
5
|
50
|
|
5
|
|
24
|
if( any { $_->{in} eq 'path' } $self->parameters( $path, $operation ) ) { |
|
5
|
|
|
|
|
18
|
|
76
|
5
|
|
|
|
|
14
|
$submit_options{-onclick} = 'replace_url_parameters( this.form )'; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} else { |
79
|
|
|
|
|
|
|
$submit_options{-name} = |
80
|
5
|
|
|
|
|
25
|
sprintf 'Submit Query (cannot be handled for %s)', |
81
|
|
|
|
|
|
|
uc $operation; |
82
|
5
|
|
|
|
|
11
|
$submit_options{-disabled} = 'disabled'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
10
|
|
|
|
|
47
|
return submit( %submit_options ) . end_fieldset . end_form; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub parameter |
89
|
|
|
|
|
|
|
{ |
90
|
74
|
|
|
74
|
1
|
139
|
my( $self, $parameter ) = @_; |
91
|
74
|
|
|
|
|
99
|
my @parameter; |
92
|
74
|
100
|
|
|
|
195
|
return @parameter if $parameter->{'x-is-pattern'}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
push @parameter, |
95
|
|
|
|
|
|
|
h3( $parameter->{name} ), |
96
|
68
|
100
|
|
|
|
139
|
$parameter->{description} ? p( $parameter->{description} ) : (); |
97
|
68
|
100
|
100
|
|
|
3481
|
if( $parameter->{schema} && $parameter->{schema}{enum} ) { |
|
|
100
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
98
|
6
|
|
|
|
|
18
|
my @values = @{$parameter->{schema}{enum}}; |
|
6
|
|
|
|
|
32
|
|
99
|
6
|
50
|
|
|
|
17
|
if( !$parameter->{required} ) { |
100
|
6
|
|
|
|
|
14
|
unshift @values, ''; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
push @parameter, |
103
|
|
|
|
|
|
|
popup_menu( -name => $parameter->{name}, |
104
|
|
|
|
|
|
|
-values => \@values, |
105
|
6
|
50
|
|
|
|
26
|
($parameter->{in} eq 'path' |
106
|
|
|
|
|
|
|
? ( '-data-in-path' => 1 ) : ()) ); |
107
|
|
|
|
|
|
|
} elsif( ($parameter->{schema}{type} && |
108
|
|
|
|
|
|
|
$parameter->{schema}{type} eq 'object') || |
109
|
|
|
|
|
|
|
($parameter->{schema}{format} && |
110
|
|
|
|
|
|
|
$parameter->{schema}{format} eq 'binary') ) { |
111
|
|
|
|
|
|
|
push @parameter, |
112
|
36
|
|
|
|
|
106
|
filefield( -name => $parameter->{name} ); |
113
|
|
|
|
|
|
|
} else { |
114
|
|
|
|
|
|
|
push @parameter, |
115
|
|
|
|
|
|
|
input( { -type => 'text', |
116
|
|
|
|
|
|
|
-name => $parameter->{name}, |
117
|
|
|
|
|
|
|
($parameter->{in} eq 'path' |
118
|
|
|
|
|
|
|
? ( '-data-in-path' => 1 ) : ()), |
119
|
|
|
|
|
|
|
(exists $parameter->{example} |
120
|
|
|
|
|
|
|
? ( -placeholder => $parameter->{example} ) |
121
|
|
|
|
|
|
|
: ()), |
122
|
|
|
|
|
|
|
($parameter->{in} eq 'path' || $parameter->{required} |
123
|
26
|
100
|
66
|
|
|
181
|
? ( -required => 'required' ) : ()) } ); |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
125
|
68
|
|
|
|
|
16292
|
return @parameter; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |