.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojolicious::Plugin::OpenAPI::SpecRenderer 3pm" .TH Mojolicious::Plugin::OpenAPI::SpecRenderer 3pm "2021-01-30" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojolicious::Plugin::OpenAPI::SpecRenderer \- Render OpenAPI specification .SH "SYNOPSIS" .IX Header "SYNOPSIS" .SS "With Mojolicious::Plugin::OpenAPI" .IX Subsection "With Mojolicious::Plugin::OpenAPI" .Vb 6 \& $app\->plugin(OpenAPI => { \& plugins => [qw(+SpecRenderer)], \& render_specification => 1, \& render_specification_for_paths => 1, \& %openapi_parameters, \& }); .Ve .PP See \*(L"register\*(R" in Mojolicious::Plugin::OpenAPI for what \&\f(CW%openapi_parameters\fR might contain. .SS "Standalone" .IX Subsection "Standalone" .Vb 2 \& use Mojolicious::Lite; \& plugin "Mojolicious::Plugin::OpenAPI::SpecRenderer"; \& \& # Some specification to render \& my $petstore = app\->home\->child("petstore.json"); \& \& get "/my\-spec" => sub { \& my $c = shift; \& my $path = $c\->param(\*(Aqpath\*(Aq) || \*(Aq/\*(Aq; \& state $custom_spec = JSON::Validator\->new\->schema($petstore\->to_string)\->bundle; \& $c\->openapi\->render_spec($path, $custom_spec); \& }; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojolicious::Plugin::OpenAPI::SpecRenderer will enable Mojolicious::Plugin::OpenAPI to render the specification in both \s-1HTML\s0 and \&\s-1JSON\s0 format. It can also be used \*(L"Standalone\*(R" if you just want to render the specification, and not add any \s-1API\s0 routes to your application. .PP See \*(L"\s-1TEMPLATING\*(R"\s0 to see how you can override parts of the rendering. .PP The human readable format focus on making the documentation printable, so you can easily share it with third parties as a \s-1PDF.\s0 If this documentation format is too basic or has missing information, then please report in suggestions for enhancements. .PP See for a demo. .SH "HELPERS" .IX Header "HELPERS" .SS "openapi.render_spec" .IX Subsection "openapi.render_spec" .Vb 4 \& $c = $c\->openapi\->render_spec; \& $c = $c\->openapi\->render_spec($json_path); \& $c = $c\->openapi\->render_spec($json_path, \e%custom_spec); \& $c = $c\->openapi\->render_spec("/user/{id}"); .Ve .PP Used to render the specification as either \*(L"html\*(R" or \*(L"json\*(R". Set the \&\*(L"stash\*(R" in Mojolicious variable \*(L"format\*(R" to change the format to render. .PP Will render the whole specification by default, but can also render documentation for a given OpenAPI path. .SS "openapi.rich_text" .IX Subsection "openapi.rich_text" .Vb 1 \& $bytestream = $c\->openapi\->rich_text($text); .Ve .PP Used to render the \*(L"description\*(R" in the specification with Text::Markdown if it is installed. Will just return the text if the module is not available. .SH "METHODS" .IX Header "METHODS" .SS "register" .IX Subsection "register" .Vb 1 \& $doc\->register($app, $openapi, \e%config); .Ve .PP Adds the features mentioned in the \*(L"\s-1DESCRIPTION\*(R"\s0. .PP \&\f(CW%config\fR is the same as passed on to \&\*(L"register\*(R" in Mojolicious::Plugin::OpenAPI. The following keys are used by this plugin: .PP \fIrender_specification\fR .IX Subsection "render_specification" .PP Render the whole specification as either \s-1HTML\s0 or \s-1JSON\s0 from \*(L"/:basePath\*(R". Example if \f(CW\*(C`basePath\*(C'\fR in your specification is \*(L"/api\*(R": .PP .Vb 2 \& GET https://api.example.com/api.html \& GET https://api.example.com/api.json .Ve .PP Disable this feature by setting \f(CW\*(C`render_specification\*(C'\fR to \f(CW0\fR. .PP \fIrender_specification_for_paths\fR .IX Subsection "render_specification_for_paths" .PP Render the specification from individual routes, using the \s-1OPTIONS HTTP\s0 method. Example: .PP .Vb 2 \& OPTIONS https://api.example.com/api/some/path.json \& OPTIONS https://api.example.com/api/some/path.json?method=post .Ve .PP Disable this feature by setting \f(CW\*(C`render_specification_for_paths\*(C'\fR to \f(CW0\fR. .SH "TEMPLATING" .IX Header "TEMPLATING" Overriding templates is \s-1EXPERIMENTAL,\s0 but not very likely to break in a bad way. .PP Mojolicious::Plugin::OpenAPI::SpecRenderer uses many template files to make up the human readable version of the spec. Each of them can be overridden by creating a file in your templates folder. .PP .Vb 10 \& mojolicious/plugin/openapi/layout.html.ep \& |\- mojolicious/plugin/openapi/head.html.ep \& | \*(Aq\- mojolicious/plugin/openapi/style.html.ep \& |\- mojolicious/plugin/openapi/header.html.ep \& | |\- mojolicious/plugin/openapi/logo.html.ep \& | \*(Aq\- mojolicious/plugin/openapi/toc.html.ep \& |\- mojolicious/plugin/openapi/intro.html.ep \& |\- mojolicious/plugin/openapi/resources.html.ep \& | \*(Aq\- mojolicious/plugin/openapi/resource.html.ep \& | |\- mojolicious/plugin/openapi/human.html.ep \& | |\- mojolicious/plugin/openapi/parameters.html.ep \& | \*(Aq\- mojolicious/plugin/openapi/response.html.ep \& | \*(Aq\- mojolicious/plugin/openapi/human.html.ep \& |\- mojolicious/plugin/openapi/references.html.ep \& |\- mojolicious/plugin/openapi/footer.html.ep \& |\- mojolicious/plugin/openapi/javascript.html.ep \& \*(Aq\- mojolicious/plugin/openapi/foot.html.ep .Ve .PP See the \s-1DATA\s0 section in the source code for more details on styling and markup structure. .PP .PP Variables available in the templates: .PP .Vb 3 \& %= $serialize\->($data_structure) \& %= $slugify\->(@str) \& %= $spec\->{info}{title} .Ve .PP In addition, there is a logo in \*(L"header.html.ep\*(R" that can be overriden by either changing the static file \*(L"mojolicious/plugin/openapi/logo.png\*(R" or set \&\*(L"openapi_spec_renderer_logo\*(R" in stash to a custom \s-1URL.\s0 .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious::Plugin::OpenAPI