vendor/nelmio/api-doc-bundle/src/Controller/SwaggerUiController.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the NelmioApiDocBundle package.
  4.  *
  5.  * (c) Nelmio
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Nelmio\ApiDocBundle\Controller;
  11. use Nelmio\ApiDocBundle\Exception\RenderInvalidArgumentException;
  12. use Nelmio\ApiDocBundle\Render\Html\AssetsMode;
  13. use Nelmio\ApiDocBundle\Render\RenderOpenApi;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  17. final class SwaggerUiController
  18. {
  19.     /**
  20.      * @var RenderOpenApi
  21.      */
  22.     private $renderOpenApi;
  23.     /**
  24.      * @var string
  25.      */
  26.     private $uiRenderer;
  27.     public function __construct(RenderOpenApi $renderOpenApistring $uiRenderer)
  28.     {
  29.         $this->renderOpenApi $renderOpenApi;
  30.         $this->uiRenderer $uiRenderer;
  31.     }
  32.     public function __invoke(Request $request$area 'default')
  33.     {
  34.         try {
  35.             $response = new Response(
  36.                 $this->renderOpenApi->renderFromRequest($requestRenderOpenApi::HTML$area, [
  37.                     'assets_mode' => AssetsMode::BUNDLE,
  38.                     'ui_renderer' => $this->uiRenderer,
  39.                 ]),
  40.                 Response::HTTP_OK,
  41.                 ['Content-Type' => 'text/html']
  42.             );
  43.             return $response->setCharset('UTF-8');
  44.         } catch (RenderInvalidArgumentException $e) {
  45.             $advice '';
  46.             if (false !== strpos($area'.json')) {
  47.                 $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.';
  48.             }
  49.             throw new BadRequestHttpException(sprintf('Area "%s" is not supported as it isn\'t defined in config.%s'$area$advice), $e);
  50.         }
  51.     }
  52. }