jsonapi-rb / jsonapi-rails

Rails gem for fast jsonapi-compliant APIs.
http://jsonapi-rb.org
MIT License
317 stars 62 forks source link

aliased attribute name will produce incorrect errors #104

Open bsylvain opened 5 years ago

bsylvain commented 5 years ago

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.

beauby commented 5 years ago

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.