From 766ed898cf225eebfbfcb7c4932092d9c0c9a289 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sat, 3 Sep 2022 12:49:49 +0200 Subject: [PATCH] Make Model Attachable (#2025) * Make Model Attachable * fix cs * Drop zircote/swagger-php < 4.2 support --- Annotation/Model.php | 4 ++-- OpenApiPhp/ModelRegister.php | 20 ++++++++++++------- .../Functional/Controller/ApiController80.php | 2 +- Tests/Functional/Entity/ArticleInterface.php | 2 +- composer.json | 2 +- phpunit.xml.dist | 15 +------------- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/Annotation/Model.php b/Annotation/Model.php index 43e7b84..083fbaa 100644 --- a/Annotation/Model.php +++ b/Annotation/Model.php @@ -11,15 +11,15 @@ namespace Nelmio\ApiDocBundle\Annotation; -use OpenApi\Annotations\AbstractAnnotation; use OpenApi\Annotations\Parameter; +use OpenApi\Attributes\Attachable; use OpenApi\Generator; /** * @Annotation */ #[\Attribute(\Attribute::TARGET_METHOD)] -final class Model extends AbstractAnnotation +final class Model extends Attachable { /** {@inheritdoc} */ public static $_types = [ diff --git a/OpenApiPhp/ModelRegister.php b/OpenApiPhp/ModelRegister.php index 7b675d2..938fb6b 100644 --- a/OpenApiPhp/ModelRegister.php +++ b/OpenApiPhp/ModelRegister.php @@ -16,6 +16,7 @@ use Nelmio\ApiDocBundle\Model\Model; use Nelmio\ApiDocBundle\Model\ModelRegistry; use OpenApi\Analysis; use OpenApi\Annotations as OA; +use OpenApi\Generator; use Symfony\Component\PropertyInfo\Type; /** @@ -116,13 +117,16 @@ final class ModelRegister private function detach(ModelAnnotation $model, OA\AbstractAnnotation $annotation, Analysis $analysis): void { - foreach ($annotation->_unmerged as $key => $unmerged) { - if ($unmerged === $model) { - unset($annotation->_unmerged[$key]); + if (Generator::UNDEFINED !== $annotation->attachables) { + foreach ($annotation->attachables as $key => $attachable) { + if ($attachable === $model) { + unset($annotation->attachables[$key]); - break; + break; + } } } + $analysis->annotations->detach($model); } @@ -137,9 +141,11 @@ final class ModelRegister private function getModel(OA\AbstractAnnotation $annotation): ?ModelAnnotation { - foreach ($annotation->_unmerged as $unmerged) { - if ($unmerged instanceof ModelAnnotation) { - return $unmerged; + if (Generator::UNDEFINED !== $annotation->attachables) { + foreach ($annotation->attachables as $attachable) { + if ($attachable instanceof ModelAnnotation) { + return $attachable; + } } } diff --git a/Tests/Functional/Controller/ApiController80.php b/Tests/Functional/Controller/ApiController80.php index 72a59dd..5d79a11 100644 --- a/Tests/Functional/Controller/ApiController80.php +++ b/Tests/Functional/Controller/ApiController80.php @@ -11,12 +11,12 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Controller; -use Functional\Entity\ArticleInterface; use Nelmio\ApiDocBundle\Annotation\Areas; use Nelmio\ApiDocBundle\Annotation\Model; use Nelmio\ApiDocBundle\Annotation\Operation; use Nelmio\ApiDocBundle\Annotation\Security; use Nelmio\ApiDocBundle\Tests\Functional\Entity\Article; +use Nelmio\ApiDocBundle\Tests\Functional\Entity\ArticleInterface; use Nelmio\ApiDocBundle\Tests\Functional\Entity\CompoundEntity; use Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithAlternateType; use Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithObjectType; diff --git a/Tests/Functional/Entity/ArticleInterface.php b/Tests/Functional/Entity/ArticleInterface.php index 931d19a..1ef41d6 100644 --- a/Tests/Functional/Entity/ArticleInterface.php +++ b/Tests/Functional/Entity/ArticleInterface.php @@ -1,6 +1,6 @@ + @@ -21,18 +22,4 @@ Tests - - - - . - - Tests - vendor - - - - - - -