GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mojolicious::Plugin::OpenAPI::Guides::Swagger2(3) User Contributed Perl Documentation Mojolicious::Plugin::OpenAPI::Guides::Swagger2(3)

Mojolicious::Plugin::OpenAPI::Guides::Swagger2 - Swagger2 back compat guide

This guide is useful if your application is already using Mojolicious::Plugin::Swagger2.

The old plugin used to pass on $args and $cb to the action. This can be emulated using an around_action hook. The "SYNOPSIS" below contains example code that you can use to make your old controllers and actions work with Mojolicious::Plugin::OpenAPI.

  package MyApp;
  use Mojo::Base "Mojolicious";
  sub startup {
    my $self = shift;
    # Load your specification
    $self->plugin("OpenAPI" => {url => $app->home->rel_file("myapi.json")});
    $self->hook(around_action => sub {
      my ($next, $c, $action, $last) = @_;
      # Do not call the action with ($args, $cb) unless it is an
      # OpenAPI endpoint.
      return $next->() unless $last;
      return $next->() unless $c->openapi->spec;
      # Render error document unless the input is valid
      return unless $c->openapi->valid_input;
      my $cb = sub {
        my ($c, $data, $code) = @_;
        $c->render(openapi => $data, status => $code);
      };
      # Call the action with ($args, $cb)
      # NOTE! $c->validation->output will be removed in the future
      return $c->$action($c->validation->output, $cb);
    });
  }

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

<https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/master/t/swagger2.t>

Mojolicious::Plugin::OpenAPI.

2020-10-18 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.