Skip to content

Commit

Permalink
Collect unrelated annotations/attributes in Context::other (zircote…
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann authored Jun 6, 2024
1 parent 489305a commit b1a792e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Analysers/AttributeAnnotationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ public function build(\Reflector $reflector, Context $context): array
$instance = $attribute->newInstance();
if ($instance instanceof OA\AbstractAnnotation) {
$annotations[] = $instance;
} else {
if ($context->is('other') === false) {
$context->other = [];
}
$context->other[] = $instance;
}
} else {
$context->logger->debug(sprintf('Could not instantiate attribute "%s", because class not found.', $attribute->getName()));
$context->logger->debug(sprintf('Could not instantiate attribute "%s"; class not found.', $attribute->getName()));
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/Analysers/DocBlockAnnotationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OpenApi\Analysers;

use OpenApi\Annotations as OA;
use OpenApi\Context;
use OpenApi\Generator;

Expand Down Expand Up @@ -55,7 +56,19 @@ public function build(\Reflector $reflector, Context $context): array
$this->docBlockParser->setAliases($aliases);

if (method_exists($reflector, 'getDocComment') && ($comment = $reflector->getDocComment())) {
return $this->docBlockParser->fromComment($comment, $context);
$annotations = [];
foreach ($this->docBlockParser->fromComment($comment, $context) as $instance) {
if ($instance instanceof OA\AbstractAnnotation) {
$annotations[] = $instance;
} else {
if ($context->is('other') === false) {
$context->other = [];
}
$context->other[] = $instance;
}
}

return $annotations;
}

return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Analysers/DocBlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function setAliases(array $aliases): void
*
* @param string $comment a T_DOC_COMMENT
*
* @return array<OA\AbstractAnnotation>
* @return array<OA\AbstractAnnotation|object>
*/
public function fromComment(string $comment, Context $context): array
{
Expand Down
1 change: 1 addition & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* the serializer
* @property OA\AbstractAnnotation|null $nested
* @property OA\AbstractAnnotation[]|null $annotations
* @property OA\AbstractAnnotation[]|null $other Annotations not related to OpenApi
* @property LoggerInterface|null $logger Guaranteed to be set when using the `Generator`
* @property array|null $scanned Details of file scanner when using ReflectionAnalyser
* @property string|null $version The OpenAPI version in use
Expand Down

0 comments on commit b1a792e

Please sign in to comment.