line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SwaggerUI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1192
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
213
|
use Mojo::File qw(path); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
64
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
584
|
use File::ShareDir qw(dist_dir); |
|
1
|
|
|
|
|
23683
|
|
|
1
|
|
|
|
|
243
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.0.3'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
1
|
|
|
1
|
1
|
51
|
my ($self, $app, $config) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
33
|
|
|
5
|
my $prefix = $config->{route} // $app->routes()->any('/swagger-ui'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# --- Configuring the Mojolicious path resolvers |
16
|
1
|
|
|
|
|
5
|
my $resources = path(dist_dir('Mojolicious-Plugin-SwaggerUI')) |
17
|
|
|
|
|
|
|
->child('resources'); |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
191
|
push(@{$app->static()->paths()}, $resources->child('public')->to_string()); |
|
1
|
|
|
|
|
9
|
|
20
|
1
|
|
|
|
|
37
|
push(@{$app->renderer()->paths()}, $resources->child('templates')->to_string()); |
|
1
|
|
|
|
|
6
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# --- Adding the route |
23
|
1
|
|
50
|
|
|
33
|
my $url = $config->{url} // '/v1'; |
24
|
1
|
|
|
|
|
7
|
$prefix->get(q(/) => { url => $url }) |
25
|
|
|
|
|
|
|
->name('swagger_ui'); |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
249
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=encoding utf8 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Mojolicious::Plugin::SwaggerUI - Swagger UI plugin for Mojolicious |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Mojolicious Lite |
41
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
42
|
|
|
|
|
|
|
route => app->routes()->any('/swagger'), |
43
|
|
|
|
|
|
|
url => '/swagger.json', |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
The plugin allows you to run the Swagger UI component inside your Mojolicious application. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=begin html |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
src="https://gitlab.com/marghidanu/mojolicious-plugin-swaggerui/raw/master/share/images/Screenshot.png?inline=true"> |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=end html |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 OPTIONS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 route |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
64
|
|
|
|
|
|
|
route => app()->routes()->any('/swagger') |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Route for the swagger-ui component. It defaults to a any route on C |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 url |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
plugin 'SwaggerUI' => { |
72
|
|
|
|
|
|
|
url => '/swagger.json' |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Url for the JSON Swagger specification. It defaults to C. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
B |
78
|
|
|
|
|
|
|
L can expose the JSON Swagger spec under the base path route. |
79
|
|
|
|
|
|
|
You can just point the path in her and it will automatically work. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Tudor Marghidanu L |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Copyright (C) 2019, Tudor Marghidanu. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |