From 18e4a8dd140954792542f64782361d803f63258a Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Thu, 24 Apr 2025 20:59:07 +1200 Subject: [PATCH 1/2] Add breaking scratch test --- tests/Fixtures/Scratch/PromotedProperty.php | 12 ++++++++++++ tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml | 6 ++++++ tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/tests/Fixtures/Scratch/PromotedProperty.php b/tests/Fixtures/Scratch/PromotedProperty.php index 3740bb6da..08298826e 100644 --- a/tests/Fixtures/Scratch/PromotedProperty.php +++ b/tests/Fixtures/Scratch/PromotedProperty.php @@ -9,6 +9,12 @@ use OpenApi\Annotations as OA; use OpenApi\Attributes as OAT; +#[OAT\Schema(type: 'string')] +enum MyEnum: string +{ + case AA = 'AA'; +} + #[OAT\Schema] class PromotedPropertyDescription { @@ -52,6 +58,12 @@ public function __construct( * @OA\Property() */ public string $different = '', + + /* + * Intentionally not promoted! + */ + #[OAT\Property()] + MyEnum $myEnum, ) { } } diff --git a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml index a0b4cc754..0fbee3b8d 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml @@ -12,6 +12,10 @@ paths: description: OK components: schemas: + MyEnum: + type: string + enum: + - AA PromotedPropertyDescription: properties: thevalue: @@ -20,6 +24,8 @@ components: other: description: 'Other value.' type: string + myEnum: + $ref: '#/components/schemas/MyEnum' thename: description: 'Property name.' type: string diff --git a/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml b/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml index 57e190143..74db3abf3 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml @@ -12,6 +12,10 @@ paths: description: OK components: schemas: + MyEnum: + type: string + enum: + - AA PromotedPropertyDescription: properties: thevalue: @@ -20,6 +24,8 @@ components: other: description: 'Other value.' type: string + myEnum: + $ref: '#/components/schemas/MyEnum' thename: description: 'Property name.' type: string From 29e183e1cbb2ad4f7af2aacfd0b51e9ff9d70d48 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Thu, 24 Apr 2025 21:16:42 +1200 Subject: [PATCH 2/2] Fix context `nested` value for ctor args --- src/Analysers/AttributeAnnotationFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analysers/AttributeAnnotationFactory.php b/src/Analysers/AttributeAnnotationFactory.php index 0facdc09c..d9c8e32ef 100644 --- a/src/Analysers/AttributeAnnotationFactory.php +++ b/src/Analysers/AttributeAnnotationFactory.php @@ -71,7 +71,7 @@ public function build(\Reflector $reflector, Context $context): array foreach ($rp->getAttributes($attributeName, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { /** @var OA\Property|OA\Parameter|OA\RequestBody $instance */ $instance = $attribute->newInstance(); - $instance->_context = new Context(['nested' => true], $context); + $instance->_context = new Context(['nested' => false], $context); $type = (($rnt = $rp->getType()) && $rnt instanceof \ReflectionNamedType) ? $rnt->getName() : Generator::UNDEFINED; $nullable = $rnt ? $rnt->allowsNull() : true;