attributes on the Schema

releases
Yanick Champoux 2023-10-31 16:45:42 -04:00
parent d7e7c7447c
commit b4eea91aae
2 changed files with 22 additions and 2 deletions

View File

@ -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;
}

View File

@ -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();