Skip to content

Commit 05aa70f

Browse files
authored
fix: account for entry always being nullable (#279)
1 parent c2ee2cd commit 05aa70f

File tree

9 files changed

+70
-21
lines changed

9 files changed

+70
-21
lines changed

lib/rspec/openapi/schema_builder.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ def build_merged_schema_from_variations(variations)
311311

312312
has_nullable = all_prop_variations.any?(&:nil?) || nullable_only.any?
313313

314-
if prop_variations.size == 1
314+
if prop_variations.empty? && has_nullable
315+
merged[:properties][key] = { nullable: true }
316+
elsif prop_variations.size == 1
315317
merged[:properties][key] = prop_variations.first.dup
316318
merged[:properties][key][:nullable] = true if has_nullable
317319
elsif prop_variations.size > 1

spec/apps/hanami/app/actions/array_hashes/nested_objects.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def handle(request, response)
2020
"label" => "Duplicate",
2121
"modal" => {
2222
"confirm_action" => {
23-
"label" => "Duplicate"
23+
"label" => "Duplicate",
24+
"endpoint" => nil
2425
}
2526
}
2627
},
@@ -31,7 +32,8 @@ def handle(request, response)
3132
"label" => "Something Else Again",
3233
"modal" => {
3334
"confirm_action" => {
34-
"label" => nil
35+
"label" => nil,
36+
"endpoint" => nil
3537
}
3638
}
3739
}
@@ -49,7 +51,8 @@ def handle(request, response)
4951
"label" => "Duplicate",
5052
"modal" => {
5153
"confirm_action" => {
52-
"label" => "Duplicate"
54+
"label" => "Duplicate",
55+
"endpoint" => nil
5356
}
5457
}
5558
},
@@ -60,7 +63,8 @@ def handle(request, response)
6063
"label" => "Something Else Again",
6164
"modal" => {
6265
"confirm_action" => {
63-
"label" => nil
66+
"label" => nil,
67+
"endpoint" => nil
6468
}
6569
}
6670
}

spec/apps/hanami/doc/openapi.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@
376376
"label": {
377377
"type": "string",
378378
"nullable": true
379+
},
380+
"endpoint": {
381+
"nullable": true
379382
}
380383
},
381384
"required": [
@@ -419,7 +422,8 @@
419422
"label": "Duplicate",
420423
"modal": {
421424
"confirm_action": {
422-
"label": "Duplicate"
425+
"label": "Duplicate",
426+
"endpoint": null
423427
}
424428
}
425429
},
@@ -430,7 +434,8 @@
430434
"label": "Something Else Again",
431435
"modal": {
432436
"confirm_action": {
433-
"label": null
437+
"label": null,
438+
"endpoint": null
434439
}
435440
}
436441
}
@@ -448,7 +453,8 @@
448453
"label": "Duplicate",
449454
"modal": {
450455
"confirm_action": {
451-
"label": "Duplicate"
456+
"label": "Duplicate",
457+
"endpoint": null
452458
}
453459
}
454460
},
@@ -459,7 +465,8 @@
459465
"label": "Something Else Again",
460466
"modal": {
461467
"confirm_action": {
462-
"label": null
468+
"label": null,
469+
"endpoint": null
463470
}
464471
}
465472
}

spec/apps/hanami/doc/openapi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ paths:
244244
label:
245245
type: string
246246
nullable: true
247+
endpoint:
248+
nullable: true
247249
required:
248250
- label
249251
required:
@@ -267,11 +269,13 @@ paths:
267269
modal:
268270
confirm_action:
269271
label: Duplicate
272+
endpoint:
270273
- label: Edit
271274
- label: Something Else Again
272275
modal:
273276
confirm_action:
274277
label:
278+
endpoint:
275279
- id: 2
276280
metadata:
277281
author: Bob
@@ -282,11 +286,13 @@ paths:
282286
modal:
283287
confirm_action:
284288
label: Duplicate
289+
endpoint:
285290
- label: Edit
286291
- label: Something Else Again
287292
modal:
288293
confirm_action:
289294
label:
295+
endpoint:
290296
- id: 3
291297
metadata:
292298
author: Charlie

spec/apps/rails/app/controllers/array_hashes_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def nested_objects
138138
"label" => "Duplicate",
139139
"modal" => {
140140
"confirm_action" => {
141-
"label" => "Duplicate"
141+
"label" => "Duplicate",
142+
"endpoint" => nil
142143
}
143144
}
144145
},
@@ -149,7 +150,8 @@ def nested_objects
149150
"label" => "Something Else Again",
150151
"modal" => {
151152
"confirm_action" => {
152-
"label" => nil
153+
"label" => nil,
154+
"endpoint" => nil
153155
}
154156
}
155157
}
@@ -167,7 +169,8 @@ def nested_objects
167169
"label" => "Duplicate",
168170
"modal" => {
169171
"confirm_action" => {
170-
"label" => "Duplicate"
172+
"label" => "Duplicate",
173+
"endpoint" => nil
171174
}
172175
}
173176
},
@@ -178,7 +181,8 @@ def nested_objects
178181
"label" => "Something Else Again",
179182
"modal" => {
180183
"confirm_action" => {
181-
"label" => nil
184+
"label" => nil,
185+
"endpoint" => nil
182186
}
183187
}
184188
}

