diff --git a/lib/Dancer2/Plugin/JsonApi/Registry/Schema.pm b/lib/Dancer2/Plugin/JsonApi/Registry/Schema.pm index f0dcf87..047fefd 100644 --- a/lib/Dancer2/Plugin/JsonApi/Registry/Schema.pm +++ b/lib/Dancer2/Plugin/JsonApi/Registry/Schema.pm @@ -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; } diff --git a/t/registry-schema.t b/t/registry-schema.t index 18fb1f6..00ade44 100644 --- a/t/registry-schema.t +++ b/t/registry-schema.t @@ -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();