mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
fd45120d5c
* Catch more precise exception in DocumentationController * cs * Fix tests
43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?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\Controller;
|
|
|
|
use Nelmio\ApiDocBundle\Exception\RenderInvalidArgumentException;
|
|
use Nelmio\ApiDocBundle\Render\RenderOpenApi;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
|
|
|
final class DocumentationController
|
|
{
|
|
/**
|
|
* @var RenderOpenApi
|
|
*/
|
|
private $renderOpenApi;
|
|
|
|
public function __construct(RenderOpenApi $renderOpenApi)
|
|
{
|
|
$this->renderOpenApi = $renderOpenApi;
|
|
}
|
|
|
|
public function __invoke(Request $request, $area = 'default')
|
|
{
|
|
try {
|
|
return JsonResponse::fromJsonString(
|
|
$this->renderOpenApi->renderFromRequest($request, RenderOpenApi::JSON, $area)
|
|
);
|
|
} catch (RenderInvalidArgumentException $e) {
|
|
throw new BadRequestHttpException(sprintf('Area "%s" is not supported as it isn\'t defined in config.', $area));
|
|
}
|
|
}
|
|
}
|