stas / jsonapi.rb

Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
MIT License
262 stars 58 forks source link

Let `code` be usable in error objects response #90

Closed curtis741 closed 7 months ago

curtis741 commented 1 year ago

Expected Behavior

That I can set the code in the error response objects

Actual Behavior

I can only set these attributes:

{"status"=>nil, "source"=>nil, "title"=>nil, "detail"=>nil}

Steps to Reproduce the Problem

  1. use render jsonapi_errors: { code: "some_code" }

I think it all comes from here: https://github.com/stas/jsonapi.rb/blob/07a96dc7b8d709b1281d09168746e46115c2fd0e/lib/jsonapi/error_serializer.rb#L11

and according to the spec I should be able to do this: https://jsonapi.org/format/#error-objects

maybe it should also support meta, id and links as well when you supply something that isn't an active model to jsonapi_errors ?

stas commented 1 year ago

@curtis741 sorry for the late response, please feel free to share a PR and we'll get it merged :pray:

curtis741 commented 1 year ago

@stas opened: https://github.com/stas/jsonapi.rb/pull/95

Faq commented 7 months ago

This can be closed as https://github.com/stas/jsonapi.rb/commit/7a105a5c4951e51f410533780a40b9a2efa79c28