Add jsonapi_include_toplevel_object adapter option#1991
Add jsonapi_include_toplevel_object adapter option#1991nilsding wants to merge 1 commit intorails-api:masterfrom
Conversation
|
@beauby do you have opinions on this? |
|
I agree this should be overridable locally (and although it is weird that |
bf4
left a comment
There was a problem hiding this comment.
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.
| 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.
Should just be jsonapi_object, I think. (jsonapi can't be the key since render uses that
There was a problem hiding this comment.
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::Jsonapimodel, and modify theinclude_object?method to use the value of the instance option:jsonapi_include_toplevel_objectinstead of the global config, if given.Caveats
Related GitHub issues
Additional helpful information