@@ -44,7 +44,8 @@ def app
44
44
'properties' => {
45
45
'code' => { 'type' => 'string' , 'description' => 'Error code' } ,
46
46
'message' => { 'type' => 'string' , 'description' => 'Error message' }
47
- }
47
+ } ,
48
+ 'required' => %w[ code message ]
48
49
)
49
50
50
51
expect ( subject [ 'definitions' ] . keys ) . to include 'ThisApi_Entities_Something'
@@ -66,24 +67,32 @@ def app
66
67
'code' => { 'type' => 'string' , 'description' => 'Error code' } ,
67
68
'message' => { 'type' => 'string' , 'description' => 'Error message' } ,
68
69
'attr' => { 'type' => 'string' , 'description' => 'Attribute' } } ,
69
- 'required' => [ 'attr' ]
70
+ 'required' => %w[ text colors hidden_attr created_at kind kind2 kind3 tags relation
71
+ attr code message ]
70
72
)
71
73
72
74
expect ( subject [ 'definitions' ] . keys ) . to include 'ThisApi_Entities_Kind'
73
75
expect ( subject [ 'definitions' ] [ 'ThisApi_Entities_Kind' ] ) . to eq (
74
- 'type' => 'object' , 'properties' => { 'title' => { 'type' => 'string' , 'description' => 'Title of the kind.' } ,
75
- 'content' => { 'description' => 'Content' , 'type' => 'string' ,
76
- 'x-some' => 'stuff' } }
76
+ 'type' => 'object' ,
77
+ 'properties' => {
78
+ 'title' => { 'type' => 'string' , 'description' => 'Title of the kind.' } ,
79
+ 'content' => { 'type' => 'string' , 'description' => 'Content' , 'x-some' => 'stuff' }
80
+ } ,
81
+ 'required' => %w[ title content ]
77
82
)
78
83
79
84
expect ( subject [ 'definitions' ] . keys ) . to include 'ThisApi_Entities_Relation'
80
85
expect ( subject [ 'definitions' ] [ 'ThisApi_Entities_Relation' ] ) . to eq (
81
- 'type' => 'object' , 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } }
86
+ 'type' => 'object' ,
87
+ 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } } ,
88
+ 'required' => %w[ name ]
82
89
)
83
90
84
91
expect ( subject [ 'definitions' ] . keys ) . to include 'ThisApi_Entities_Tag'
85
92
expect ( subject [ 'definitions' ] [ 'ThisApi_Entities_Tag' ] ) . to eq (
86
- 'type' => 'object' , 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } }
93
+ 'type' => 'object' ,
94
+ 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } } ,
95
+ 'required' => %w[ name ]
87
96
)
88
97
end
89
98
end
@@ -134,8 +143,10 @@ class Nested < Grape::Entity
134
143
end
135
144
expose :nested_required do
136
145
expose :some1 , documentation : { required : true , desc : 'Required some 1' }
137
- expose :attr , as : :some2 , documentation : { required : true , desc : 'Required some 2' }
138
- expose :some3 , documentation : { desc : 'Optional some 3' }
146
+ expose :attr , as : :some2 , documentation : { desc : 'Required some 2' }
147
+ expose :some3 , documentation : { required : false , desc : 'Optional some 3' }
148
+ expose :some4 , if : -> { true } , documentation : { desc : 'Optional some 4' }
149
+ expose :some5 , unless : -> { true } , documentation : { desc : 'Optional some 5' }
139
150
end
140
151
141
152
expose :nested_array , documentation : { type : 'Array' , desc : 'Nested array' } do
@@ -235,7 +246,8 @@ def app
235
246
'uuid' => { 'type' => 'string' , 'format' => 'own' , 'description' => 'customer uuid' ,
236
247
'example' => 'e3008fba-d53d-4bcc-a6ae-adc56dff8020' } ,
237
248
'color' => { 'type' => 'string' , 'enum' => %w[ red blue ] , 'description' => 'Color' }
238
- }
249
+ } ,
250
+ 'required' => %w[ guid uuid color ]
239
251
)
240
252
expect ( subject [ 'TheseApi_Entities_Kind' ] ) . to eql (
241
253
'type' => 'object' ,
@@ -244,30 +256,37 @@ def app
244
256
'readOnly' => true } ,
245
257
'title' => { 'type' => 'string' , 'description' => 'Title of the kind.' , 'readOnly' => false } ,
246
258
'type' => { 'type' => 'string' , 'description' => 'Type of the kind.' , 'readOnly' => true }
247
- }
259
+ } ,
260
+ 'required' => %w[ id title type ]
248
261
)
249
262
expect ( subject [ 'TheseApi_Entities_Tag' ] ) . to eql (
250
- 'type' => 'object' , 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' ,
251
- 'example' => 'random_tag' } }
263
+ 'type' => 'object' ,
264
+ 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' , 'example' => 'random_tag' } } ,
265
+ 'required' => %w[ name ]
252
266
)
253
267
expect ( subject [ 'TheseApi_Entities_Relation' ] ) . to eql (
254
- 'type' => 'object' , 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } }
268
+ 'type' => 'object' ,
269
+ 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } } ,
270
+ 'required' => %w[ name ]
255
271
)
256
272
expect ( subject [ 'TheseApi_Entities_Nested' ] ) . to eq (
273
+ 'type' => 'object' ,
257
274
'properties' => {
258
275
'nested' => {
259
276
'type' => 'object' ,
260
277
'properties' => {
261
278
'some1' => { 'type' => 'string' , 'description' => 'Nested some 1' } ,
262
279
'some2' => { 'type' => 'string' , 'description' => 'Nested some 2' }
263
280
} ,
264
- 'description' => 'Nested entity'
281
+ 'description' => 'Nested entity' ,
282
+ 'required' => %w[ some1 some2 ]
265
283
} ,
266
284
'aliased' => {
267
285
'type' => 'object' ,
268
286
'properties' => {
269
287
'some1' => { 'type' => 'string' , 'description' => 'Alias some 1' }
270
- }
288
+ } ,
289
+ 'required' => %w[ some1 ]
271
290
} ,
272
291
'deep_nested' => {
273
292
'type' => 'object' ,
@@ -277,17 +296,21 @@ def app
277
296
'properties' => {
278
297
'level_2' => { 'type' => 'string' , 'description' => 'Level 2' }
279
298
} ,
280
- 'description' => 'More deepest nested entity'
299
+ 'description' => 'More deepest nested entity' ,
300
+ 'required' => %w[ level_2 ]
281
301
}
282
302
} ,
283
- 'description' => 'Deep nested entity'
303
+ 'description' => 'Deep nested entity' ,
304
+ 'required' => %w[ level_1 ]
284
305
} ,
285
306
'nested_required' => {
286
307
'type' => 'object' ,
287
308
'properties' => {
288
309
'some1' => { 'type' => 'string' , 'description' => 'Required some 1' } ,
289
310
'some2' => { 'type' => 'string' , 'description' => 'Required some 2' } ,
290
- 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' }
311
+ 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' } ,
312
+ 'some4' => { 'type' => 'string' , 'description' => 'Optional some 4' } ,
313
+ 'some5' => { 'type' => 'string' , 'description' => 'Optional some 5' }
291
314
} ,
292
315
'required' => %w[ some1 some2 ]
293
316
} ,
@@ -298,14 +321,16 @@ def app
298
321
'properties' => {
299
322
'id' => { 'type' => 'integer' , 'format' => 'int32' , 'description' => 'Collection element id' } ,
300
323
'name' => { 'type' => 'string' , 'description' => 'Collection element name' }
301
- }
324
+ } ,
325
+ 'required' => %w[ id name ]
302
326
} ,
303
327
'description' => 'Nested array'
304
328
}
305
329
} ,
306
- 'type ' => 'object'
330
+ 'required ' => %w[ nested aliased deep_nested nested_required nested_array ]
307
331
)
308
332
expect ( subject [ 'TheseApi_Entities_NestedChild' ] ) . to eq (
333
+ 'type' => 'object' ,
309
334
'properties' => {
310
335
'nested' => {
311
336
'type' => 'object' ,
@@ -314,14 +339,16 @@ def app
314
339
'some2' => { 'type' => 'string' , 'description' => 'Nested some 2' } ,
315
340
'some3' => { 'type' => 'string' , 'description' => 'Nested some 3' }
316
341
} ,
317
- 'description' => 'Nested entity'
342
+ 'description' => 'Nested entity' ,
343
+ 'required' => %w[ some1 some2 some3 ]
318
344
} ,
319
345
'aliased' => {
320
346
'type' => 'object' ,
321
347
'properties' => {
322
348
'some1' => { 'type' => 'string' , 'description' => 'Alias some 1' } ,
323
349
'some2' => { 'type' => 'string' , 'description' => 'Alias some 2' }
324
- }
350
+ } ,
351
+ 'required' => %w[ some1 some2 ]
325
352
} ,
326
353
'deep_nested' => {
327
354
'type' => 'object' ,
@@ -337,20 +364,25 @@ def app
337
364
'description' => 'Level 3'
338
365
}
339
366
} ,
340
- 'description' => 'Level 2'
367
+ 'description' => 'Level 2' ,
368
+ 'required' => %w[ level_3 ]
341
369
}
342
370
} ,
343
- 'description' => 'More deepest nested entity'
371
+ 'description' => 'More deepest nested entity' ,
372
+ 'required' => %w[ level_2 ]
344
373
}
345
374
} ,
346
- 'description' => 'Deep nested entity'
375
+ 'description' => 'Deep nested entity' ,
376
+ 'required' => %w[ level_1 ]
347
377
} ,
348
378
'nested_required' => {
349
379
'type' => 'object' ,
350
380
'properties' => {
351
381
'some1' => { 'type' => 'string' , 'description' => 'Required some 1' } ,
352
382
'some2' => { 'type' => 'string' , 'description' => 'Required some 2' } ,
353
- 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' }
383
+ 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' } ,
384
+ 'some4' => { 'type' => 'string' , 'description' => 'Optional some 4' } ,
385
+ 'some5' => { 'type' => 'string' , 'description' => 'Optional some 5' }
354
386
} ,
355
387
'required' => %w[ some1 some2 ]
356
388
} ,
@@ -362,12 +394,13 @@ def app
362
394
'id' => { 'type' => 'integer' , 'format' => 'int32' , 'description' => 'Collection element id' } ,
363
395
'name' => { 'type' => 'string' , 'description' => 'Collection element name' } ,
364
396
'category' => { 'type' => 'string' , 'description' => 'Collection element category' }
365
- }
397
+ } ,
398
+ 'required' => %w[ id name category ]
366
399
} ,
367
400
'description' => 'Nested array'
368
401
}
369
402
} ,
370
- 'type ' => 'object'
403
+ 'required ' => %w[ nested aliased deep_nested nested_required nested_array ]
371
404
)
372
405
expect ( subject [ 'TheseApi_Entities_Polymorphic' ] ) . to eql (
373
406
'type' => 'object' ,
@@ -380,14 +413,15 @@ def app
380
413
)
381
414
382
415
expect ( subject [ 'TheseApi_Entities_MixedType' ] ) . to eql (
416
+ 'type' => 'object' ,
383
417
'properties' => {
384
418
'tags' => {
385
419
'description' => 'Tags' ,
386
420
'items' => { '$ref' => '#/definitions/TheseApi_Entities_TagType' } ,
387
421
'type' => 'array'
388
422
}
389
423
} ,
390
- 'type ' => 'object'
424
+ 'required ' => %w[ tags ]
391
425
)
392
426
393
427
expect ( subject [ 'TheseApi_Entities_SomeEntity' ] ) . to eql (
@@ -414,7 +448,8 @@ def app
414
448
} ,
415
449
'attr' => { 'type' => 'string' , 'description' => 'Attribute' }
416
450
} ,
417
- 'required' => %w[ attr ] ,
451
+ 'required' => %w[ text kind kind2 kind3 tags relation values nested nested_child
452
+ polymorphic mixed attr code message ] ,
418
453
'description' => 'TheseApi_Entities_SomeEntity model'
419
454
)
420
455
end
0 commit comments