From 1d89d8693dffc3d2ec70b354c9daa34634cc8adf Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Wed, 10 Jul 2024 12:00:43 +1200 Subject: [PATCH 1/3] Add (failing) test --- src/Analysers/AttributeAnnotationFactory.php | 4 ++-- tests/Fixtures/Scratch/PromotedProperty.php | 8 ++++++++ tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml | 3 +++ tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Analysers/AttributeAnnotationFactory.php b/src/Analysers/AttributeAnnotationFactory.php index ba3c52f52..e4db4a5eb 100644 --- a/src/Analysers/AttributeAnnotationFactory.php +++ b/src/Analysers/AttributeAnnotationFactory.php @@ -81,12 +81,12 @@ public function build(\Reflector $reflector, Context $context): array if ($rp->isPromoted()) { // ensure each property has its own context - $instance->_context = new Context([], $instance->_context); + $instance->_context = new Context(['generated' => true], $context); // promoted parameter - docblock is available via class/property if ($comment = $rp->getDeclaringClass()->getProperty($rp->getName())->getDocComment()) { $instance->_context->comment = $comment; - } + } } } else { if (!$instance->name || Generator::isDefault($instance->name)) { diff --git a/tests/Fixtures/Scratch/PromotedProperty.php b/tests/Fixtures/Scratch/PromotedProperty.php index f0733ccea..9b05e9576 100644 --- a/tests/Fixtures/Scratch/PromotedProperty.php +++ b/tests/Fixtures/Scratch/PromotedProperty.php @@ -27,6 +27,14 @@ public function __construct( #[OAT\Property(property: 'thevalue')] public string $value = '', + /** + * Other value. + * + * @var string + */ + #[OAT\Property(property: 'other')] + public string $other = '', + /** * Property meta. * diff --git a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml index 6c4e5a3c5..ed5bc7ebd 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml @@ -17,6 +17,9 @@ components: thevalue: description: 'Property value.' type: string + other: + description: 'Other value' + type: string 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 977e3b6e0..2a742c9bc 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml @@ -17,6 +17,9 @@ components: thevalue: description: 'Property value.' type: string + other: + description: 'Other value' + type: string thename: description: 'Property name.' type: string From ce1e3bf782c5c33c5deb8b549281bcee10cb965e Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Sun, 14 Jul 2024 21:30:52 +1200 Subject: [PATCH 2/3] Fix promoted property contexts --- src/Analysers/AttributeAnnotationFactory.php | 5 +++-- tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml | 2 +- tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Analysers/AttributeAnnotationFactory.php b/src/Analysers/AttributeAnnotationFactory.php index e4db4a5eb..c93609a29 100644 --- a/src/Analysers/AttributeAnnotationFactory.php +++ b/src/Analysers/AttributeAnnotationFactory.php @@ -65,6 +65,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(); + $type = (($rnt = $rp->getType()) && $rnt instanceof \ReflectionNamedType) ? $rnt->getName() : Generator::UNDEFINED; $nullable = $rnt ? $rnt->allowsNull() : true; @@ -81,12 +82,12 @@ public function build(\Reflector $reflector, Context $context): array if ($rp->isPromoted()) { // ensure each property has its own context - $instance->_context = new Context(['generated' => true], $context); + $instance->_context = new Context(['generated' => true, 'annotations' => [$instance]], $context); // promoted parameter - docblock is available via class/property if ($comment = $rp->getDeclaringClass()->getProperty($rp->getName())->getDocComment()) { $instance->_context->comment = $comment; - } + } } } else { if (!$instance->name || Generator::isDefault($instance->name)) { diff --git a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml index ed5bc7ebd..9281b7345 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml @@ -18,7 +18,7 @@ components: description: 'Property value.' type: string other: - description: 'Other value' + description: 'Other value.' type: string thename: description: 'Property name.' diff --git a/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml b/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml index 2a742c9bc..f7a829505 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml @@ -18,7 +18,7 @@ components: description: 'Property value.' type: string other: - description: 'Other value' + description: 'Other value.' type: string thename: description: 'Property name.' From 449e4d3b36753a423437310ee86a536cb8e91fe1 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Sun, 14 Jul 2024 21:35:20 +1200 Subject: [PATCH 3/3] Add another docblock annotation --- tests/Fixtures/Scratch/PromotedProperty.php | 9 +++++++++ tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml | 3 +++ tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml | 3 +++ 3 files changed, 15 insertions(+) diff --git a/tests/Fixtures/Scratch/PromotedProperty.php b/tests/Fixtures/Scratch/PromotedProperty.php index 9b05e9576..3740bb6da 100644 --- a/tests/Fixtures/Scratch/PromotedProperty.php +++ b/tests/Fixtures/Scratch/PromotedProperty.php @@ -43,6 +43,15 @@ public function __construct( * @OA\Property(property="themeta") */ public string $meta = '', + + /** + * Property different. + * + * @var string + * + * @OA\Property() + */ + public string $different = '', ) { } } diff --git a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml index 9281b7345..eccdf87cb 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml @@ -26,4 +26,7 @@ components: themeta: description: 'Property meta.' type: string + different: + description: 'Property different.' + type: string type: object diff --git a/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml b/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml index f7a829505..e7059d6c3 100644 --- a/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml +++ b/tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml @@ -26,4 +26,7 @@ components: themeta: description: 'Property meta.' type: string + different: + description: 'Property different.' + type: string type: object