Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve docblocks for consecutive promoted properties #1627

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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