Skip to content

Commit

Permalink
Preserve docblocks for consecutive promoted properties (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann authored Jul 15, 2024
1 parent e28255e commit 2a6fa1d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Analysers/AttributeAnnotationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -81,7 +82,7 @@ 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, 'annotations' => [$instance]], $context);

// promoted parameter - docblock is available via class/property
if ($comment = $rp->getDeclaringClass()->getProperty($rp->getName())->getDocComment()) {
Expand Down
17 changes: 17 additions & 0 deletions tests/Fixtures/Scratch/PromotedProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -35,6 +43,15 @@ public function __construct(
* @OA\Property(property="themeta")
*/
public string $meta = '',

/**
* Property different.
*
* @var string
*
* @OA\Property()
*/
public string $different = '',
) {
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixtures/Scratch/PromotedProperty3.0.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ components:
thevalue:
description: 'Property value.'
type: string
other:
description: 'Other value.'
type: string
thename:
description: 'Property name.'
type: string
themeta:
description: 'Property meta.'
type: string
different:
description: 'Property different.'
type: string
type: object
6 changes: 6 additions & 0 deletions tests/Fixtures/Scratch/PromotedProperty3.1.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ components:
thevalue:
description: 'Property value.'
type: string
other:
description: 'Other value.'
type: string
thename:
description: 'Property name.'
type: string
themeta:
description: 'Property meta.'
type: string
different:
description: 'Property different.'
type: string
type: object

0 comments on commit 2a6fa1d

Please sign in to comment.