class ActiveModelSerializers::Adapter::JsonApi

def success_document

rubocop:disable Metrics/CyclomaticComplexity
}.reject! {|_,v| v.nil? }
jsonapi: toplevel_jsonapi
links: toplevel_links,
meta: toplevel_meta,
included: toplevel_included,
data: toplevel_data,
{
structure:
☑ toplevel_jsonapi
☑ toplevel_links
☑ toplevel_meta
☐ toplevel_included
☐ toplevel_data (required)
definition:
{http://jsonapi.org/format/#document-top-level Primary data}
def success_document
  is_collection = serializer.respond_to?(:each)
  serializers = is_collection ? serializer : [serializer]
  primary_data, included = resource_objects_for(serializers)
  hash = {}
  # toplevel_data
  # definition:
  #   oneOf
  #     resource
  #     array of unique items of type 'resource'
  #     null
  #
  # description:
  #   The document's "primary data" is a representation of the resource or collection of resources
  #   targeted by a request.
  #
  #   Singular: the resource object.
  #
  #   Collection: one of an array of resource objects, an array of resource identifier objects, or
  #   an empty array ([]), for requests that target resource collections.
  #
  #   None: null if the request is one that might correspond to a single resource, but doesn't currently.
  # structure:
  #  if serializable_resource.resource?
  #    resource
  #  elsif serializable_resource.collection?
  #    [
  #      resource,
  #      resource
  #    ]
  #  else
  #    nil
  #  end
  hash[:data] = is_collection ? primary_data : primary_data[0]
  # toplevel_included
  #   alias included
  # definition:
  #   array of unique items of type 'resource'
  #
  # description:
  #   To reduce the number of HTTP requests, servers **MAY** allow
  #   responses that include related resources along with the requested primary
  #   resources. Such responses are called "compound documents".
  # structure:
  #     [
  #       resource,
  #       resource
  #     ]
  hash[:included] = included if included.any?
  Jsonapi.add!(hash)
  if instance_options[:links]
    hash[:links] ||= {}
    hash[:links].update(instance_options[:links])
  end
  if is_collection && serializer.paginated?
    hash[:links] ||= {}
    hash[:links].update(pagination_links_for(serializer))
  end
  hash[:meta] = instance_options[:meta] unless instance_options[:meta].blank?
  hash
end