Skip to content

Commit 25a33ea

Browse files
authored
Convert annotated type array into single type + nullable for 3.0 (#1786)
1 parent b82e160 commit 25a33ea

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Annotations/AbstractAnnotation.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,21 @@ public function jsonSerialize()
381381
$data->minimum = $data->exclusiveMinimum;
382382
$data->exclusiveMinimum = true;
383383
}
384+
384385
if (isset($data->exclusiveMaximum) && is_numeric($data->exclusiveMaximum)) {
385386
$data->maximum = $data->exclusiveMaximum;
386387
$data->exclusiveMaximum = true;
387388
}
389+
390+
if (isset($data->type) && is_array($data->type)) {
391+
if (in_array('null', $data->type)) {
392+
$data->nullable = true;
393+
$data->type = array_filter($data->type, fn ($v): bool => $v !== 'null');
394+
if (1 === count($data->type)) {
395+
$data->type = array_pop($data->type);
396+
}
397+
}
398+
}
388399
}
389400

390401
if ($this->_context->isVersion(OpenApi::VERSION_3_1_0)) {

tests/Fixtures/Scratch/Nullable3.0.0.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ components:
4646
$ref: '#/components/schemas/MyDateTime'
4747
nullable: true
4848
description:
49-
type:
50-
- string
51-
- 'null'
49+
type: string
50+
nullable: true
5251
choice:
5352
type: string
5453
enum:

0 commit comments

Comments
 (0)