Skip to content

Commit 2703a45

Browse files
committed
fix(swagger): no throw when operation is not found
1 parent e65d2c3 commit 2703a45

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Symfony/Bundle/SwaggerUi/SwaggerUiAction.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Symfony\Bundle\SwaggerUi;
1515

16-
use ApiPlatform\Exception\RuntimeException;
1716
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
1817
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
1918
use ApiPlatform\OpenApi\Options;
@@ -94,13 +93,15 @@ public function __invoke(Request $request): Response
9493
$swaggerData['shortName'] = $metadata->getShortName();
9594
$swaggerData['operationId'] = $this->normalizeOperationName($metadata->getName());
9695

97-
[$swaggerData['path'], $swaggerData['method']] = $this->getPathAndMethod($swaggerData);
96+
if ($data = $this->getPathAndMethod($swaggerData)) {
97+
[$swaggerData['path'], $swaggerData['method']] = $data;
98+
}
9899
}
99100

100101
return new Response($this->twig->render('@ApiPlatform/SwaggerUi/index.html.twig', $swaggerContext + ['swagger_data' => $swaggerData]));
101102
}
102103

103-
private function getPathAndMethod(array $swaggerData): array
104+
private function getPathAndMethod(array $swaggerData): ?array
104105
{
105106
foreach ($swaggerData['spec']['paths'] as $path => $operations) {
106107
foreach ($operations as $method => $operation) {
@@ -110,6 +111,6 @@ private function getPathAndMethod(array $swaggerData): array
110111
}
111112
}
112113

113-
throw new RuntimeException(sprintf('The operation "%s" cannot be found in the Swagger specification.', $swaggerData['operationId']));
114+
return null;
114115
}
115116
}

0 commit comments

Comments
 (0)