Skip to content

Commit f6f5612

Browse files
authored
Favour promoted property annotation nullable over native (#1785)
1 parent 25a33ea commit f6f5612

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/Analysers/AttributeAnnotationFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public function build(\Reflector $reflector, Context $context): array
8585
if (Generator::isDefault($instance->type)) {
8686
$instance->type = $type;
8787
}
88-
$instance->nullable = $nullable ?: Generator::UNDEFINED;
88+
if (Generator::isDefault($instance->nullable)) {
89+
$instance->nullable = $nullable ?: Generator::UNDEFINED;
90+
}
8991

9092
if ($rp->isPromoted()) {
9193
// ensure each property has its own context

tests/Fixtures/Scratch/Nullable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class Nullable
5252

5353
#[OAT\Property(enum: ['Choice1', 'Choice2', null], example: 'Choice1', nullable: true)]
5454
public ?string $choice = null;
55+
56+
public function __construct(
57+
#[OAT\Property(nullable: false)]
58+
public ?string $title,
59+
) {
60+
}
5561
}
5662

5763
#[OAT\Get(

tests/Fixtures/Scratch/Nullable3.0.0.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ components:
2121
example: '2023-08-02T07:06:46+03:30'
2222
Nullable:
2323
properties:
24+
title:
25+
type: string
26+
nullable: false
2427
firstname:
2528
type: string
2629
nullable: true

tests/Fixtures/Scratch/Nullable3.1.0.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ components:
2121
example: '2023-08-02T07:06:46+03:30'
2222
Nullable:
2323
properties:
24+
title:
25+
type: string
2426
firstname:
2527
type:
2628
- string

0 commit comments

Comments
 (0)