From 2cd0791af64045f569527ae1f835cd3c27621693 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 16:59:09 +0200 Subject: [PATCH] drop annotations from OpenApiPhpDescriber --- UPGRADE-5.0.md | 5 +++- .../NelmioApiDocExtension.php | 1 - src/Describer/OpenApiPhpDescriber.php | 27 +++---------------- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 7fc944442..0ce63c679 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -16,4 +16,7 @@ Upgrade to PHP 8.1 attributes. +#[OA\Property(type: "integer", format: "negative-int")] public int $negative; ... -``` \ No newline at end of file +``` + +This causes the following breaking changes in classes that used on annotations: +- BC BREAK: Removed 3rd parameter `?Reader $annotationReader` from `Nelmio\ApiDocBundle\Describer\OpenApiPhpDescriber::__construct()` \ No newline at end of file diff --git a/src/DependencyInjection/NelmioApiDocExtension.php b/src/DependencyInjection/NelmioApiDocExtension.php index 7b877b001..c05d411ef 100644 --- a/src/DependencyInjection/NelmioApiDocExtension.php +++ b/src/DependencyInjection/NelmioApiDocExtension.php @@ -115,7 +115,6 @@ public function load(array $configs, ContainerBuilder $container): void ->setArguments([ new Reference(sprintf('nelmio_api_doc.routes.%s', $area)), new Reference('nelmio_api_doc.controller_reflector'), - new Reference('annotations.reader', ContainerInterface::NULL_ON_INVALID_REFERENCE), // We cannot use the cached version of the annotation reader since the construction of the annotations is context dependant... new Reference('logger'), ]) ->addTag(sprintf('nelmio_api_doc.describer.%s', $area), ['priority' => -200]); diff --git a/src/Describer/OpenApiPhpDescriber.php b/src/Describer/OpenApiPhpDescriber.php index 20cc958de..79a807c72 100644 --- a/src/Describer/OpenApiPhpDescriber.php +++ b/src/Describer/OpenApiPhpDescriber.php @@ -11,7 +11,6 @@ namespace Nelmio\ApiDocBundle\Describer; -use Doctrine\Common\Annotations\Reader; use Nelmio\ApiDocBundle\Annotation\Operation; use Nelmio\ApiDocBundle\Annotation\Security; use Nelmio\ApiDocBundle\OpenApiPhp\Util; @@ -33,11 +32,9 @@ final class OpenApiPhpDescriber private RouteCollection $routeCollection; private ControllerReflector $controllerReflector; - - private ?Reader $annotationReader; private LoggerInterface $logger; - public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, ?Reader $annotationReader, LoggerInterface $logger, bool $overwrite = false) + public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, LoggerInterface $logger, bool $overwrite = false) { if ($overwrite || func_num_args() > 4) { trigger_deprecation('nelmio/api-doc-bundle', '4.25.2', 'The "$overwrite" argument of "%s" is unused and therefore deprecated.', __METHOD__); @@ -45,7 +42,6 @@ public function __construct(RouteCollection $routeCollection, ControllerReflecto $this->routeCollection = $routeCollection; $this->controllerReflector = $controllerReflector; - $this->annotationReader = $annotationReader; $this->logger = $logger; } @@ -68,27 +64,10 @@ public function describe(OA\OpenApi $api): void $this->setContext($context); if (!array_key_exists($declaringClass->getName(), $classAnnotations)) { - $classAnnotations = []; - if (null !== $this->annotationReader) { - $classAnnotations = $this->annotationReader->getClassAnnotations($declaringClass); - } - - $classAnnotations = array_filter($classAnnotations, function ($v) { - return $v instanceof OA\AbstractAnnotation; - }); - - $classAnnotations = array_merge($classAnnotations, $this->getAttributesAsAnnotation($declaringClass, $context)); - $classAnnotations[$declaringClass->getName()] = $classAnnotations; - } - - $annotations = []; - if (null !== $this->annotationReader) { - $annotations = array_filter($this->annotationReader->getMethodAnnotations($method), function ($v) { - return $v instanceof OA\AbstractAnnotation; - }); + $classAnnotations[$declaringClass->getName()] = $this->getAttributesAsAnnotation($declaringClass, $context); } - $annotations = array_merge($annotations, $this->getAttributesAsAnnotation($method, $context)); + $annotations = $this->getAttributesAsAnnotation($method, $context); $implicitAnnotations = []; $mergeProperties = new \stdClass();