Make Model Attachable (#2025)

* Make Model Attachable

* fix cs

* Drop zircote/swagger-php < 4.2 support
This commit is contained in:
Guilhem Niot 2022-09-03 12:49:49 +02:00 committed by GitHub
parent a17ad38cc8
commit 766ed898cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 26 deletions

View File

@ -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 = [

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -1,6 +1,6 @@
<?php
namespace Functional\Entity;
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;
interface ArticleInterface
{

View File

@ -30,7 +30,7 @@
"symfony/options-resolver": "^4.4|^5.0|^6.0",
"symfony/property-info": "^4.4|^5.0|^6.0",
"symfony/routing": "^4.4|^5.0|^6.0",
"zircote/swagger-php": "^3.2|^4.0",
"zircote/swagger-php": "^4.2.0",
"phpdocumentor/reflection-docblock": "^3.1|^4.0|^5.0"
},
"require-dev": {

View File

@ -13,6 +13,7 @@
<php>
<env name="SHELL_VERBOSITY" value="-1" />
<ini name="error_reporting" value="-1" />
<ini name="memory_limit" value="512M" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
</php>
@ -21,18 +22,4 @@
<directory>Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>Tests</directory>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>
<php>
<ini name="memory_limit" value="512M" />
</php>
</phpunit>