jsonapi-rails icon indicating copy to clipboard operation
jsonapi-rails copied to clipboard

aliased attribute name will produce incorrect errors

Open bsylvain opened this issue 6 years ago • 1 comments
trafficstars

The error pointer do not match the alias used in the serializer.

serializer :

attribute :reply do
  @object.content
end

response when there is an active record error : {"errors":[{"title":"Invalid content","detail":"Nouveau commentaire est trop court (au moins 16 caractères)","source":{}}],"jsonapi":{"version":"1.0"}}

Ideally source should contain a pointer to reply. I am not sure If it is possible to correctly alias the error with the declaration done in a bloc.

bsylvain avatar Mar 08 '19 17:03 bsylvain

The errors are set by the deserializer, which are independent from the serializers. The deserializable module maintains a reverse mapping for renamed keys, which is used to generate the JSON pointer.

beauby avatar Mar 08 '19 17:03 beauby