spec/apps/rails/doc/minitest_openapi.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@
419419
"label": {
420420
"type": "string",
421421
"nullable": true
422+
},
423+
"endpoint": {
424+
"nullable": true
422425
}
423426
},
424427
"required": [
@@ -462,7 +465,8 @@
462465
"label": "Duplicate",
463466
"modal": {
464467
"confirm_action": {
465-
"label": "Duplicate"
468+
"label": "Duplicate",
469+
"endpoint": null
466470
}
467471
}
468472
},
@@ -473,7 +477,8 @@
473477
"label": "Something Else Again",
474478
"modal": {
475479
"confirm_action": {
476-
"label": null
480+
"label": null,
481+
"endpoint": null
477482
}
478483
}
479484
}
@@ -491,7 +496,8 @@
491496
"label": "Duplicate",
492497
"modal": {
493498
"confirm_action": {
494-
"label": "Duplicate"
499+
"label": "Duplicate",
500+
"endpoint": null
495501
}
496502
}
497503
},
@@ -502,7 +508,8 @@
502508
"label": "Something Else Again",
503509
"modal": {
504510
"confirm_action": {
505-
"label": null
511+
"label": null,
512+
"endpoint": null
506513
}
507514
}
508515
}

spec/apps/rails/doc/minitest_openapi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ paths:
272272
label:
273273
type: string
274274
nullable: true
275+
endpoint:
276+
nullable: true
275277
required:
276278
- label
277279
required:
@@ -295,11 +297,13 @@ paths:
295297
modal:
296298
confirm_action:
297299
label: Duplicate
300+
endpoint:
298301
- label: Edit
299302
- label: Something Else Again
300303
modal:
301304
confirm_action:
302305
label:
306+
endpoint:
303307
- id: 2
304308
metadata:
305309
author: Bob
@@ -310,11 +314,13 @@ paths:
310314
modal:
311315
confirm_action:
312316
label: Duplicate
317+
endpoint:
313318
- label: Edit
314319
- label: Something Else Again
315320
modal:
316321
confirm_action:
317322
label:
323+
endpoint:
318324
- id: 3
319325
metadata:
320326
author: Charlie

spec/apps/rails/doc/rspec_openapi.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@
419419
"label": {
420420
"type": "string",
421421
"nullable": true
422+
},
423+
"endpoint": {
424+
"nullable": true
422425
}
423426
},
424427
"required": [
@@ -462,7 +465,8 @@
462465
"label": "Duplicate",
463466
"modal": {
464467
"confirm_action": {
465-
"label": "Duplicate"
468+
"label": "Duplicate",
469+
"endpoint": null
466470
}
467471
}
468472
},
@@ -473,7 +477,8 @@
473477
"label": "Something Else Again",
474478
"modal": {
475479
"confirm_action": {
476-
"label": null
480+
"label": null,
481+
"endpoint": null
477482
}
478483
}
479484
}
@@ -491,7 +496,8 @@
491496
"label": "Duplicate",
492497
"modal": {
493498
"confirm_action": {
494-
"label": "Duplicate"
499+
"label": "Duplicate",
500+
"endpoint": null
495501
}
496502
}
497503
},
@@ -502,7 +508,8 @@
502508
"label": "Something Else Again",
503509
"modal": {
504510
"confirm_action": {
505-
"label": null
511+
"label": null,
512+
"endpoint": null
506513
}
507514
}
508515
}

spec/apps/rails/doc/rspec_openapi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ paths:
272272
label:
273273
type: string
274274
nullable: true
275+
endpoint:
276+
nullable: true
275277
required:
276278
- label
277279
required:
@@ -295,11 +297,13 @@ paths:
295297
modal:
296298
confirm_action:
297299
label: Duplicate
300+
endpoint:
298301
- label: Edit
299302
- label: Something Else Again
300303
modal:
301304
confirm_action:
302305
label:
306+
endpoint:
303307
- id: 2
304308
metadata:
305309
author: Bob
@@ -310,11 +314,13 @@ paths:
310314
modal:
311315
confirm_action:
312316
label: Duplicate
317+
endpoint:
313318
- label: Edit
314319
- label: Something Else Again
315320
modal:
316321
confirm_action:
317322
label:
323+
endpoint:
318324
- id: 3
319325
metadata:
320326
author: Charlie

0 commit comments

Comments
 (0)