Skip to content

Commit def5058

Browse files
authored
Fix context nested value for ctor args (#1762)
1 parent 42dd051 commit def5058

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/Analysers/AttributeAnnotationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function build(\Reflector $reflector, Context $context): array
7171
foreach ($rp->getAttributes($attributeName, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
7272
/** @var OA\Property|OA\Parameter|OA\RequestBody $instance */
7373
$instance = $attribute->newInstance();
74-
$instance->_context = new Context(['nested' => true], $context);
74+
$instance->_context = new Context(['nested' => false], $context);
7575

7676
$type = (($rnt = $rp->getType()) && $rnt instanceof \ReflectionNamedType) ? $rnt->getName() : Generator::UNDEFINED;
7777
$nullable = $rnt ? $rnt->allowsNull() : true;

tests/Fixtures/Scratch/PromotedProperty.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
use OpenApi\Annotations as OA;
1010
use OpenApi\Attributes as OAT;
1111

12+
#[OAT\Schema(type: 'string')]
13+
enum MyEnum: string
14+
{
15+
case AA = 'AA';
16+
}
17+
1218
#[OAT\Schema]
1319
class PromotedPropertyDescription
1420
{
@@ -52,6 +58,12 @@ public function __construct(
5258
* @OA\Property()
5359
*/
5460
public string $different = '',
61+
62+
/*
63+
* Intentionally not promoted!
64+
*/
65+
#[OAT\Property()]
66+
MyEnum $myEnum,
5567
) {
5668
}
5769
}

tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ paths:
1212
description: OK
1313
components:
1414
schemas:
15+
MyEnum:
16+
type: string
17+
enum:
18+
- AA
1519
PromotedPropertyDescription:
1620
properties:
1721
thevalue:
@@ -20,6 +24,8 @@ components:
2024
other:
2125
description: 'Other value.'
2226
type: string
27+
myEnum:
28+
$ref: '#/components/schemas/MyEnum'
2329
thename:
2430
description: 'Property name.'
2531
type: string

tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ paths:
1212
description: OK
1313
components:
1414
schemas:
15+
MyEnum:
16+
type: string
17+
enum:
18+
- AA
1519
PromotedPropertyDescription:
1620
properties:
1721
thevalue:
@@ -20,6 +24,8 @@ components:
2024
other:
2125
description: 'Other value.'
2226
type: string
27+
myEnum:
28+
$ref: '#/components/schemas/MyEnum'
2329
thename:
2430
description: 'Property name.'
2531
type: string

0 commit comments

Comments
 (0)