mirror of
https://github.com/samsonjs/grape-active_model_serializers.git
synced 2026-04-02 10:05:50 +00:00
Ensures there is a root available for arrays
This commit is contained in:
parent
7933a1796b
commit
3b02d16211
2 changed files with 7 additions and 1 deletions
|
|
@ -13,6 +13,11 @@ module Grape
|
|||
@endpoint = env["api.endpoint"]
|
||||
options = endpoint.namespace_options.merge(endpoint.route_options)
|
||||
|
||||
if resource.is_a?(Array) && !resource.empty?
|
||||
# ensure we have an root to fallback on
|
||||
endpoint.controller_name = resource.first.class.name.underscore.pluralize
|
||||
end
|
||||
|
||||
serializer = ::ActiveModel::Serializer.build_json(endpoint, resource, options)
|
||||
|
||||
if serializer
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#
|
||||
module Grape
|
||||
module EndpointExtension
|
||||
attr_accessor :controller_name
|
||||
|
||||
def namespace_options
|
||||
settings[:namespace] ? settings[:namespace].options : {}
|
||||
end
|
||||
|
|
@ -18,7 +20,6 @@ module Grape
|
|||
def serialization_scope; end
|
||||
def _serialization_scope; end
|
||||
def url_options; end
|
||||
def controller_name; end
|
||||
end
|
||||
|
||||
Endpoint.send(:include, EndpointExtension)
|
||||
|
|
|
|||
Loading…
Reference in a new issue