Merge branch 'attributes'

This commit is contained in:
Yanick Champoux 2023-10-31 16:45:49 -04:00
commit a5e552b06e
2 changed files with 22 additions and 2 deletions

View File

@ -5,7 +5,7 @@ package Dancer2::Plugin::JsonApi::Registry::Schema;
use Moo; use Moo;
use experimental qw/ signatures /; use experimental qw/ signatures /;
use List::AllUtils qw/ pairmap /; use List::AllUtils qw/ pairmap pairgrep /;
=head1 ATTRIBUTES =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) $serial->{meta} = gen_links($self->top_level_meta,$data,$extra_data)
if $self->top_level_meta; if $self->top_level_meta;
return $serial; return $serial;
} }
@ -81,6 +80,8 @@ sub serialize ( $self, $data, $extra_data = {} ) {
$s->{links} = gen_links($self->links,$data,$extra_data); $s->{links} = gen_links($self->links,$data,$extra_data);
} }
$s->{attributes} = +{ pairgrep { $a ne $self->id } %$data };
return $s; return $s;
} }

View File

@ -49,4 +49,23 @@ like(
)->top_level_serialize( {}, { bar => 'yup' } ), )->top_level_serialize( {}, { bar => 'yup' } ),
{ meta => { foo => 1, 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(); done_testing();