Skip to content

Commit 7826566

Browse files
committed
Merge 3.3
2 parents fb75008 + cf89f9f commit 7826566

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
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

Routing/IriConverter.php

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

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

8394
if ($operation instanceof CollectionOperationInterface) {

0 commit comments

Comments
 (0)