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

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.     public function __construct(RenderOpenApi $renderOpenApi)
  24.     {
  25.         $this->renderOpenApi $renderOpenApi;
  26.     }
  27.     public function __invoke(Request $request$area 'default')
  28.     {
  29.         try {
  30.             $response = new Response(
  31.                 $this->renderOpenApi->renderFromRequest($requestRenderOpenApi::HTML$area, [
  32.                     'assets_mode' => AssetsMode::BUNDLE,
  33.                 ]),
  34.                 Response::HTTP_OK,
  35.                 ['Content-Type' => 'text/html']
  36.             );
  37.             return $response->setCharset('UTF-8');
  38.         } catch (RenderInvalidArgumentException $e) {
  39.             $advice '';
  40.             if (false !== strpos($area'.json')) {
  41.                 $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.';
  42.             }
  43.             throw new BadRequestHttpException(sprintf('Area "%s" is not supported as it isn\'t defined in config.%s'$area$advice), $e);
  44.         }
  45.     }
  46. }