From 5fcbc5c97b2881750ade5c3012b5536e0dd7066f Mon Sep 17 00:00:00 2001 From: soyuka Date: Tue, 19 Sep 2023 11:50:50 +0200 Subject: [PATCH] fix(symfony): show documentation as entrypoint when requesting html --- src/Action/EntrypointAction.php | 5 +++-- src/Symfony/Bundle/Resources/config/api.xml | 1 + tests/Fixtures/app/config/config_common.yml | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Action/EntrypointAction.php b/src/Action/EntrypointAction.php index 08c0c737130..ad49c747b03 100644 --- a/src/Action/EntrypointAction.php +++ b/src/Action/EntrypointAction.php @@ -31,7 +31,8 @@ final class EntrypointAction public function __construct( private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, private readonly ?ProviderInterface $provider = null, - private readonly ?ProcessorInterface $processor = null + private readonly ?ProcessorInterface $processor = null, + private readonly array $documentationFormats = [] ) { } @@ -42,7 +43,7 @@ public function __invoke(Request $request = null) { if ($this->provider && $this->processor) { $context = ['request' => $request]; - $operation = new Get(read: true, serialize: true, class: Entrypoint::class, provider: fn () => new Entrypoint($this->resourceNameCollectionFactory->create())); + $operation = new Get(outputFormats: $this->documentationFormats, read: true, serialize: true, class: Entrypoint::class, provider: fn () => new Entrypoint($this->resourceNameCollectionFactory->create())); $body = $this->provider->provide($operation, [], $context); return $this->processor->process($body, $operation, [], $context); diff --git a/src/Symfony/Bundle/Resources/config/api.xml b/src/Symfony/Bundle/Resources/config/api.xml index 97fd4fc9b86..cf6802b2d80 100644 --- a/src/Symfony/Bundle/Resources/config/api.xml +++ b/src/Symfony/Bundle/Resources/config/api.xml @@ -100,6 +100,7 @@ + %api_platform.docs_formats% diff --git a/tests/Fixtures/app/config/config_common.yml b/tests/Fixtures/app/config/config_common.yml index 4408d6ed18d..449c1d268f3 100644 --- a/tests/Fixtures/app/config/config_common.yml +++ b/tests/Fixtures/app/config/config_common.yml @@ -48,6 +48,8 @@ api_platform: jsonopenapi: ['application/vnd.openapi+json'] yamlopenapi: ['application/vnd.openapi+yaml'] jsonld: ['application/ld+json'] + jsonhal: ['application/hal+json'] + jsonapi: ['application/vnd.api+json'] error_formats: jsonproblem: ['application/problem+json'] jsonld: ['application/ld+json']