APISchema
view release on metacpan or search on metacpan
lib/APISchema/DSL.pm view on Meta::CPAN
# cpan
use Exporter 'import';
use Path::Class qw(file);
my %schema_meta = (
( map { $_ => "${_}_resource" } qw(request response) ),
( map { $_ => $_ } qw(title description destination option) ),
);
our %METHODS = (
( map { $_ => $_ } qw(HEAD GET POST PUT DELETE PATCH) ),
FETCH => [qw(GET HEAD)],
);
our @DIRECTIVES = (qw(include filter resource title description), keys %METHODS);
our @EXPORT = @DIRECTIVES;
my $_directive = {};
sub process (&) {
my $dsl = shift;
t/Plack-App-APISchema-MockServer.t view on Meta::CPAN
my $res = $server->(GET '/maybe_bmi');
is $res->code, 200;
is $res->header('content-type'), 'application/json; charset=utf-8';
is $res->content, q!{"value":19.5}!;
};
}
sub status_201 : Tests {
my $schema = t::test::fixtures::prepare_bmi;
$schema->register_route(
method => 'PUT',
route => '/put_bmi',
request_resource => {
encoding => 'json',
body => 'figure',
},
response_resource => {
201 => {
encoding => 'json',
body => 'bmi',
},
},
);
my $app = Plack::App::APISchema::MockServer->new(schema => $schema)->to_app;
test_psgi $app => sub {
my $server = shift;
my $res = $server->(PUT '/put_bmi');
is $res->content, q!{"value":19.5}!;
is $res->code, 201;
};
}
sub status_204 : Tests {
my $schema = t::test::fixtures::prepare_bmi;
$schema->register_route(
method => 'GET',
route => '/empty',
t/fixtures/family.def view on Meta::CPAN
enum => [ 'success', 'failure' ],
example => 'success',
},
message => {
type => 'string',
example => 'OK',
},
},
};
PUT '/person' => {
title => 'Person PUT API',
description => 'Define a new person',
destination => {},
request => 'person',
response => 'result',
};
GET '/person' => {
title => 'Person GET API',
description => 'Retrieve a person',
destination => {},
request => { parameter => 'target' },
response => 'person',
};
PUT '/child' => {
title => 'Child PUT API',
description => 'Add a child to a person',
destination => {},
request => {
parameter => 'parent',
body => 'person',
},
response => 'result',
};
GET '/children' => {
( run in 0.446 second using v1.01-cache-2.11-cpan-4e96b696675 )