Skip to content

Commit 3d32d5e

Browse files
authored
fix(openapi): entrypoint access vnd+openapi (#6012)
fixes #6010
1 parent 3408c31 commit 3d32d5e

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: Entrypoint support
2+
In order to build an auto-discoverable API
3+
As a client software developer
4+
I need to access to an entrypoint listing top-level resources
5+
6+
Scenario: Retrieve the Entrypoint
7+
When I add "Accept" header equal to "application/vnd.openapi+json"
8+
When I send a "GET" request to "/"
9+
Then the response status code should be 200
10+
And the response should be in JSON
11+
And the header "Content-Type" should be equal to "application/vnd.openapi+json; charset=utf-8"
12+
And the JSON should be sorted
13+
14+
Scenario: Retrieve the Entrypoint with url format
15+
When I send a "GET" request to "/index.jsonopenapi"
16+
Then the response status code should be 200
17+
And the response should be in JSON
18+
And the header "Content-Type" should be equal to "application/vnd.openapi+json; charset=utf-8"
19+
And the JSON should be sorted

src/Symfony/Bundle/Resources/config/legacy/events.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<argument>%api_platform.formats%</argument>
1111
<argument>%api_platform.error_formats%</argument>
1212
<argument>%api_platform.docs_formats%</argument>
13-
<argument>%api_platform.event_listeners_backward_compatibility_layer%</argument>
13+
<argument>null</argument>
1414

1515
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="28" />
1616
</service>

src/Symfony/EventListener/AddFormatListener.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class AddFormatListener
3434
{
3535
use OperationRequestInitiatorTrait;
3636

37-
public function __construct(private readonly Negotiator $negotiator, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, private readonly array $formats = [], private readonly array $errorFormats = [], private readonly array $docsFormats = [], private readonly bool $eventsBackwardCompatibility = true)
37+
public function __construct(private readonly Negotiator $negotiator, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, private readonly array $formats = [], private readonly array $errorFormats = [], private readonly array $docsFormats = [], private readonly ?bool $eventsBackwardCompatibility = null) // @phpstan-ignore-line
3838
{
3939
$this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
4040
}
@@ -50,7 +50,11 @@ public function onKernelRequest(RequestEvent $event): void
5050
$request = $event->getRequest();
5151
$operation = $this->initializeOperation($request);
5252

53-
if ('api_platform.symfony.main_controller' === $operation?->getController() || ($this->eventsBackwardCompatibility && 'api_platform.action.entrypoint' === $request->attributes->get('_controller')) || $request->attributes->get('_api_platform_disable_listeners')) {
53+
if ('api_platform.action.entrypoint' === $request->attributes->get('_controller')) {
54+
return;
55+
}
56+
57+
if ('api_platform.symfony.main_controller' === $operation?->getController() || $request->attributes->get('_api_platform_disable_listeners')) {
5458
return;
5559
}
5660

0 commit comments

Comments
 (0)