welcome back to dyb-tech
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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\Html\AssetsMode;
|
||||
use Nelmio\ApiDocBundle\Render\RenderOpenApi;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
final class SwaggerUiController
|
||||
{
|
||||
/**
|
||||
* @var RenderOpenApi
|
||||
*/
|
||||
private $renderOpenApi;
|
||||
|
||||
public function __construct(RenderOpenApi $renderOpenApi)
|
||||
{
|
||||
$this->renderOpenApi = $renderOpenApi;
|
||||
}
|
||||
|
||||
public function __invoke(Request $request, $area = 'default')
|
||||
{
|
||||
try {
|
||||
$response = new Response(
|
||||
$this->renderOpenApi->renderFromRequest($request, RenderOpenApi::HTML, $area, [
|
||||
'assets_mode' => AssetsMode::BUNDLE,
|
||||
]),
|
||||
Response::HTTP_OK,
|
||||
['Content-Type' => 'text/html']
|
||||
);
|
||||
|
||||
return $response->setCharset('UTF-8');
|
||||
} catch (RenderInvalidArgumentException $e) {
|
||||
$advice = '';
|
||||
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.';
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException(sprintf('Area "%s" is not supported as it isn\'t defined in config.%s', $area, $advice), $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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 InvalidArgumentException;
|
||||
use Nelmio\ApiDocBundle\Render\RenderOpenApi;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
final class YamlDocumentationController
|
||||
{
|
||||
/**
|
||||
* @var RenderOpenApi
|
||||
*/
|
||||
private $renderOpenApi;
|
||||
|
||||
public function __construct(RenderOpenApi $renderOpenApi)
|
||||
{
|
||||
$this->renderOpenApi = $renderOpenApi;
|
||||
}
|
||||
|
||||
public function __invoke(Request $request, $area = 'default')
|
||||
{
|
||||
try {
|
||||
$response = new Response(
|
||||
$this->renderOpenApi->renderFromRequest($request, RenderOpenApi::YAML, $area),
|
||||
Response::HTTP_OK,
|
||||
['Content-Type' => 'text/x-yaml']
|
||||
);
|
||||
|
||||
return $response->setCharset('UTF-8');
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new BadRequestHttpException(sprintf('Area "%s" is not supported as it isn\'t defined in config.', $area));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user