@@ -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,11 @@ 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' }
150
+ expose :some6 , expose_nil : false , documentation : { desc : 'Optional some 6' }
139
151
end
140
152
141
153
expose :nested_array , documentation : { type : 'Array' , desc : 'Nested array' } do
@@ -235,7 +247,8 @@ def app
235
247
'uuid' => { 'type' => 'string' , 'format' => 'own' , 'description' => 'customer uuid' ,
236
248
'example' => 'e3008fba-d53d-4bcc-a6ae-adc56dff8020' } ,
237
249
'color' => { 'type' => 'string' , 'enum' => %w[ red blue ] , 'description' => 'Color' }
238
- }
250
+ } ,
251
+ 'required' => %w[ guid uuid color ]
239
252
)
240
253
expect ( subject [ 'TheseApi_Entities_Kind' ] ) . to eql (
241
254
'type' => 'object' ,
@@ -244,30 +257,37 @@ def app
244
257
'readOnly' => true } ,
245
258
'title' => { 'type' => 'string' , 'description' => 'Title of the kind.' , 'readOnly' => false } ,
246
259
'type' => { 'type' => 'string' , 'description' => 'Type of the kind.' , 'readOnly' => true }
247
- }
260
+ } ,
261
+ 'required' => %w[ id title type ]
248
262
)
249
263
expect ( subject [ 'TheseApi_Entities_Tag' ] ) . to eql (
250
- 'type' => 'object' , 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' ,
251
- 'example' => 'random_tag' } }
264
+ 'type' => 'object' ,
265
+ 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' , 'example' => 'random_tag' } } ,
266
+ 'required' => %w[ name ]
252
267
)
253
268
expect ( subject [ 'TheseApi_Entities_Relation' ] ) . to eql (
254
- 'type' => 'object' , 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } }
269
+ 'type' => 'object' ,
270
+ 'properties' => { 'name' => { 'type' => 'string' , 'description' => 'Name' } } ,
271
+ 'required' => %w[ name ]
255
272
)
256
273
expect ( subject [ 'TheseApi_Entities_Nested' ] ) . to eq (
274
+ 'type' => 'object' ,
257
275
'properties' => {
258
276
'nested' => {
259
277
'type' => 'object' ,
260
278
'properties' => {
261
279
'some1' => { 'type' => 'string' , 'description' => 'Nested some 1' } ,
262
280
'some2' => { 'type' => 'string' , 'description' => 'Nested some 2' }
263
281
} ,
264
- 'description' => 'Nested entity'
282
+ 'description' => 'Nested entity' ,
283
+ 'required' => %w[ some1 some2 ]
265
284
} ,
266
285
'aliased' => {
267
286
'type' => 'object' ,
268
287
'properties' => {
269
288
'some1' => { 'type' => 'string' , 'description' => 'Alias some 1' }
270
- }
289
+ } ,
290
+ 'required' => %w[ some1 ]
271
291
} ,
272
292
'deep_nested' => {
273
293
'type' => 'object' ,
@@ -277,17 +297,22 @@ def app
277
297
'properties' => {
278
298
'level_2' => { 'type' => 'string' , 'description' => 'Level 2' }
279
299
} ,
280
- 'description' => 'More deepest nested entity'
300
+ 'description' => 'More deepest nested entity' ,
301
+ 'required' => %w[ level_2 ]
281
302
}
282
303
} ,
283
- 'description' => 'Deep nested entity'
304
+ 'description' => 'Deep nested entity' ,
305
+ 'required' => %w[ level_1 ]
284
306
} ,
285
307
'nested_required' => {
286
308
'type' => 'object' ,
287
309
'properties' => {
288
310
'some1' => { 'type' => 'string' , 'description' => 'Required some 1' } ,
289
311
'some2' => { 'type' => 'string' , 'description' => 'Required some 2' } ,
290
- 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' }
312
+ 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' } ,
313
+ 'some4' => { 'type' => 'string' , 'description' => 'Optional some 4' } ,
314
+ 'some5' => { 'type' => 'string' , 'description' => 'Optional some 5' } ,
315
+ 'some6' => { 'type' => 'string' , 'description' => 'Optional some 6' }
291
316
} ,
292
317
'required' => %w[ some1 some2 ]
293
318
} ,
@@ -298,14 +323,16 @@ def app
298
323
'properties' => {
299
324
'id' => { 'type' => 'integer' , 'format' => 'int32' , 'description' => 'Collection element id' } ,
300
325
'name' => { 'type' => 'string' , 'description' => 'Collection element name' }
301
- }
326
+ } ,
327
+ 'required' => %w[ id name ]
302
328
} ,
303
329
'description' => 'Nested array'
304
330
}
305
331
} ,
306
- 'type ' => 'object'
332
+ 'required ' => %w[ nested aliased deep_nested nested_required nested_array ]
307
333
)
308
334
expect ( subject [ 'TheseApi_Entities_NestedChild' ] ) . to eq (
335
+ 'type' => 'object' ,
309
336
'properties' => {
310
337
'nested' => {
311
338
'type' => 'object' ,
@@ -314,14 +341,16 @@ def app
314
341
'some2' => { 'type' => 'string' , 'description' => 'Nested some 2' } ,
315
342
'some3' => { 'type' => 'string' , 'description' => 'Nested some 3' }
316
343
} ,
317
- 'description' => 'Nested entity'
344
+ 'description' => 'Nested entity' ,
345
+ 'required' => %w[ some1 some2 some3 ]
318
346
} ,
319
347
'aliased' => {
320
348
'type' => 'object' ,
321
349
'properties' => {
322
350
'some1' => { 'type' => 'string' , 'description' => 'Alias some 1' } ,
323
351
'some2' => { 'type' => 'string' , 'description' => 'Alias some 2' }
324
- }
352
+ } ,
353
+ 'required' => %w[ some1 some2 ]
325
354
} ,
326
355
'deep_nested' => {
327
356
'type' => 'object' ,
@@ -337,20 +366,26 @@ def app
337
366
'description' => 'Level 3'
338
367
}
339
368
} ,
340
- 'description' => 'Level 2'
369
+ 'description' => 'Level 2' ,
370
+ 'required' => %w[ level_3 ]
341
371
}
342
372
} ,
343
- 'description' => 'More deepest nested entity'
373
+ 'description' => 'More deepest nested entity' ,
374
+ 'required' => %w[ level_2 ]
344
375
}
345
376
} ,
346
- 'description' => 'Deep nested entity'
377
+ 'description' => 'Deep nested entity' ,
378
+ 'required' => %w[ level_1 ]
347
379
} ,
348
380
'nested_required' => {
349
381
'type' => 'object' ,
350
382
'properties' => {
351
383
'some1' => { 'type' => 'string' , 'description' => 'Required some 1' } ,
352
384
'some2' => { 'type' => 'string' , 'description' => 'Required some 2' } ,
353
- 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' }
385
+ 'some3' => { 'type' => 'string' , 'description' => 'Optional some 3' } ,
386
+ 'some4' => { 'type' => 'string' , 'description' => 'Optional some 4' } ,
387
+ 'some5' => { 'type' => 'string' , 'description' => 'Optional some 5' } ,
388
+ 'some6' => { 'type' => 'string' , 'description' => 'Optional some 6' }
354
389
} ,
355
390
'required' => %w[ some1 some2 ]
356
391
} ,
@@ -362,12 +397,13 @@ def app
362
397
'id' => { 'type' => 'integer' , 'format' => 'int32' , 'description' => 'Collection element id' } ,
363
398
'name' => { 'type' => 'string' , 'description' => 'Collection element name' } ,
364
399
'category' => { 'type' => 'string' , 'description' => 'Collection element category' }
365
- }
400
+ } ,
401
+ 'required' => %w[ id name category ]
366
402
} ,
367
403
'description' => 'Nested array'
368
404
}
369
405
} ,
370
- 'type ' => 'object'
406
+ 'required ' => %w[ nested aliased deep_nested nested_required nested_array ]
371
407
)
372
408
expect ( subject [ 'TheseApi_Entities_Polymorphic' ] ) . to eql (
373
409
'type' => 'object' ,
@@ -380,14 +416,15 @@ def app
380
416
)
381
417
382
418
expect ( subject [ 'TheseApi_Entities_MixedType' ] ) . to eql (
419
+ 'type' => 'object' ,
383
420
'properties' => {
384
421
'tags' => {
385
422
'description' => 'Tags' ,
386
423
'items' => { '$ref' => '#/definitions/TheseApi_Entities_TagType' } ,
387
424
'type' => 'array'
388
425
}
389
426
} ,
390
- 'type ' => 'object'
427
+ 'required ' => %w[ tags ]
391
428
)
392
429
393
430
expect ( subject [ 'TheseApi_Entities_SomeEntity' ] ) . to eql (
@@ -414,7 +451,8 @@ def app
414
451
} ,
415
452
'attr' => { 'type' => 'string' , 'description' => 'Attribute' }
416
453
} ,
417
- 'required' => %w[ attr ] ,
454
+ 'required' => %w[ text kind kind2 kind3 tags relation values nested nested_child
455
+ polymorphic mixed attr code message ] ,
418
456
'description' => 'TheseApi_Entities_SomeEntity model'
419
457
)
420
458
end
0 commit comments