1Mojolicious::Plugin::OpUesneArPIC:o:nMGtourjiiodbleuistc:ei:doSuwPsae:gr:glPelrDu2og(ci3un)m:e:nOtpaetniAoPnI::Guides::Swagger2(3)
2
3
4

NAME

6       Mojolicious::Plugin::OpenAPI::Guides::Swagger2 - Swagger2 back compat
7       guide
8

OVERVIEW

10       This guide is useful if your application is already using
11       Mojolicious::Plugin::Swagger2.
12
13       The old plugin used to pass on $args and $cb to the action. This can be
14       emulated using an around_action hook. The "SYNOPSIS" below contains
15       example code that you can use to make your old controllers and actions
16       work with Mojolicious::Plugin::OpenAPI.
17

SYNOPSIS

19         package MyApp;
20         use Mojo::Base "Mojolicious";
21
22         sub startup {
23           my $self = shift;
24
25           # Load your specification
26           $self->plugin("OpenAPI" => {url => $app->home->rel_file("myapi.json")});
27
28           $self->hook(around_action => sub {
29             my ($next, $c, $action, $last) = @_;
30
31             # Do not call the action with ($args, $cb) unless it is an
32             # OpenAPI endpoint.
33             return $next->() unless $last;
34             return $next->() unless $c->openapi->spec;
35
36             # Render error document unless the input is valid
37             return unless $c->openapi->valid_input;
38
39             my $cb = sub {
40               my ($c, $data, $code) = @_;
41               $c->render(openapi => $data, status => $code);
42             };
43
44             # Call the action with ($args, $cb)
45             # NOTE! $c->validation->output will be removed in the future
46             return $c->$action($c->validation->output, $cb);
47           });
48         }
49

MOVING FORWARD

51       Note that the "around_action" hook above does not prevent you from
52       writing new actions using the standard Mojolicious::Plugin::OpenAPI
53       API. In the new actions, you can simply drop using $args and $cb and it
54       will work as expected as well.
55

SEE ALSO

57       <https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/master/t/swagger2.t>
58
59       Mojolicious::Plugin::OpenAPI.
60
61
62
63perl v5.38.0                 Mojol2i0c2i3o-u0s7:-:2P0lugin::OpenAPI::Guides::Swagger2(3)
Impressum