-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for jsonapi top level member #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2f40b25
to
336972d
Compare
47509d8
to
c3c992c
Compare
@@ -9,3 +9,5 @@ The following configuration options can be set on `ActiveModel::Serializer.confi | |||
## JSON API | |||
|
|||
- `jsonapi_resource_type`: Whether the `type` attributes of resources should be singular or plural. Possible values: `:singular, :plural`. Default: `:plural`. | |||
- `jsonapi_toplevel_member`: Whether to include a [top level JSON API member](http://jsonapi.org/format/#document-jsonapi-object) in the response document. Default: `false`. | |||
- `jsonapi_version`: The latest version of the spec the API conforms to. Used when `jsonapi_toplevel_member` is `true`. Default: `'1.0'`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
This is cool, I'm not sure about the adapter options, feels like edge cases for me that might add complexity to maintain. |
Hmm namespacing config options... I remember someone very wise mentioning that in #1097 :p |
So lets remove the adapter options? So can add it if someone supports/needs it 😁 |
9b8716b
to
1a167f8
Compare
1a167f8
to
8ab4c4a
Compare
Done 👍 |
I'm good with this. 👍 |
end | ||
|
||
def test_toplevel_jsonapi_meta | ||
with_adapter :json_api do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for with_adapter
. Just pass in adapter: :json_api
@@ -8,6 +8,8 @@ module Configuration | |||
base.config.array_serializer = ActiveModel::Serializer::ArraySerializer | |||
base.config.adapter = :flatten_json | |||
base.config.jsonapi_resource_type = :plural | |||
base.config.jsonapi_toplevel_member = false | |||
base.config.jsonapi_version = '1.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be in the JsonApi adapter IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense.
Alternative implementation at #1050 which was rebased to include this work |
needs rebase :-( |
Closing in favor of #1050. |
C.f. http://jsonapi.org/format/#document-top-level
Supports :
jsonapi_toplevel_member
, that decides whether a top leveljsonapi
member will be included in each serialized resource, which defaults tofalse
,jsonapi_version
, which defaults to1.0
,jsonapi_toplevel_meta
.This PR is based on #1121 for convenience.