Skip to content

Commit

Permalink
fix(swagger): no throw when operation is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Sep 11, 2023
1 parent e65d2c3 commit 2703a45
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Symfony/Bundle/SwaggerUi/SwaggerUiAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace ApiPlatform\Symfony\Bundle\SwaggerUi;

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

[$swaggerData['path'], $swaggerData['method']] = $this->getPathAndMethod($swaggerData);
if ($data = $this->getPathAndMethod($swaggerData)) {
[$swaggerData['path'], $swaggerData['method']] = $data;
}
}

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

private function getPathAndMethod(array $swaggerData): array
private function getPathAndMethod(array $swaggerData): ?array
{
foreach ($swaggerData['spec']['paths'] as $path => $operations) {
foreach ($operations as $method => $operation) {
Expand All @@ -110,6 +111,6 @@ private function getPathAndMethod(array $swaggerData): array
}
}

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

0 comments on commit 2703a45

Please sign in to comment.