.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" 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 turned on, 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 "Swagger2 3pm" .TH Swagger2 3pm "2016-04-17" "perl v5.22.1" "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" Swagger2 \- Swagger RESTful API Documentation .SH "VERSION" .IX Header "VERSION" 0.77 .SH "DESCRIPTION" .IX Header "DESCRIPTION" Swagger2 is a module for generating, parsing and transforming swagger \s-1API\s0 specification. It has support for reading swagger specification in \s-1JSON\s0 notation and as well \s-1YAML\s0 format. .PP Please read for an introduction to Swagger and reasons for why you would to use it. .SS "Mojolicious server side code generator" .IX Subsection "Mojolicious server side code generator" This distribution comes with a Mojolicious plugin, Mojolicious::Plugin::Swagger2, which can set up routes and perform input and output validation. .SS "Mojolicious client side code generator" .IX Subsection "Mojolicious client side code generator" Swagger2 also comes with a Swagger2::Client generator, which converts the client spec to perl code in memory. .SH "RECOMMENDED MODULES" .IX Header "RECOMMENDED MODULES" .IP "\(bu" 4 \&\s-1YAML\s0 parser .Sp A \s-1YAML\s0 parser is required if you want to read/write spec written in the \s-1YAML\s0 format. Supported modules are \s-1YAML::XS\s0, YAML::Syck, \s-1YAML\s0 and YAML::Tiny. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Swagger2; \& my $swagger = Swagger2\->new("/path/to/api\-spec.yaml"); \& \& # Access the raw specification values \& print $swagger\->api_spec\->get("/swagger"); \& \& # Returns the specification as a POD document \& print $swagger\->pod\->to_string; .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .SS "api_spec" .IX Subsection "api_spec" .Vb 2 \& $pointer = $self\->api_spec; \& $self = $self\->api_spec(Mojo::JSON::Pointer\->new({})); .Ve .PP Holds a Mojo::JSON::Pointer object containing your \s-1API\s0 specification. .SS "base_url" .IX Subsection "base_url" .Vb 1 \& $mojo_url = $self\->base_url; .Ve .PP Mojo::URL object that holds the location to the \s-1API\s0 endpoint. Note: This might also just be a dummy \s-1URL\s0 to . .SS "ua" .IX Subsection "ua" .Vb 2 \& $ua = $self\->ua; \& $self = $self\->ua(Mojo::UserAgent\->new); .Ve .PP A Mojo::UserAgent used to fetch remote documentation. .SS "url" .IX Subsection "url" .Vb 1 \& $mojo_url = $self\->url; .Ve .PP Mojo::URL object that holds the location to the documentation file. This can be both a location on disk or an \s-1URL\s0 to a server. A remote resource will be fetched using Mojo::UserAgent. .SH "METHODS" .IX Header "METHODS" .SS "expand" .IX Subsection "expand" .Vb 1 \& $swagger = $self\->expand; .Ve .PP This method returns a new \f(CW\*(C`Swagger2\*(C'\fR object, where all the references are resolved. .SS "find_operations" .IX Subsection "find_operations" .Vb 1 \& $operations = $self\->find_operations(\e%q); .Ve .PP Used to find a list of Operation Objects from the specification. \f(CW%q\fR can be: .PP .Vb 5 \& $all = $self\->find_operations; \& $operations = $self\->find_operations($operationId); \& $operations = $self\->find_operations({operationId => "listPets"}); \& $operations = $self\->find_operations({method => "post", path => "/pets"}); \& $operations = $self\->find_operations({tag => "pets"}); .Ve .SS "javascript_client" .IX Subsection "javascript_client" .Vb 1 \& $file = $self\->javascript_client; .Ve .PP Returns a Mojo::Asset::File object which points to a file containing a custom JavaScript file which can communicate with Mojolicious::Plugin::Swagger2. .PP See for source code. .PP \&\f(CW\*(C`swagger2\-client.js\*(C'\fR is currently \s-1EXPERIMENTAL\s0! .SS "load" .IX Subsection "load" .Vb 2 \& $self = $self\->load; \& $self = $self\->load($url); .Ve .PP Used to load the content from \f(CW$url\fR or \*(L"url\*(R". This method will try to guess the content type (\s-1JSON\s0 or \s-1YAML\s0) by looking at the content of the \f(CW$url\fR. .SS "new" .IX Subsection "new" .Vb 3 \& $self = Swagger2\->new($url); \& $self = Swagger2\->new(%attributes); \& $self = Swagger2\->new(\e%attributes); .Ve .PP Object constructor. .SS "parse" .IX Subsection "parse" .Vb 1 \& $self = $self\->parse($text); .Ve .PP Used to parse \f(CW$text\fR instead of loading data from \*(L"url\*(R". .PP The type of input text can be either \s-1JSON\s0 or \s-1YAML.\s0 It will default to \s-1YAML,\s0 but parse the text as \s-1JSON\s0 if it starts with \*(L"{\*(R". .SS "pod" .IX Subsection "pod" .Vb 1 \& $pod_object = $self\->pod; .Ve .PP Returns a Swagger2::POD object. .SS "to_string" .IX Subsection "to_string" .Vb 3 \& $json = $self\->to_string; \& $json = $self\->to_string("json"); \& $yaml = $self\->to_string("yaml"); .Ve .PP This method can transform this object into Swagger spec. .SS "validate" .IX Subsection "validate" .Vb 1 \& @errors = $self\->validate; .Ve .PP Will validate \*(L"api_spec\*(R" against Swagger RESTful \s-1API\s0 Documentation Specification , and return a list with all the errors found. See also \*(L"validate\*(R" in JSON::Validator. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2014\-2015, Jan Henning Thorsen .PP This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. .SH "AUTHOR" .IX Header "AUTHOR" Jan Henning Thorsen \- \f(CW\*(C`jhthorsen@cpan.org\*(C'\fR