@@ -137,6 +137,28 @@ class Nested < Grape::Entity
137
137
end
138
138
end
139
139
140
+ class NestedChild < Nested
141
+ expose :nested , documentation : { type : Hash , desc : 'Nested entity' } do
142
+ expose :some3 , documentation : { type : 'String' , desc : 'Nested some 3' }
143
+ end
144
+
145
+ expose :nested_with_alias , as : :aliased do
146
+ expose :some2 , documentation : { type : 'String' , desc : 'Alias some 2' }
147
+ end
148
+
149
+ expose :deep_nested , documentation : { type : 'Object' , desc : 'Deep nested entity' } do
150
+ expose :level_1 , documentation : { type : 'Object' , desc : 'More deepest nested entity' } do
151
+ expose :level_2 , documentation : { type : 'String' , desc : 'Level 2' } do
152
+ expose :level_3 , documentation : { type : 'String' , desc : 'Level 3' }
153
+ end
154
+ end
155
+ end
156
+
157
+ expose :nested_array , documentation : { type : 'Array' , desc : 'Nested array' } do
158
+ expose :category , documentation : { type : 'String' , desc : 'Collection element category' }
159
+ end
160
+ end
161
+
140
162
class Polymorphic < Grape ::Entity
141
163
expose :obj , as : :kind , if : lambda { |instance , _ |
142
164
instance . type == 'kind'
@@ -162,6 +184,7 @@ class SomeEntity < Grape::Entity
162
184
documentation : { type : 'TheseApi_Relation' , desc : 'A related model.' }
163
185
expose :values , using : TheseApi ::Entities ::Values , documentation : { desc : 'Tertiary kind.' }
164
186
expose :nested , using : TheseApi ::Entities ::Nested , documentation : { desc : 'Nested object.' }
187
+ expose :nested_child , using : TheseApi ::Entities ::NestedChild , documentation : { desc : 'Nested child object.' }
165
188
expose :polymorphic , using : TheseApi ::Entities ::Polymorphic , documentation : { desc : 'Polymorphic Model' }
166
189
expose :merged_attribute , using : ThisApi ::Entities ::Nested , merge : true
167
190
end
@@ -268,6 +291,70 @@ def app
268
291
} ,
269
292
'type' => 'object'
270
293
)
294
+ expect ( subject [ 'TheseApi_Entities_NestedChild' ] ) . to eq (
295
+ 'properties' => {
296
+ 'nested' => {
297
+ 'type' => 'object' ,
298
+ 'properties' => {
299
+ 'some1' => { 'type' => 'string' , 'description' => 'Nested some 1' } ,
300
+ 'some2' => { 'type' => 'string' , 'description' => 'Nested some 2' } ,
301
+ 'some3' => { 'type' => 'string' , 'description' => 'Nested some 3' }
302
+ } ,
303
+ 'description' => 'Nested entity'
304
+ } ,
305
+ 'aliased' => {
306
+ 'type' => 'object' ,
307
+ 'properties' => {
308
+ 'some1' => { 'type' => 'string' , 'description' => 'Alias some 1' } ,
309
+ 'some2' => { 'type' => 'string' , 'description' => 'Alias some 2' }
310
+ }
311
+ } ,
312
+ 'deep_nested' => {
313
+ 'type' => 'object' ,
314
+ 'properties' => {
315
+ 'level_1' => {
316
+ 'type' => 'object' ,
317
+ 'properties' => {
318
+ 'level_2' => {
319
+ 'type' => 'object' ,
320
+ 'properties' => {
321
+ 'level_3' => {
322
+ 'type' => 'string' ,
323
+ 'description' => 'Level 3'
324
+ }
325
+ } ,
326
+ 'description' => 'Level 2'
327
+ }
328
+ } ,
329
+ 'description' => 'More deepest nested entity'
330
+ }
331
+ } ,
332
+ 'description' => 'Deep nested entity'
333
+ } ,
334
+ 'nested_required' => {
335
+ 'type' => 'object' ,
336
+ 'properties' => {
337
+ 'some1' => { 'type' => 'string' , 'description' => 'Required some 1' } ,
338
+ 'some2' => { 'type' => 'string' , 'description' => 'Required some 2' } ,
339
+ 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' }
340
+ } ,
341
+ 'required' => %w[ some1 some2 ]
342
+ } ,
343
+ 'nested_array' => {
344
+ 'type' => 'array' ,
345
+ 'items' => {
346
+ 'type' => 'object' ,
347
+ 'properties' => {
348
+ 'id' => { 'type' => 'integer' , 'format' => 'int32' , 'description' => 'Collection element id' } ,
349
+ 'name' => { 'type' => 'string' , 'description' => 'Collection element name' } ,
350
+ 'category' => { 'type' => 'string' , 'description' => 'Collection element category' }
351
+ }
352
+ } ,
353
+ 'description' => 'Nested array'
354
+ }
355
+ } ,
356
+ 'type' => 'object'
357
+ )
271
358
expect ( subject [ 'TheseApi_Entities_Polymorphic' ] ) . to eql (
272
359
'type' => 'object' ,
273
360
'properties' => {
@@ -290,6 +377,8 @@ def app
290
377
'relation' => { '$ref' => '#/definitions/TheseApi_Entities_Relation' , 'description' => 'A related model.' } ,
291
378
'values' => { '$ref' => '#/definitions/TheseApi_Entities_Values' , 'description' => 'Tertiary kind.' } ,
292
379
'nested' => { '$ref' => '#/definitions/TheseApi_Entities_Nested' , 'description' => 'Nested object.' } ,
380
+ 'nested_child' => { '$ref' => '#/definitions/TheseApi_Entities_NestedChild' ,
381
+ 'description' => 'Nested child object.' } ,
293
382
'code' => { 'type' => 'string' , 'description' => 'Error code' } ,
294
383
'message' => { 'type' => 'string' , 'description' => 'Error message' } ,
295
384
'polymorphic' => { '$ref' => '#/definitions/TheseApi_Entities_Polymorphic' ,
0 commit comments