| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Modern::OpenAPI::Generator; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
607272
|
use v5.26; |
|
|
6
|
|
|
|
|
19
|
|
|
4
|
6
|
|
|
6
|
|
21
|
use strict; |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
120
|
|
|
5
|
6
|
|
|
6
|
|
19
|
use warnings; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
288
|
|
|
6
|
6
|
|
|
6
|
|
22
|
use Carp qw(croak); |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
363
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
2362
|
use Modern::OpenAPI::Generator::Spec (); |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
150
|
|
|
11
|
6
|
|
|
6
|
|
2284
|
use Modern::OpenAPI::Generator::Writer (); |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
125
|
|
|
12
|
6
|
|
|
6
|
|
2590
|
use Modern::OpenAPI::Generator::CodeGen::Client (); |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
122
|
|
|
13
|
6
|
|
|
6
|
|
2554
|
use Modern::OpenAPI::Generator::CodeGen::ClientModels (); |
|
|
6
|
|
|
|
|
18
|
|
|
|
6
|
|
|
|
|
196
|
|
|
14
|
6
|
|
|
6
|
|
2482
|
use Modern::OpenAPI::Generator::CodeGen::Server (); |
|
|
6
|
|
|
|
|
24
|
|
|
|
6
|
|
|
|
|
159
|
|
|
15
|
6
|
|
|
6
|
|
2574
|
use Modern::OpenAPI::Generator::CodeGen::StubData (); |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
117
|
|
|
16
|
6
|
|
|
6
|
|
2174
|
use Modern::OpenAPI::Generator::CodeGen::Auth (); |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
109
|
|
|
17
|
6
|
|
|
6
|
|
2909
|
use Modern::OpenAPI::Generator::CodeGen::Docs (); |
|
|
6
|
|
|
|
|
13
|
|
|
|
6
|
|
|
|
|
148
|
|
|
18
|
6
|
|
|
6
|
|
2307
|
use Modern::OpenAPI::Generator::CodeGen::Tests (); |
|
|
6
|
|
|
|
|
13
|
|
|
|
6
|
|
|
|
|
165
|
|
|
19
|
6
|
|
|
6
|
|
30
|
use Path::Tiny qw(path); |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
3278
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
|
22
|
4
|
|
|
4
|
1
|
549308
|
my ( $class, %arg ) = @_; |
|
23
|
|
|
|
|
|
|
bless { |
|
24
|
|
|
|
|
|
|
spec_path => ( $arg{spec_path} // croak('spec_path required') ), |
|
25
|
|
|
|
|
|
|
output_dir => ( |
|
26
|
|
|
|
|
|
|
length( $arg{output_dir} // '' ) |
|
27
|
|
|
|
|
|
|
? $arg{output_dir} |
|
28
|
|
|
|
|
|
|
: croak('output_dir required') |
|
29
|
|
|
|
|
|
|
), |
|
30
|
|
|
|
|
|
|
name => ( $arg{name} // croak('name required') ), |
|
31
|
|
|
|
|
|
|
client => $arg{client} // 1, |
|
32
|
|
|
|
|
|
|
server => $arg{server} // 1, |
|
33
|
|
|
|
|
|
|
ui => $arg{ui} // 1, |
|
34
|
|
|
|
|
|
|
sync => $arg{sync} // 1, |
|
35
|
|
|
|
|
|
|
async => $arg{async} // 1, |
|
36
|
|
|
|
|
|
|
skeleton => $arg{skeleton} // 0, |
|
37
|
|
|
|
|
|
|
force => $arg{force} // 0, |
|
38
|
|
|
|
|
|
|
merge => $arg{merge} // 0, |
|
39
|
|
|
|
|
|
|
signatures => $arg{signatures} // [], |
|
40
|
4
|
50
|
33
|
|
|
200
|
local_test => $arg{local_test} // 0, |
|
|
|
|
50
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
41
|
|
|
|
|
|
|
}, $class; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub run { |
|
45
|
4
|
|
|
4
|
1
|
9
|
my ($self) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
47
|
my $spec = Modern::OpenAPI::Generator::Spec->load( $self->{spec_path} ); |
|
48
|
|
|
|
|
|
|
my $writer = Modern::OpenAPI::Generator::Writer->new( |
|
49
|
|
|
|
|
|
|
root => $self->{output_dir}, |
|
50
|
|
|
|
|
|
|
force => $self->{force}, |
|
51
|
|
|
|
|
|
|
merge => $self->{merge}, |
|
52
|
4
|
|
|
|
|
101
|
); |
|
53
|
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
228
|
path( $self->{output_dir} )->mkpath( { mode => 0755 } ); |
|
55
|
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
491
|
my $copy_spec = path( $self->{output_dir} )->child('share')->child('openapi.yaml'); |
|
57
|
4
|
|
|
|
|
308
|
$copy_spec->parent->mkpath( { mode => 0755 } ); |
|
58
|
4
|
50
|
33
|
|
|
1307
|
if ( !( $self->{merge} && -e $copy_spec ) ) { |
|
59
|
4
|
|
|
|
|
15
|
path( $self->{spec_path} )->copy($copy_spec); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
14779
|
my $base = $self->{name}; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Modern::OpenAPI::Generator::CodeGen::Auth->emit_plugins( |
|
65
|
|
|
|
|
|
|
writer => $writer, |
|
66
|
|
|
|
|
|
|
base => $base, |
|
67
|
|
|
|
|
|
|
signatures => $self->{signatures}, |
|
68
|
4
|
|
|
|
|
51
|
); |
|
69
|
|
|
|
|
|
|
|
|
70
|
4
|
100
|
|
|
|
13
|
if ( $self->{client} ) { |
|
71
|
|
|
|
|
|
|
Modern::OpenAPI::Generator::CodeGen::Client->generate( |
|
72
|
|
|
|
|
|
|
writer => $writer, |
|
73
|
|
|
|
|
|
|
spec => $spec, |
|
74
|
|
|
|
|
|
|
base => $base, |
|
75
|
|
|
|
|
|
|
sync => $self->{sync}, |
|
76
|
|
|
|
|
|
|
async => $self->{async}, |
|
77
|
|
|
|
|
|
|
signatures => $self->{signatures}, |
|
78
|
3
|
|
|
|
|
32
|
); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Models are required for StubData when serving with --local-test without a generated HTTP client. |
|
82
|
4
|
50
|
33
|
|
|
29
|
if ( $self->{client} || ( $self->{server} && $self->{local_test} ) ) { |
|
|
|
|
66
|
|
|
|
|
|
83
|
4
|
|
|
|
|
44
|
Modern::OpenAPI::Generator::CodeGen::ClientModels->generate( |
|
84
|
|
|
|
|
|
|
writer => $writer, |
|
85
|
|
|
|
|
|
|
spec => $spec, |
|
86
|
|
|
|
|
|
|
base => $base, |
|
87
|
|
|
|
|
|
|
); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
4
|
50
|
|
|
|
22
|
if ( $self->{server} ) { |
|
|
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Modern::OpenAPI::Generator::CodeGen::Server->generate( |
|
92
|
|
|
|
|
|
|
writer => $writer, |
|
93
|
|
|
|
|
|
|
spec => $spec, |
|
94
|
|
|
|
|
|
|
base => $base, |
|
95
|
|
|
|
|
|
|
skeleton => $self->{skeleton}, |
|
96
|
|
|
|
|
|
|
local_test => $self->{local_test}, |
|
97
|
|
|
|
|
|
|
ui => $self->{ui}, |
|
98
|
|
|
|
|
|
|
signatures => $self->{signatures}, |
|
99
|
4
|
|
|
|
|
55
|
); |
|
100
|
4
|
100
|
|
|
|
23
|
if ( $self->{local_test} ) { |
|
101
|
2
|
|
|
|
|
25
|
Modern::OpenAPI::Generator::CodeGen::StubData->generate( |
|
102
|
|
|
|
|
|
|
writer => $writer, |
|
103
|
|
|
|
|
|
|
base => $base, |
|
104
|
|
|
|
|
|
|
); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
elsif ( $self->{ui} ) { |
|
108
|
0
|
|
|
|
|
0
|
Modern::OpenAPI::Generator::CodeGen::Server->generate_spec_ui_only( |
|
109
|
|
|
|
|
|
|
writer => $writer, |
|
110
|
|
|
|
|
|
|
spec => $spec, |
|
111
|
|
|
|
|
|
|
base => $base, |
|
112
|
|
|
|
|
|
|
); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
4
|
|
33
|
|
|
24
|
my $ui_only = !$self->{server} && $self->{ui}; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Modern::OpenAPI::Generator::CodeGen::Docs->generate( |
|
118
|
|
|
|
|
|
|
writer => $writer, |
|
119
|
|
|
|
|
|
|
spec => $spec, |
|
120
|
|
|
|
|
|
|
base => $base, |
|
121
|
|
|
|
|
|
|
client => $self->{client}, |
|
122
|
|
|
|
|
|
|
server => $self->{server}, |
|
123
|
|
|
|
|
|
|
ui => $self->{ui}, |
|
124
|
|
|
|
|
|
|
sync => $self->{sync}, |
|
125
|
|
|
|
|
|
|
async => $self->{async}, |
|
126
|
|
|
|
|
|
|
ui_only => $ui_only, |
|
127
|
|
|
|
|
|
|
local_test => $self->{local_test}, |
|
128
|
4
|
|
|
|
|
59
|
); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Modern::OpenAPI::Generator::CodeGen::Tests->generate( |
|
131
|
|
|
|
|
|
|
writer => $writer, |
|
132
|
|
|
|
|
|
|
base => $base, |
|
133
|
|
|
|
|
|
|
client => $self->{client}, |
|
134
|
|
|
|
|
|
|
server => $self->{server}, |
|
135
|
|
|
|
|
|
|
ui => $self->{ui}, |
|
136
|
|
|
|
|
|
|
sync => $self->{sync}, |
|
137
|
|
|
|
|
|
|
async => $self->{async}, |
|
138
|
|
|
|
|
|
|
signatures => $self->{signatures}, |
|
139
|
|
|
|
|
|
|
ui_only => $ui_only, |
|
140
|
|
|
|
|
|
|
local_test => $self->{local_test}, |
|
141
|
4
|
|
|
|
|
56
|
); |
|
142
|
|
|
|
|
|
|
|
|
143
|
4
|
|
|
|
|
20
|
$self->_write_root_cpanfile($writer); |
|
144
|
4
|
|
|
|
|
111
|
return $self; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub _write_root_cpanfile { |
|
148
|
4
|
|
|
4
|
|
10
|
my ( $self, $writer ) = @_; |
|
149
|
4
|
|
|
|
|
20
|
my $txt = <<'CPAN'; |
|
150
|
|
|
|
|
|
|
requires 'perl', '5.026'; |
|
151
|
|
|
|
|
|
|
requires 'Mojolicious', '9.0'; |
|
152
|
|
|
|
|
|
|
requires 'Mojolicious::Plugin::OpenAPI', '5.00'; |
|
153
|
|
|
|
|
|
|
requires 'Mojolicious::Plugin::SwaggerUI', '0'; |
|
154
|
|
|
|
|
|
|
requires 'JSON::Validator', '5.0'; |
|
155
|
|
|
|
|
|
|
requires 'OpenAPI::Modern', '0.060'; |
|
156
|
|
|
|
|
|
|
requires 'Moo', '2.005'; |
|
157
|
|
|
|
|
|
|
requires 'Types::Standard', '2.000'; |
|
158
|
|
|
|
|
|
|
requires 'YAML::PP', '0.034'; |
|
159
|
|
|
|
|
|
|
requires 'JSON::MaybeXS', '1.004'; |
|
160
|
|
|
|
|
|
|
requires 'Modern::Perl::Prelude', '0'; |
|
161
|
|
|
|
|
|
|
requires 'Digest::SHA', '6.00'; |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
on test => sub { |
|
164
|
|
|
|
|
|
|
requires 'Test::More', '0.96'; |
|
165
|
|
|
|
|
|
|
}; |
|
166
|
|
|
|
|
|
|
CPAN |
|
167
|
4
|
|
|
|
|
12
|
$writer->write( 'cpanfile', $txt ); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |