APISchema
view release on metacpan or search on metacpan
lib/APISchema/Generator/Markdown/ExampleFormatter.pm view on Meta::CPAN
my $resource = $body->definition or return '';
my $example = $self->example($resource);
return '' unless defined $example;
return ref $example ? json($example) : $example;
}
sub header_and_body {
my ($self) = @_;
join("\n", grep { defined $_ && length $_ > 0 } $self->header, $self->body);
}
1;
lib/APISchema/Generator/Markdown/Formatter.pm view on Meta::CPAN
use Exporter qw(import);
our @EXPORT = qw(type json pretty_json code restriction desc anchor method methods content_type http_status http_status_code);
# cpan
use HTTP::Status qw(status_message);
use URI::Escape qw(uri_escape_utf8);
use JSON::XS ();
my $JSON = JSON::XS->new->canonical(1);
use constant +{
RESTRICTIONS => [qw(required max_items min_items max_length min_length maximum minimum pattern)],
SHORT_DESCRIPTION_LENGTH => 100,
};
sub type ($); # type has recursive call
sub type ($) {
my $def = shift;
my $bar = '|';
if (ref $def) {
lib/APISchema/Generator/Markdown/Formatter.pm view on Meta::CPAN
push @result, _code sprintf "$r(%s)", json $def->{$r};
}
}
return join ' ', @result;
}
sub desc ($) {
my $text = shift || '';
$text = $text =~ s/[\r\n].*\z//sr;
$text = substr($text, 0, SHORT_DESCRIPTION_LENGTH) . '...'
if length($text) > SHORT_DESCRIPTION_LENGTH;
return $text;
}
sub method ($) {
my $method = shift;
return $method->[0] if (ref $method || '') eq 'ARRAY';
return $method;
}
sub methods ($) {
my $method = shift;
return join ', ', map { _code($_) } @$method
if (ref $method || '') eq 'ARRAY';
return _code($method);
}
sub content_type ($) {
my $type = shift;
return '-' unless length($type);
return "`$type`";
}
sub http_status ($) {
my $code = shift;
return undef unless $code;
return join(' ', $code, status_message($code));
}
sub http_status_code {
t/Plack-Middleware-APISchema-RequestValidator.t view on Meta::CPAN
X_Weight => 50,
);
is $res->code, HTTP_UNPROCESSABLE_ENTITY;
cmp_deeply $res->content, json({
header => {
attribute => 'Valiemon::Attributes::Required',
position => '/$ref/required',
message => "Contents do not match resource 'figure_header'",
encoding => 'perl',
actual => {
content_length => 0,
x_weight => 50,
content_type => "application/x-www-form-urlencoded",
host => "localhost",
},
expected => $schema->get_resource_by_name('figure_header')->definition,
},
});
done_testing;
}
};
( run in 0.376 second using v1.01-cache-2.11-cpan-65fba6d93b7 )