<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    Mojolicious::Plugin::OpenAPI - OpenAPI / Swagger plugin for Mojolicious

SYNOPSIS
      use Mojolicious::Lite;

      # Will be moved under "basePath", resulting in "POST /api/echo"
      post "/echo" =&gt; sub {

        # Validate input request or return an error document
        my $c = shift-&gt;openapi-&gt;valid_input or return;

        # Generate some data
        my $data = {body =&gt; $c-&gt;validation-&gt;param("body")};

        # Validate the output response and render it to the user agent
        $c-&gt;reply-&gt;openapi(200 =&gt; $data);
      }, "echo";

      # Load specification and start web server
      plugin OpenAPI =&gt; {url =&gt; "data://main/api.json"};
      app-&gt;start;

      __DATA__
      @@ api.json
      {
        "swagger" : "2.0",
        "info" : { "version": "0.8", "title" : "Pets" },
        "schemes" : [ "http" ],
        "basePath" : "/api",
        "paths" : {
          "/echo" : {
            "post" : {
              "x-mojo-name" : "echo",
              "parameters" : [
                { "in": "body", "name": "body", "schema": { "type" : "object" } }
              ],
              "responses" : {
                "200": {
                  "description": "Echo response",
                  "schema": { "type": "object" }
                }
              }
            }
          }
        }
      }

    See Mojolicious::Plugin::OpenAPI::Guides::Tutorial for a tutorial on how
    to write a "full" app with application class and controllers.

DESCRIPTION
    Mojolicious::Plugin::OpenAPI is Mojolicious::Plugin that add routes and
    input/output validation to your Mojolicious application based on a
    OpenAPI (Swagger) specification.

    Have a look at the "SEE ALSO" for references to more documentation, or
    jump right to the tutorial.

    Mojolicious::Plugin::OpenAPI will replace Mojolicious::Plugin::Swagger2.

    This plugin is currently EXPERIMENTAL.

HELPERS
  openapi.spec
      $hash = $c-&gt;openapi-&gt;spec($json_pointer)
      $hash = $c-&gt;openapi-&gt;spec("/info/title")
      $hash = $c-&gt;openapi-&gt;spec;

    Returns the OpenAPI specification. A JSON Pointer can be used to extract
    a given section of the specification. The default value of $json_pointer
    will be relative to the current operation. Example:

      {
        "paths": {
          "/pets": {
            "get": {
              // This datastructure is returned by default
            }
          }
        }
      }

  openapi.validate
      @errors = $c-&gt;openapi-&gt;validate;

    Used to validate a request. @errors holds a list of
    JSON::Validator::Error objects or empty list on valid input.

    Note that this helper is only for customization. You probably want
    "openapi.valid_input" in most cases.

    Validated input parameters will be copied to
    "Mojolicious::Controller/validation", which again can be extracted by
    the "name" in the parameters list from the spec. Example:

      # specification:
      "parameters": [{"in": "body", "name": "whatever", "schema": {"type": "object"}}],

      # controller
      my $body = $c-&gt;validation-&gt;param("whatever");

  openapi.valid_input
      $c = $c-&gt;openapi-&gt;valid_input;

    Returns the Mojolicious::Controller object if the input is valid or
    automatically render an error document if not and return false. See
    "SYNOPSIS" for example usage.

  reply.openapi
      $c-&gt;reply-&gt;openapi($status =&gt; $output);

    Will validate $output before passing it on to "render" in
    Mojolicious::Controller. Note that $output will be passed on using the
    format key in stash, which defaults to "json". This also goes for
    auto-rendering. Example:

      my $format = $c-&gt;stash("format") || "json";
      $c-&gt;render($format =&gt; \%output);

    $status is a HTTP status code.

METHODS
  register
      $self-&gt;register($app, \%config);

    Loads the OpenAPI specification, validates it and add routes to $app. It
    will also set up "HELPERS" and adds a before_render hook for
    auto-rendering of error documents.

    %config can have:

    * allow_invalid_ref

      The OpenAPI specification does not allow "$ref" at every level, but
      setting this flag to a true value will ignore the $ref check.

      Note that setting this attribute is discourage.

    * coerce

      See "coerce" in JSON::Validator for possible values that "coerce" can
      take.

      Default: 1

    * log_level

      "log_level" is used when logging invalid request/response error
      messages.

      Default: "warn".

    * route

      "route" can be specified in case you want to have a protected API.
      Example:

        $app-&gt;plugin(OpenAPI =&gt; {
          route =&gt; $app-&gt;routes-&gt;under("/api")-&gt;to("user#auth"),
          url   =&gt; $app-&gt;home-&gt;rel_file("cool.api"),
        });

    * spec_route_name

      Name of the route that handles the "basePath" part of the
      specification and serves the specification. Defaults to "x-mojo-name"
      in the specification at the top level.

    * url

      See "schema" in JSON::Validator for the different "url" formats that
      is accepted.

AUTHOR
    Jan Henning Thorsen

COPYRIGHT AND LICENSE
    Copyright (C) 2016, Jan Henning Thorsen

    This program is free software, you can redistribute it and/or modify it
    under the terms of the Artistic License version 2.0.

SEE ALSO
    * Mojolicious::Plugin::OpenAPI::Guides::Tutorial

    * &lt;http://thorsen.pm/perl/programming/2015/07/05/mojolicious-swagger2.ht
      ml&gt;.

    * OpenAPI specification &lt;https://openapis.org/specification&gt;

    * Mojolicious::Plugin::Swagger2.

</pre></body></html>