-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add jsonapi_include_toplevel_object adapter option #1991
base: master
Are you sure you want to change the base?
Conversation
@beauby do you have opinions on this? |
I agree this should be overridable locally (and although it is weird that |
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.
Idea is good, needs discussion of option name and distinction between turning on default via an option and passing in the jsonapi
object in an option.
@@ -2,7 +2,7 @@ | |||
|
|||
module ActiveModelSerializers | |||
class SerializableResource | |||
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter, :meta, :meta_key, :links, :serialization_context, :key_transform]) | |||
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter, :meta, :meta_key, :links, :serialization_context, :key_transform, :jsonapi_include_toplevel_object]) |
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 just be jsonapi_object, I think. (jsonapi can't be the key since render uses that
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.
A question I have is what should be different between wanting to pass in your own jsonapi
object vs. telling the adapter to include the default one?
Purpose
Sometimes, I have the need to include the JSON-API top level object while it's disabled in the config. This PR adds the functionality to include it on the fly using an option to the serializer:
Changes
Pass instance options to the
ActiveModelSerializers::Adapter::JsonApi::Jsonapi
model, and modify theinclude_object?
method to use the value of the instance option:jsonapi_include_toplevel_object
instead of the global config, if given.Caveats
Related GitHub issues
Additional helpful information