diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 6fabe66..a505eda 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -36,7 +36,6 @@ jobs: symfony-require: "5.4.*" - php-version: 8.1 symfony-require: "6.0.*" - api-platform: "early" steps: - name: "Checkout" diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index ce0d0e6..a95beb9 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -168,7 +168,7 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI } // ApiPlatform support - if (isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Core\Documentation\Documentation')) { + if (isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Documentation\Documentation')) { $loader->load('api_platform.xml'); } diff --git a/Describer/ApiPlatformDescriber.php b/Describer/ApiPlatformDescriber.php index 88f092d..920e291 100644 --- a/Describer/ApiPlatformDescriber.php +++ b/Describer/ApiPlatformDescriber.php @@ -11,14 +11,16 @@ namespace Nelmio\ApiDocBundle\Describer; -use ApiPlatform\Core\Documentation\Documentation; use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer; +use ApiPlatform\Documentation\DocumentationInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; final class ApiPlatformDescriber extends ExternalDocDescriber { - public function __construct(Documentation $documentation, NormalizerInterface $normalizer) + public function __construct(DocumentationInterface $documentation, NormalizerInterface $normalizer) { + // var_dump(get_class($documentation)); + // die(); if (!$normalizer->supportsNormalization($documentation, 'json')) { throw new \InvalidArgumentException(sprintf('Argument 2 passed to %s() must implement %s and support normalization of %s. The normalizer provided is an instance of %s.', __METHOD__, NormalizerInterface::class, Documentation::class, get_class($normalizer))); } @@ -27,7 +29,7 @@ final class ApiPlatformDescriber extends ExternalDocDescriber $documentation = (array) $normalizer->normalize( $documentation, null, - [DocumentationNormalizer::SPEC_VERSION => 3] + class_exists(DocumentationNormalizer::class) ? [DocumentationNormalizer::SPEC_VERSION => 3] : [] ); // TODO: remove this diff --git a/Resources/config/api_platform.xml b/Resources/config/api_platform.xml index 24d747c..8edbfe1 100644 --- a/Resources/config/api_platform.xml +++ b/Resources/config/api_platform.xml @@ -5,18 +5,17 @@ - - + + - - - - - + + + + diff --git a/Tests/Describer/ApiPlatformDescriberTest.php b/Tests/Describer/ApiPlatformDescriberTest.php index 03a113b..ffdef4b 100644 --- a/Tests/Describer/ApiPlatformDescriberTest.php +++ b/Tests/Describer/ApiPlatformDescriberTest.php @@ -11,7 +11,7 @@ namespace Nelmio\ApiDocBundle\Tests\Describer; -use ApiPlatform\Core\Documentation\Documentation; +use ApiPlatform\Documentation\Documentation; use ApiPlatform\Metadata\Resource\ResourceNameCollection; use Nelmio\ApiDocBundle\Describer\ApiPlatformDescriber; use OpenApi\Annotations\OpenApi; diff --git a/Tests/Functional/Entity/Dummy.php b/Tests/Functional/Entity/Dummy.php index 1a07b9a..33737a8 100644 --- a/Tests/Functional/Entity/Dummy.php +++ b/Tests/Functional/Entity/Dummy.php @@ -12,48 +12,13 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Entity; use ApiPlatform\Core\Annotation\ApiProperty; -use ApiPlatform\Core\Annotation\ApiResource; -use Symfony\Component\Validator\Constraints as Assert; +use Nelmio\ApiDocBundle\Tests\Functional\EntityExcluded; -/** - * @author Guilhem N. - * - * @ApiResource( - * collectionOperations={ - * "get"={"method"="GET"}, - * "custom2"={"path"="/foo", "method"="GET"}, - * "custom"={"path"="/foo", "method"="POST"}, - * }, - * itemOperations={"get"={"method"="GET"}}) - * ) - */ -class Dummy -{ - /** - * @var int - */ - private $id; - - /** - * @var string - * - * @Assert\NotBlank - * @ApiProperty(iri="http://schema.org/name") - */ - private $name; - - public function getId(): int +// BC Api-Platform < 3.x +if (!class_exists(ApiProperty::class)) { + class Dummy extends EntityExcluded\ApiPlatform3\Dummy { - return $this->id; - } - - public function setName(string $name) - { - $this->name = $name; - } - - public function getName(): string - { - return $this->name; } +} else { + class_alias(EntityExcluded\ApiPlatform2\Dummy::class, Dummy::class); } diff --git a/Tests/Functional/EntityExcluded/ApiPlatform2/Dummy.php b/Tests/Functional/EntityExcluded/ApiPlatform2/Dummy.php new file mode 100644 index 0000000..5b9ce09 --- /dev/null +++ b/Tests/Functional/EntityExcluded/ApiPlatform2/Dummy.php @@ -0,0 +1,59 @@ + + * + * @ApiResource( + * collectionOperations={ + * "get"={"method"="GET"}, + * "custom2"={"path"="/foo", "method"="GET"}, + * "custom"={"path"="/foo", "method"="POST"}, + * }, + * itemOperations={"get"={"method"="GET"}}) + * ) + */ +class Dummy +{ + /** + * @var int + */ + private $id; + + /** + * @var string + * + * @Assert\NotBlank + * @ApiProperty(iri="http://schema.org/name") + */ + private $name; + + public function getId(): int + { + return $this->id; + } + + public function setName(string $name) + { + $this->name = $name; + } + + public function getName(): string + { + return $this->name; + } +} diff --git a/Tests/Functional/EntityExcluded/ApiPlatform3/Dummy.php b/Tests/Functional/EntityExcluded/ApiPlatform3/Dummy.php new file mode 100644 index 0000000..1ed84fa --- /dev/null +++ b/Tests/Functional/EntityExcluded/ApiPlatform3/Dummy.php @@ -0,0 +1,63 @@ + + */ +#[ + ApiResource( + operations: [ + new Get(name: 'get'), + new Get(name: 'custom2', uriTemplate: '/foo'), + new Post(name: 'custom', uriTemplate: '/foo'), + new GetCollection(), + ], + ) +] +class Dummy +{ + /** + * @var int + */ + private $id; + + /** + * @var string + * + * @Assert\NotBlank + */ + #[ApiProperty(iris: ['http://schema.org/name'])] + private $name; + + public function getId(): int + { + return $this->id; + } + + public function setName(string $name) + { + $this->name = $name; + } + + public function getName(): string + { + return $this->name; + } +} diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index f6ca42d..f716027 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -11,7 +11,8 @@ namespace Nelmio\ApiDocBundle\Tests\Functional; -use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle; +use ApiPlatform\Core\Annotation\ApiProperty; +use ApiPlatform\Symfony\Bundle\ApiPlatformBundle; use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle; use FOS\RestBundle\FOSRestBundle; use Hateoas\Configuration\Embedded; @@ -163,7 +164,11 @@ class TestKernel extends Kernel ]); $c->loadFromExtension('api_platform', [ - 'mapping' => ['paths' => ['%kernel.project_dir%/Tests/Functional/Entity']], + 'mapping' => ['paths' => [ + !class_exists(ApiProperty::class) + ? '%kernel.project_dir%/Tests/Functional/EntityExcluded/ApiPlatform3' + : '%kernel.project_dir%/Tests/Functional/EntityExcluded/ApiPlatform2', + ]], ]); $c->loadFromExtension('fos_rest', [ diff --git a/composer.json b/composer.json index 403be59..8f35aad 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "symfony/twig-bundle": "^4.4|^5.2|^6.0", "symfony/validator": "^4.4|^5.2|^6.0", - "api-platform/core": "^2.7.0", + "api-platform/core": "^2.7.0|^3@dev", "symfony/deprecation-contracts": "^2.1|^3", "friendsofsymfony/rest-bundle": "^2.8|^3.0",