APISchema
view release on metacpan or search on metacpan
t/APISchema-DSL.t view on Meta::CPAN
is_deeply [ sort {
$a->title cmp $b->title;
} @{$schema->get_resources} ], [ {
title => 'bmi',
definition => {
type => 'object',
description => 'Body mass index',
properties => {
value => {
type => 'number',
description => 'bmi value',
example => 19.5,
},
},
required => ['value'],
},
}, {
title => 'figure',
definition => {
type => 'object',
description => 'Figure, which includes weight and height',
properties => {
weight => {
type => 'number',
description => 'Weight(kg)',
example => 50,
},
height => {
type => 'number',
description => 'Height(m)',
example => 1.6,
},
},
required => ['weight', 'height'],
},
} ];
my $routes = $schema->get_routes;
is scalar @$routes, 1;
is $routes->[0]->route, '/bmi';
is $routes->[0]->title, 'BMI API';
is $routes->[0]->description, 'This API calculates your BMI.';
is_deeply $routes->[0]->destination, {
controller => 'BMI',
action => 'calculate',
};
cmp_deeply $routes->[0]->option, { on_match => code(sub { 1 }) };
is $routes->[0]->request_resource, 'figure';
is $routes->[0]->response_resource, 'bmi';
};
dies_ok {
my $schema = APISchema::DSL::process {
include 'not-such-file';
};
};
dies_ok {
my $schema = APISchema::DSL::process {
include 't/fixtures/syntax-error.def';
};
};
dies_ok {
my $schema = APISchema::DSL::process {
include 't/fixtures/runtime-error.def';
};
};
}
sub with_unicode : Tests {
my $schema = APISchema::DSL::process {
include 't/fixtures/user.def';
};
isa_ok $schema, 'APISchema::Schema';
is $schema->title, decode_utf8('ã¦ã¼ã¶ã¼');
is $schema->description, decode_utf8('ã¦ã¼ã¶ã¼ã®å®ç¾©');
cmp_deeply $schema->get_resource_by_name('user')->{definition}, {
type => 'object',
description => decode_utf8('ã¦ã¼ã¶ã¼'),
properties => {
first_name => {
type => 'string',
description => decode_utf8('å§'),
example => decode_utf8('å°é£¼'),
},
last_name => {
type => 'string',
description => decode_utf8('å'),
example => decode_utf8('å¼¾'),
},
},
required => ['first_name', 'last_name'],
};
}
( run in 0.807 second using v1.01-cache-2.11-cpan-39bf76dae61 )