mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-10 17:46:09 +03:00
Catch a more precise exception in Swagger controller (#2005)
This commit is contained in:
parent
235963df41
commit
f33eee70fc
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Controller;
|
namespace Nelmio\ApiDocBundle\Controller;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use Nelmio\ApiDocBundle\Exception\RenderInvalidArgumentException;
|
||||||
use Nelmio\ApiDocBundle\Render\Html\AssetsMode;
|
use Nelmio\ApiDocBundle\Render\Html\AssetsMode;
|
||||||
use Nelmio\ApiDocBundle\Render\RenderOpenApi;
|
use Nelmio\ApiDocBundle\Render\RenderOpenApi;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -42,7 +42,7 @@ final class SwaggerUiController
|
|||||||
);
|
);
|
||||||
|
|
||||||
return $response->setCharset('UTF-8');
|
return $response->setCharset('UTF-8');
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (RenderInvalidArgumentException $e) {
|
||||||
$advice = '';
|
$advice = '';
|
||||||
if (false !== strpos($area, '.json')) {
|
if (false !== strpos($area, '.json')) {
|
||||||
$advice = ' Since the area provided contains `.json`, the issue is likely caused by route priorities. Try switching the Swagger UI / the json documentation routes order.';
|
$advice = ' Since the area provided contains `.json`, the issue is likely caused by route priorities. Try switching the Swagger UI / the json documentation routes order.';
|
||||||
|
16
Exception/RenderInvalidArgumentException.php
Normal file
16
Exception/RenderInvalidArgumentException.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the NelmioApiDocBundle package.
|
||||||
|
*
|
||||||
|
* (c) Nelmio
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Nelmio\ApiDocBundle\Exception;
|
||||||
|
|
||||||
|
class RenderInvalidArgumentException extends \InvalidArgumentException
|
||||||
|
{
|
||||||
|
}
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Render;
|
namespace Nelmio\ApiDocBundle\Render;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use Nelmio\ApiDocBundle\Exception\RenderInvalidArgumentException;
|
||||||
use OpenApi\Annotations\OpenApi;
|
use OpenApi\Annotations\OpenApi;
|
||||||
use OpenApi\Annotations\Server;
|
use OpenApi\Annotations\Server;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
@ -65,9 +65,9 @@ class RenderOpenApi
|
|||||||
public function render(string $format, string $area, array $options = []): string
|
public function render(string $format, string $area, array $options = []): string
|
||||||
{
|
{
|
||||||
if (!$this->generatorLocator->has($area)) {
|
if (!$this->generatorLocator->has($area)) {
|
||||||
throw new InvalidArgumentException(sprintf('Area "%s" is not supported.', $area));
|
throw new RenderInvalidArgumentException(sprintf('Area "%s" is not supported.', $area));
|
||||||
} elseif (!array_key_exists($format, $this->openApiRenderers)) {
|
} elseif (!array_key_exists($format, $this->openApiRenderers)) {
|
||||||
throw new InvalidArgumentException(sprintf('Format "%s" is not supported.', $format));
|
throw new RenderInvalidArgumentException(sprintf('Format "%s" is not supported.', $format));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var OpenApi $spec */
|
/** @var OpenApi $spec */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user