attributes on the Schema
This commit is contained in:
parent
d7e7c7447c
commit
b4eea91aae
@ -5,7 +5,7 @@ package Dancer2::Plugin::JsonApi::Registry::Schema;
|
||||
use Moo;
|
||||
|
||||
use experimental qw/ signatures /;
|
||||
use List::AllUtils qw/ pairmap /;
|
||||
use List::AllUtils qw/ pairmap pairgrep /;
|
||||
|
||||
=head1 ATTRIBUTES
|
||||
|
||||
@ -58,7 +58,6 @@ sub top_level_serialize ( $self, $data, $extra_data = {} ) {
|
||||
$serial->{meta} = gen_links($self->top_level_meta,$data,$extra_data)
|
||||
if $self->top_level_meta;
|
||||
|
||||
|
||||
return $serial;
|
||||
|
||||
}
|
||||
@ -81,6 +80,8 @@ sub serialize ( $self, $data, $extra_data = {} ) {
|
||||
$s->{links} = gen_links($self->links,$data,$extra_data);
|
||||
}
|
||||
|
||||
$s->{attributes} = +{ pairgrep { $a ne $self->id } %$data };
|
||||
|
||||
return $s;
|
||||
|
||||
}
|
||||
|
@ -49,4 +49,23 @@ like(
|
||||
)->top_level_serialize( {}, { bar => 'yup' } ),
|
||||
{ meta => { foo => 1, bar => 'yup' } } );
|
||||
|
||||
|
||||
subtest 'attributes' => sub {
|
||||
my $serialized =
|
||||
Dancer2::Plugin::JsonApi::Registry::Schema->new(
|
||||
type => 'thing',
|
||||
)->serialize( { id => 1, foo => 'bar'});
|
||||
|
||||
is $serialized => {
|
||||
type => 'thing',
|
||||
id => 1,
|
||||
attributes => {
|
||||
foo => 'bar',
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
done_testing();
|
||||
|
Loading…
Reference in New Issue
Block a user