Skip to content

Commit

Permalink
drop annotations from OpenApiPhpDescriber
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Oct 22, 2024
1 parent bf7e31c commit 9b1103d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
5 changes: 4 additions & 1 deletion UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ Upgrade to PHP 8.1 attributes.
+#[OA\Property(type: "integer", format: "negative-int")]
public int $negative;
...
```
```

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()`
1 change: 0 additions & 1 deletion src/DependencyInjection/NelmioApiDocExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
27 changes: 3 additions & 24 deletions src/Describer/OpenApiPhpDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,19 +32,16 @@ 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__);
}

$this->routeCollection = $routeCollection;
$this->controllerReflector = $controllerReflector;
$this->annotationReader = $annotationReader;
$this->logger = $logger;
}

Expand All @@ -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();
Expand Down

0 comments on commit 9b1103d

Please sign in to comment.