Skip to content

Commit ffd3b21

Browse files
committed
Merge 3.4
2 parents 8482aac + 0bff114 commit ffd3b21

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

Bundle/SwaggerUi/SwaggerUiProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Symfony\Bundle\SwaggerUi;
1515

1616
use ApiPlatform\Documentation\Documentation;
17+
use ApiPlatform\Documentation\Entrypoint;
1718
use ApiPlatform\Metadata\Error;
1819
use ApiPlatform\Metadata\Get;
1920
use ApiPlatform\Metadata\HttpOperation;
@@ -44,6 +45,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4445
!($operation instanceof HttpOperation)
4546
|| !($request = $context['request'] ?? null)
4647
|| 'html' !== $request->getRequestFormat()
48+
|| true === ($operation->getExtraProperties()['_api_disable_swagger_provider'] ?? false)
4749
) {
4850
return $this->decorated->provide($operation, $uriVariables, $context);
4951
}
@@ -55,11 +57,12 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5557
// We need to call our operation provider just in case it fails
5658
// when it fails we'll get an Error and we'll fix the status accordingly
5759
// @see features/main/content_negotiation.feature:119
58-
// DocumentationAction has no content negotation as well we want HTML so render swagger ui
59-
if (!$operation instanceof Error && Documentation::class !== $operation->getClass()) {
60+
// When requesting DocumentationAction or EntrypointAction with Accept: text/html we render SwaggerUi
61+
if (!$operation instanceof Error && !\in_array($operation->getClass(), [Documentation::class, Entrypoint::class], true)) {
6062
$this->decorated->provide($operation, $uriVariables, $context);
6163
}
6264

65+
// This should render only when an error occured
6366
$swaggerUiOperation = new Get(
6467
class: OpenApi::class,
6568
processor: 'api_platform.swagger_ui.processor',
@@ -71,7 +74,6 @@ class: OpenApi::class,
7174

7275
// save our operation
7376
$request->attributes->set('_api_operation', $swaggerUiOperation);
74-
7577
$data = $this->openApiFactory->__invoke(['base_url' => $request->getBaseUrl() ?: '/']);
7678
$request->attributes->set('data', $data);
7779

EventListener/ErrorListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re
7979
// - use api platform to handle errors (the default behavior we handle firewall errors for example but they're out of our scope)
8080

8181
// Let the error handler take this we don't handle HTML nor non-api platform requests
82-
if ('html' === $format) {
82+
if (false === ($apiOperation?->getExtraProperties()['_api_error_handler'] ?? true) || 'html' === $format) {
8383
$this->controller = 'error_controller';
8484

8585
return parent::duplicateRequest($exception, $request);

Routing/IriConverter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
7575
throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri));
7676
}
7777

78+
// uri_variables come from the Request context and may not be available
79+
foreach ($context['uri_variables'] ?? [] as $key => $value) {
80+
if (!isset($parameters[$key]) || $parameters[$key] !== (string) $value) {
81+
throw new InvalidArgumentException(sprintf('The iri "%s" does not reference the correct resource.', $iri));
82+
}
83+
}
84+
85+
if ($operation && !is_a($parameters['_api_resource_class'], $operation->getClass(), true)) {
86+
throw new InvalidArgumentException(sprintf('The iri "%s" does not reference the correct resource.', $iri));
87+
}
88+
7889
$operation = $parameters['_api_operation'] = $this->resourceMetadataCollectionFactory->create($parameters['_api_resource_class'])->getOperation($parameters['_api_operation_name']);
7990

8091
if ($operation instanceof CollectionOperationInterface) {

Tests/EventListener/QueryParameterValidateListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function testDoNothingWhenListenersDisabled(): void
204204
$event = new RequestEvent(
205205
$this->prophesize(HttpKernelInterface::class)->reveal(),
206206
new Request([], [], ['_api_resource_class' => Dummy::class, '_api_operation_name' => 'get', '_api_platform_disable_listeners' => true]),
207-
\defined(HttpKernelInterface::class.'::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST,
207+
HttpKernelInterface::MAIN_REQUEST,
208208
);
209209

210210
$listener->onKernelRequest($event);

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
"api-platform/state": "*@dev || ^3.1",
3434
"api-platform/validator": "*@dev || ^3.1",
3535
"api-platform/openapi": "*@dev || ^3.1",
36-
"symfony/property-info": "^6.4 || ^7.0",
37-
"symfony/property-access": "^6.4 || ^7.0",
38-
"symfony/serializer": "^6.4 || ^7.0",
36+
"symfony/property-info": "^6.4 || ^7.1",
37+
"symfony/property-access": "^6.4 || ^7.1",
38+
"symfony/serializer": "^6.4 || ^7.1",
3939
"symfony/security-core": "^6.4 || ^7.0"
4040
},
4141
"require-dev": {
@@ -72,13 +72,14 @@
7272
},
7373
"extra": {
7474
"branch-alias": {
75-
"dev-main": "3.3.x-dev"
75+
"dev-main": "4.0.x-dev",
76+
"dev-3.4": "3.4.x-dev"
7677
},
7778
"symfony": {
78-
"require": "^6.4"
79+
"require": "^6.4 || ^7.1"
7980
}
8081
},
8182
"scripts": {
8283
"test": "./vendor/bin/phpunit"
8384
}
84-
}
85+
}

0 commit comments

Comments
 (0)