line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SwaggerUI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1231
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
208
|
use Mojo::File qw(path); |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
592
|
use File::ShareDir qw(dist_dir); |
|
1
|
|
|
|
|
23944
|
|
|
1
|
|
|
|
|
305
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.0.4'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
1
|
|
|
1
|
1
|
62
|
my ($self, $app, $config) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
33
|
|
|
6
|
my $prefix = $config->{route} // $app->routes()->any('/swagger-ui'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# --- Configuring the Mojolicious path resolvers |
16
|
1
|
|
|
|
|
4
|
my $resources = path(dist_dir('Mojolicious-Plugin-SwaggerUI')) |
17
|
|
|
|
|
|
|
->child('resources'); |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
201
|
push(@{$app->static()->paths()}, $resources->child('public')->to_string()); |
|
1
|
|
|
|
|
7
|
|
20
|
1
|
|
|
|
|
42
|
push(@{$app->renderer()->paths()}, $resources->child('templates')->to_string()); |
|
1
|
|
|
|
|
5
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# --- Adding the route |
23
|
1
|
|
50
|
|
|
36
|
my $url = $config->{url} // '/v1'; |
24
|
1
|
|
50
|
|
|
11
|
my $title = $config->{title} // 'Swagger UI'; |
25
|
|
|
|
|
|
|
my $favicon |
26
|
|
|
|
|
|
|
= (defined $config->{favicon} and $app->static()->file($config->{favicon})) |
27
|
|
|
|
|
|
|
? $config->{favicon} |
28
|
1
|
50
|
33
|
|
|
5
|
: undef; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
7
|
$prefix->get(q(/) => { url => $url, title => $title, favicon => $favicon }) |
31
|
|
|
|
|
|
|
->name('swagger_ui'); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
289
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=encoding utf8 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Mojolicious::Plugin::SwaggerUI - Swagger UI plugin for Mojolicious |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Mojolicious Lite |
47
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
48
|
|
|
|
|
|
|
route => app->routes()->any('/swagger'), |
49
|
|
|
|
|
|
|
url => '/swagger.json', |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Mojolicious Full |
53
|
|
|
|
|
|
|
$app->plugin( |
54
|
|
|
|
|
|
|
SwaggerUI => { |
55
|
|
|
|
|
|
|
route => $app->routes()->any('api'), |
56
|
|
|
|
|
|
|
url => "/api/v1", |
57
|
|
|
|
|
|
|
title => "Mojolicious App", |
58
|
|
|
|
|
|
|
favicon => "/images/favicon.png" |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The plugin allows you to run the Swagger UI component inside your Mojolicious application. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=begin html |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
src="https://gitlab.com/marghidanu/mojolicious-plugin-swaggerui/raw/master/share/images/Screenshot.png?inline=true"> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=end html |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 OPTIONS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 route |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
80
|
|
|
|
|
|
|
route => app()->routes()->any('/swagger') |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Route for the swagger-ui component. It defaults to a any route on C |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 url |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
88
|
|
|
|
|
|
|
url => '/swagger.json' |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Url for the JSON Swagger specification. It defaults to C. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
B |
94
|
|
|
|
|
|
|
L can expose the JSON Swagger spec under the base path route. |
95
|
|
|
|
|
|
|
You can just point the path in her and it will automatically work. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 title |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
100
|
|
|
|
|
|
|
title => 'Project Title' |
101
|
|
|
|
|
|
|
}; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The HTML title that you want to show on swagger-ui page. Deafult to 'Swagger UI' |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 favicon |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
108
|
|
|
|
|
|
|
favicon => '/images/favicon.png' |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Favicon which you want to associate with swagger-ui page. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
It will be served automatically from a 'public' directory if it exists. |
114
|
|
|
|
|
|
|
In case of non existence mojolicious default favicon will be displayed. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Tudor Marghidanu C |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 CREDITS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Gaurav Rai C |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Copyright (C) 2019, Tudor Marghidanu. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |