Skip to content

Commit 660955b

Browse files
authored
fix(symfony): show documentation as entrypoint when requesting html (#5836)
1 parent 1c6862d commit 660955b

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/Action/EntrypointAction.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ final class EntrypointAction
3131
public function __construct(
3232
private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory,
3333
private readonly ?ProviderInterface $provider = null,
34-
private readonly ?ProcessorInterface $processor = null
34+
private readonly ?ProcessorInterface $processor = null,
35+
private readonly array $documentationFormats = []
3536
) {
3637
}
3738

@@ -42,7 +43,7 @@ public function __invoke(Request $request = null)
4243
{
4344
if ($this->provider && $this->processor) {
4445
$context = ['request' => $request];
45-
$operation = new Get(read: true, serialize: true, class: Entrypoint::class, provider: fn () => new Entrypoint($this->resourceNameCollectionFactory->create()));
46+
$operation = new Get(outputFormats: $this->documentationFormats, read: true, serialize: true, class: Entrypoint::class, provider: fn () => new Entrypoint($this->resourceNameCollectionFactory->create()));
4647
$body = $this->provider->provide($operation, [], $context);
4748

4849
return $this->processor->process($body, $operation, [], $context);

src/Symfony/Bundle/Resources/config/api.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />
101101
<argument type="service" id="api_platform.state_provider.main" on-invalid="null" />
102102
<argument type="service" id="api_platform.state_processor.main" on-invalid="null" />
103+
<argument>%api_platform.docs_formats%</argument>
103104
</service>
104105

105106
<service id="api_platform.action.documentation" class="ApiPlatform\Documentation\Action\DocumentationAction" public="true">

tests/Fixtures/app/config/config_common.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ api_platform:
4848
jsonopenapi: ['application/vnd.openapi+json']
4949
yamlopenapi: ['application/vnd.openapi+yaml']
5050
jsonld: ['application/ld+json']
51+
jsonhal: ['application/hal+json']
52+
jsonapi: ['application/vnd.api+json']
5153
error_formats:
5254
jsonproblem: ['application/problem+json']
5355
jsonld: ['application/ld+json']

0 commit comments

Comments
 (0)