se Mojo::Base -base;
use Mojo::Asset::File;
use Mojo::JSON;
use Mojo::JSON::Pointer;
use Mojo::URL;
use File::Basename ();
use File::Spec;
use JSON::Validator::OpenAPI;
our $VERSION = '0.89';
# Shou
= shift;
return $self->_validator->_load_schema($self->url) if '' . $self->url;
return Mojo::JSON::Pointer->new({});
};
has base_url => sub {
my $self = shift;
my $url = Mojo::URL->new;
m
pecification => sub { shift->_validator->schema('http://swagger.io/v2/schema.json')->schema };
has _validator => sub { JSON::Validator::OpenAPI->new };
sub ua { shift->_validator->ua(@_) }
sub url
$base_url = $args[$i + 1] if $_ eq '-b';
$args = Mojo::JSON::decode_json($args[0]) if /^\{/;
$args->{$1} = $2 if /^(\w+)=(.*)/;
f $base_url;
eval {
my $res = $client->$method($args);
print $OUT $res->json ? Mojo::Util::dumper($res->json) : $res->body;
1;
} or do {
my $e = $@;
$e =~ s! at .* line.*!!s;
pec.json" if $_[0] eq 'perldoc';
return "Usage: mojo swagger2 pod path/to/spec.json" if $_[0] eq 'pod';
return "Usage: mojo swagger2 validate path/to/spec.json"
initializing = false;
ace.session.setMode("ace/mode/" + (ace.getValue().match(/^\s*\{/) ? "json" : "yaml"));
preview.scrollTop = scrollSave();
};
var render = function() {
scrollSa
Editor> is a WEB based Swagger2 API editor.
=head1 SYNOPSIS
$ mojo swagger2 edit /path/to/api.json --listen http://*:3000
=head1 ATTRIBUTES
=head2 specification_file
Returns path to swagger spe
render the POD if requested as C</.txt> instead.
=head2 POST /
Will L<parse|Swagger/parse> the JSON/YAML in the HTTP body and render it as POD.
=head1 METHODS
=head2 startup
Used to set up the L
package Swagger2::Client;
use Mojo::Base -base;
use Mojo::JSON;
use Mojo::UserAgent;
use Mojo::Util;
use Carp ();
use Swagger2;
use JSON::Validator::OpenAPI;
use constant DEBUG => $ENV{SWAGGER2_DEBU
t->_swagger->base_url) };
has ua => sub { Mojo::UserAgent->new };
has _validator => sub { JSON::Validator::OpenAPI->new; };
sub generate {
my $class = shift;
my ($swagger, $url) = _swagge
es = Mojo::Message::Response->new;
$res->headers->content_type('application/json');
$res->body(Mojo::JSON::encode_json({errors => $_[0]}));
$res->code(400)->message($res->default_message);
$re
package Swagger2::POD;
use Mojo::Base -base;
use Mojo::JSON 'encode_json';
use Mojo::Message::Response;
use Scalar::Util 'blessed';
use constant NO_DESCRIPTION => 'No description.';
require Swagger2;
obj->{$k} and $obj->{$k} eq Mojo::JSON->true;
return "$k=false" if blessed $obj->{$k} and $obj->{$k} eq Mojo::JSON->false;
return sprintf '%s=%s', $k, encode_json $obj->{$k} if ref $obj->{$k};
r
agger2;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::JSON;
use Mojo::Loader;
use Mojo::Util qw(decamelize deprecated);
use Swagger2;
use JSON::Validator::OpenAPI::Mojolicious;
use constant DEBUG
PACKAGE__, 'layouts/mojolicious_plugin_swagger.html.ep');
has url => '';
has _validator => sub { JSON::Validator::OpenAPI::Mojolicious->new; };
sub dispatch_to_swagger {
return undef unless $_[1]-
($c, $data) = @_;
my $self = $c->stash('swagger.plugin');
my $reply
= sub { $_[0]->send({json => {code => $_[2] || 200, id => $data->{id}, body => $_[1]}}) };
my $defaults = $self->{route_d
package Swagger2::SchemaValidator;
use Mojo::Base 'JSON::Validator::OpenAPI';
warn "# Swagger2::SchemaValidator is deprecated in favor of JSON::Validator::OpenAPI";
1;
=encoding utf8
=head1 NAME
Sw
Validator - DEPRECATED
=head1 DEPRECATION WARNING
See L<Swagger2>.
=head1 DESCRIPTION
Use L<JSON::Validator::OpenAPI> instead.
=head1 SEE ALSO
L<Swagger2> and L<JSON::Validator::OpenAPI>.
=cut