diff --git a/Action/DocumentationAction.php b/Action/DocumentationAction.php deleted file mode 100644 index e507041..0000000 --- a/Action/DocumentationAction.php +++ /dev/null @@ -1,132 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ApiPlatform\Documentation\Action; - -use ApiPlatform\Documentation\Documentation; -use ApiPlatform\Documentation\DocumentationInterface; -use ApiPlatform\Metadata\Get; -use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; -use ApiPlatform\Metadata\Util\ContentNegotiationTrait; -use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface; -use ApiPlatform\OpenApi\OpenApi; -use ApiPlatform\OpenApi\Serializer\ApiGatewayNormalizer; -use ApiPlatform\OpenApi\Serializer\LegacyOpenApiNormalizer; -use ApiPlatform\OpenApi\Serializer\OpenApiNormalizer; -use ApiPlatform\State\ProcessorInterface; -use ApiPlatform\State\ProviderInterface; -use Negotiation\Negotiator; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; - -/** - * Generates the API documentation. - * - * @deprecated use ApiPlatform\Symfony\DocumentationAction instead - * - * @author Amrouche Hamza - */ -final class DocumentationAction -{ - use ContentNegotiationTrait; - - public function __construct( - private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, - private readonly string $title = '', - private readonly string $description = '', - private readonly string $version = '', - private readonly ?OpenApiFactoryInterface $openApiFactory = null, - private readonly ?ProviderInterface $provider = null, - private readonly ?ProcessorInterface $processor = null, - ?Negotiator $negotiator = null, - private readonly array $documentationFormats = [OpenApiNormalizer::JSON_FORMAT => ['application/vnd.openapi+json'], OpenApiNormalizer::FORMAT => ['application/json']], - ) { - $this->negotiator = $negotiator ?? new Negotiator(); - } - - /** - * @return DocumentationInterface|OpenApi|Response - */ - public function __invoke(?Request $request = null) - { - if (null === $request) { - return new Documentation($this->resourceNameCollectionFactory->create(), $this->title, $this->description, $this->version); - } - - $context = [ - 'api_gateway' => $request->query->getBoolean(ApiGatewayNormalizer::API_GATEWAY), - 'base_url' => $request->getBaseUrl(), - 'spec_version' => (string) $request->query->get(LegacyOpenApiNormalizer::SPEC_VERSION), - ]; - $request->attributes->set('_api_normalization_context', $request->attributes->get('_api_normalization_context', []) + $context); - $format = $this->getRequestFormat($request, $this->documentationFormats); - - if (null !== $this->openApiFactory && ('html' === $format || OpenApiNormalizer::FORMAT === $format || OpenApiNormalizer::JSON_FORMAT === $format || OpenApiNormalizer::YAML_FORMAT === $format)) { - return $this->getOpenApiDocumentation($context, $format, $request); - } - - return $this->getHydraDocumentation($context, $request); - } - - /** - * @param array $context - */ - private function getOpenApiDocumentation(array $context, string $format, Request $request): OpenApi|Response - { - if ($this->provider && $this->processor) { - $context['request'] = $request; - $operation = new Get( - class: OpenApi::class, - read: true, - serialize: true, - provider: fn () => $this->openApiFactory->__invoke($context), - normalizationContext: [ - ApiGatewayNormalizer::API_GATEWAY => $context['api_gateway'] ?? null, - LegacyOpenApiNormalizer::SPEC_VERSION => $context['spec_version'] ?? null, - ], - outputFormats: $this->documentationFormats - ); - - if ('html' === $format) { - $operation = $operation->withProcessor('api_platform.swagger_ui.processor')->withWrite(true); - } - - return $this->processor->process($this->provider->provide($operation, [], $context), $operation, [], $context); - } - - return $this->openApiFactory->__invoke($context); - } - - /** - * TODO: the logic behind the Hydra Documentation is done in a ApiPlatform\Hydra\Serializer\DocumentationNormalizer. - * We should transform this to a provider, it'd improve performances also by a bit. - * - * @param array $context - */ - private function getHydraDocumentation(array $context, Request $request): DocumentationInterface|Response - { - if ($this->provider && $this->processor) { - $context['request'] = $request; - $operation = new Get( - class: Documentation::class, - read: true, - serialize: true, - provider: fn () => new Documentation($this->resourceNameCollectionFactory->create(), $this->title, $this->description, $this->version) - ); - - return $this->processor->process($this->provider->provide($operation, [], $context), $operation, [], $context); - } - - return new Documentation($this->resourceNameCollectionFactory->create(), $this->title, $this->description, $this->version); - } -} diff --git a/Action/EntrypointAction.php b/Action/EntrypointAction.php deleted file mode 100644 index d93e1d9..0000000 --- a/Action/EntrypointAction.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace ApiPlatform\Documentation\Action; - -use ApiPlatform\Documentation\Entrypoint; -use ApiPlatform\Metadata\Get; -use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; -use ApiPlatform\Metadata\Resource\ResourceNameCollection; -use ApiPlatform\OpenApi\Serializer\LegacyOpenApiNormalizer; -use ApiPlatform\State\ProcessorInterface; -use ApiPlatform\State\ProviderInterface; -use Symfony\Component\HttpFoundation\Request; - -/** - * Generates the API entrypoint. - * - * @deprecated use ApiPlatform\Symfony\EntrypointAction instead - * - * @author Kévin Dunglas - */ -final class EntrypointAction -{ - private static ResourceNameCollection $resourceNameCollection; - - public function __construct( - private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, - private readonly ProviderInterface $provider, - private readonly ProcessorInterface $processor, - private readonly array $documentationFormats = [], - ) { - } - - public function __invoke(Request $request) - { - self::$resourceNameCollection = $this->resourceNameCollectionFactory->create(); - $context = [ - 'request' => $request, - 'spec_version' => (string) $request->query->get(LegacyOpenApiNormalizer::SPEC_VERSION), - ]; - $request->attributes->set('_api_platform_disable_listeners', true); - $operation = new Get( - outputFormats: $this->documentationFormats, - read: true, - serialize: true, - class: Entrypoint::class, - provider: [self::class, 'provide'] - ); - $request->attributes->set('_api_operation', $operation); - $body = $this->provider->provide($operation, [], $context); - $operation = $request->attributes->get('_api_operation'); - - return $this->processor->process($body, $operation, [], $context); - } - - public static function provide(): Entrypoint - { - return new Entrypoint(self::$resourceNameCollection); - } -} diff --git a/composer.json b/composer.json index 71c570c..b02d87e 100644 --- a/composer.json +++ b/composer.json @@ -21,15 +21,17 @@ ], "require": { "php": ">=8.2", - "api-platform/metadata": "^3.4 || ^4.0" + "api-platform/metadata": "^5.0@alpha" }, "extra": { "branch-alias": { - "dev-main": "4.0.x-dev", - "dev-3.4": "3.4.x-dev" + "dev-main": "5.0.x-dev", + "dev-4.2": "4.2.x-dev", + "dev-3.4": "3.4.x-dev", + "dev-4.1": "4.1.x-dev" }, "symfony": { - "require": "^6.4 || ^7.0" + "require": "^6.4 || ^7.0 || ^8.0" }, "thanks": { "name": "api-platform/api-platform", @@ -37,6 +39,8 @@ } }, "require-dev": { - "phpunit/phpunit": "^11.2" - } + "phpunit/phpunit": "^11.5 || ^12.2" + }, + "minimum-stability": "beta", + "prefer-stable": true }