File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed
Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -87,15 +87,19 @@ def self.exposures
8787
8888 # This allows you to set a root element name for your representation.
8989 #
90- # @param singular [String] the root key to use when representing a single object
91- # @param plural [String] the root key to use when representing a collection of objects
90+ # @param plural [String] the root key to use when representing
91+ # a collection of objects. If missing or nil, no root key will be used
92+ # when representing collections of objects.
93+ # @param singular [String] the root key to use when representing
94+ # a single object. If missing or nil, no root key will be used when
95+ # representing an individual object.
9296 #
9397 # @example Entity Definition
9498 #
9599 # module API
96100 # module Entities
97101 # class User < Grape::Entity
98- # root 'user ', 'users '
102+ # root 'users ', 'user '
99103 # expose :id
100104 # end
101105 # end
@@ -120,9 +124,9 @@ def self.exposures
120124 # end
121125 # end
122126 # end
123- def self . root ( singular , plural = nil )
124- @root = singular
127+ def self . root ( plural , singular = nil )
125128 @collection_root = plural
129+ @root = singular
126130 end
127131
128132 # This convenience method allows you to instantiate one or more entities by
Original file line number Diff line number Diff line change 6262 describe '.root' do
6363 context 'with singular and plural root keys' do
6464 before ( :each ) do
65- subject . root 'thing ' , 'things '
65+ subject . root 'things ' , 'thing '
6666 end
6767
6868 context 'with a single object' do
8888
8989 context 'with singular root key' do
9090 before ( :each ) do
91- subject . root 'thing'
91+ subject . root nil , 'thing'
9292 end
9393
9494 context 'with a single object' do
112112
113113 context 'with plural root key' do
114114 before ( :each ) do
115- subject . root nil , 'things'
115+ subject . root 'things'
116116 end
117117
118118 context 'with a single object' do
You can’t perform that action at this time.
0 commit comments