jsonapi field in the ::Schema
This commit is contained in:
parent
e679ab442d
commit
d51ee14eac
@ -1,7 +1,7 @@
|
||||
package Dancer2::Plugin::JsonApi::Registry;
|
||||
|
||||
use 5.32.0;
|
||||
use Dancer2::Plugin::JsonApi::Registry::Type;
|
||||
use Dancer2::Plugin::JsonApi::Registry::Schema;
|
||||
|
||||
use Carp;
|
||||
|
||||
@ -15,14 +15,14 @@ The registry for the different types of data managed by the plugin.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 serialize($type,$data,$meta={})
|
||||
=head2 serialize($type,$data,$extra_data={})
|
||||
|
||||
Returns the serialized form of C<$data>.
|
||||
|
||||
=cut
|
||||
|
||||
sub serialize($self,$type,$data,$meta={}) {
|
||||
return {};
|
||||
sub serialize($self,$type,$data,$extra_data={}) {
|
||||
return $self->type($type)->top_level_serialize($data,$extra_data);
|
||||
}
|
||||
|
||||
has types => (
|
||||
@ -37,7 +37,7 @@ Adds a data type to the registry.
|
||||
=cut
|
||||
|
||||
sub add_type($self,$type,$definition={}) {
|
||||
$self->{types}{$type} = Dancer2::Plugin::JsonApi::Registry::Type->new(
|
||||
$self->{types}{$type} = Dancer2::Plugin::JsonApi::Registry::Schema->new(
|
||||
type => $type,
|
||||
%$definition
|
||||
);
|
||||
|
14
t/registry.t
14
t/registry.t
@ -10,14 +10,16 @@ $registry->add_type(
|
||||
people => {
|
||||
id => 'id',
|
||||
links => {
|
||||
self => sub($data) {
|
||||
return "/peoples/$data->{id}"
|
||||
self => sub ( $data, @ ) {
|
||||
return "/peoples/$data->{id}";
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
} } );
|
||||
|
||||
isa_ok $registry->type('people') => 'Dancer2::Plugin::JsonApi::Registry::Type';
|
||||
isa_ok $registry->type('people') =>
|
||||
'Dancer2::Plugin::JsonApi::Registry::Schema';
|
||||
|
||||
like(
|
||||
$registry->serialize( people => {} ),
|
||||
{ jsonapi => { version => '1.0' } } );
|
||||
|
||||
done_testing();
|
||||
|
Loading…
Reference in New Issue
Block a user