e APISchema::JSON;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw(encode_json_canonical);
use JSON::XS;
my $json = JSON::XS->new->utf8->canonical(1);
sub encode_json_canonical {
my ($value) = @_;
$json->encode($value);
}
1;
ter;
use 5.014;
use strict;
use warnings;
# lib
use APISchema::Generator::Markdown::Formatter qw(json);
# cpan
use URI::Escape qw(uri_escape_utf8);
use Class::Accessor::Lite (
new => 1,
ro =
e = $self->example($resource);
return '' unless defined $example;
return ref $example ? json($example) : $example;
}
sub header_and_body {
my ($self) = @_;
join("\n", grep { defined
?>"></a> `<?= $resource->title ?>` : <?= type($resource->definition) ?>
```javascript
<?= pretty_json $r->example($resource->definition) ?>
```
?= $resource->definition->{description} || ''
#### Pr
Plack::Util::Accessor qw(schema);
use Plack::Request;
use Encode qw(encode_utf8);
use APISchema::JSON;
use APISchema::Generator::Router::Simple;
use APISchema::Generator::Markdown::ResourceResolver;
# TODO: format body with encoding
return [$default_code, ['Content-Type' => 'application/json; charset=utf-8'], [encode_utf8($formatter->body)]];
}
sub router {
my ($self) = @_;
ret
cpan
use JSON::XS qw(decode_json);
use URL::Encode qw(url_params_mixed);
use Class::Accessor::Lite ( new => 1 );
sub perl {
my ($self, $body) = @_;
return $body;
}
my $JSON = JSON::XS->new-
>utf8;
sub json {
my ($self, $body) = @_;
return $JSON->decode($body);
}
sub url_parameter {
my ($self, $body) = @_;
return undef unless defined $body;
return url_params_mixed($bo
lack::Request;
use APISchema::Generator::Router::Simple;
use APISchema::Validator;
use APISchema::JSON;
use constant DEFAULT_VALIDATOR_CLASS => 'Valiemon';
sub call {
my ($self, $env) = @_;
result);
return [
$status_code,
[ 'Content-Type' => 'application/json' ],
[ encode_json_canonical($errors) ],
] if scalar keys %$errors;
$self->app->($env);
}
sub
pe 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 => 10
in $bar, map { code($_) } @{$type} if ref $type eq 'ARRAY';
}
return 'undefined';
}
sub json ($) {
my $x = shift;
if (ref $x eq 'SCALAR') {
if ($$x eq 1) {
$x = '
PISchema::Generator::Markdown::ResourceResolver;
use 5.014;
use strict;
use warnings;
# cpan
use JSON::Pointer;
use Class::Accessor::Lite (
new => 1,
ro => [qw(schema)],
);
sub _foreach_pro
y $ref = $definition->{'$ref'};
if ($ref) {
$ref = $ref =~ s/^#//r;
my $def = JSON::Pointer->get($self->schema, $ref);
return $self->_collect_properties($path, $def)
y $ref = $definition->{'$ref'};
if ($ref) {
$ref = $ref =~ s/^#//r;
my $def = JSON::Pointer->get($self->schema, $ref);
return ($self->_collect_example($path, $def), 1) if $
ack::Response;
use APISchema::Generator::Router::Simple;
use APISchema::Validator;
use APISchema::JSON;
use constant DEFAULT_VALIDATOR_CLASS => 'Valiemon';
sub call {
my ($self, $env) = @_;
500,
[ 'Content-Type' => 'application/json', 'X-Error-Cause' => $error_cause ],
[ encode_json_canonical($errors) ],
);
return;
=> [qw(header parameter body)],
DEFAULT_ENCODING_SPEC => {
'application/json' => 'json',
'application/x-www-form-urlencoded' => 'url_parameter',
# TODO ya