Skip to content

Commit b82e160

Browse files
authored
Favour annotation nullable over native (#1784)
1 parent 1782c27 commit b82e160

4 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/Processors/AugmentProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function augmentType(Analysis $analysis, OA\Property $property, Contex
137137

138138
// native typehints
139139
if ($context->type && !Generator::isDefault($context->type)) {
140-
if ($context->nullable === true) {
140+
if ($context->nullable === true && Generator::isDefault($property->nullable)) {
141141
$property->nullable = true;
142142
}
143143
$type = strtolower($context->type);

tests/Fixtures/Scratch/Nullable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class Nullable
3232
#[OAT\Property]
3333
public ?string $firstname;
3434

35+
#[OAT\Property(nullable: false)]
36+
public ?string $middlename;
37+
3538
#[OAT\Property(nullable: true)]
3639
public ?string $lastname;
3740

tests/Fixtures/Scratch/Nullable3.0.0.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ components:
2424
firstname:
2525
type: string
2626
nullable: true
27+
middlename:
28+
type: string
29+
nullable: false
2730
lastname:
2831
type: string
2932
nullable: true

tests/Fixtures/Scratch/Nullable3.1.0.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ components:
2525
type:
2626
- string
2727
- 'null'
28+
middlename:
29+
type: string
2830
lastname:
2931
type:
3032
- string

0 commit comments

Comments
 (0)