mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-10 03:29:25 +03:00
Remove deprecated features (#1640)
* Remove deprecated features * Fix cs
This commit is contained in:
parent
58f791c0f7
commit
d558560f61
@ -11,11 +11,9 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Controller;
|
namespace Nelmio\ApiDocBundle\Controller;
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\ApiDocGenerator;
|
|
||||||
use OpenApi\Annotations\OpenApi;
|
use OpenApi\Annotations\OpenApi;
|
||||||
use OpenApi\Annotations\Server;
|
use OpenApi\Annotations\Server;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
@ -24,22 +22,8 @@ final class DocumentationController
|
|||||||
{
|
{
|
||||||
private $generatorLocator;
|
private $generatorLocator;
|
||||||
|
|
||||||
/**
|
public function __construct(ContainerInterface $generatorLocator)
|
||||||
* @param ContainerInterface $generatorLocator
|
|
||||||
*/
|
|
||||||
public function __construct($generatorLocator)
|
|
||||||
{
|
{
|
||||||
if (!$generatorLocator instanceof ContainerInterface) {
|
|
||||||
if (!$generatorLocator instanceof ApiDocGenerator) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" to "%s" is not supported.', get_class($generatorLocator), __METHOD__));
|
|
||||||
}
|
|
||||||
|
|
||||||
@trigger_error(sprintf('Providing an instance of "%s" to "%s()" is deprecated since version 3.1. Provide it an instance of "%s" instead.', ApiDocGenerator::class, __METHOD__, ContainerInterface::class), E_USER_DEPRECATED);
|
|
||||||
$generatorLocator = new ServiceLocator(['default' => function () use ($generatorLocator): ApiDocGenerator {
|
|
||||||
return $generatorLocator;
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->generatorLocator = $generatorLocator;
|
$this->generatorLocator = $generatorLocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,11 +11,9 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Controller;
|
namespace Nelmio\ApiDocBundle\Controller;
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\ApiDocGenerator;
|
|
||||||
use OpenApi\Annotations\OpenApi;
|
use OpenApi\Annotations\OpenApi;
|
||||||
use OpenApi\Annotations\Server;
|
use OpenApi\Annotations\Server;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
@ -27,26 +25,12 @@ final class SwaggerUiController
|
|||||||
|
|
||||||
private $twig;
|
private $twig;
|
||||||
|
|
||||||
/**
|
public function __construct(ContainerInterface $generatorLocator, $twig)
|
||||||
* @param ContainerInterface $generatorLocator
|
|
||||||
*/
|
|
||||||
public function __construct($generatorLocator, $twig)
|
|
||||||
{
|
{
|
||||||
if (!$twig instanceof \Twig_Environment && !$twig instanceof Environment) {
|
if (!$twig instanceof \Twig_Environment && !$twig instanceof Environment) {
|
||||||
throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" as twig is not supported.', get_class($twig)));
|
throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" as twig is not supported.', get_class($twig)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$generatorLocator instanceof ContainerInterface) {
|
|
||||||
if (!$generatorLocator instanceof ApiDocGenerator) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" to "%s" is not supported.', get_class($generatorLocator), __METHOD__));
|
|
||||||
}
|
|
||||||
|
|
||||||
@trigger_error(sprintf('Providing an instance of "%s" to "%s()" is deprecated since version 3.1. Provide it an instance of "%s" instead.', ApiDocGenerator::class, __METHOD__, ContainerInterface::class), E_USER_DEPRECATED);
|
|
||||||
$generatorLocator = new ServiceLocator(['default' => function () use ($generatorLocator): ApiDocGenerator {
|
|
||||||
return $generatorLocator;
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->generatorLocator = $generatorLocator;
|
$this->generatorLocator = $generatorLocator;
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
}
|
}
|
||||||
|
@ -28,24 +28,6 @@ final class Configuration implements ConfigurationInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$rootNode
|
$rootNode
|
||||||
->beforeNormalization()
|
|
||||||
->ifTrue(function ($v) {
|
|
||||||
return !isset($v['areas']) && isset($v['routes']);
|
|
||||||
})
|
|
||||||
->then(function ($v) {
|
|
||||||
$v['areas'] = $v['routes'];
|
|
||||||
unset($v['routes']);
|
|
||||||
@trigger_error('The `nelmio_api_doc.routes` config option is deprecated. Please use `nelmio_api_doc.areas` instead (just replace `routes` by `areas` in your config).', E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
return $v;
|
|
||||||
})
|
|
||||||
->end()
|
|
||||||
->beforeNormalization()
|
|
||||||
->ifTrue(function ($v) {
|
|
||||||
return isset($v['routes']);
|
|
||||||
})
|
|
||||||
->thenInvalid('You must not use both `nelmio_api_doc.areas` and `nelmio_api_doc.routes` config options. Please update your config to only use `nelmio_api_doc.areas`.')
|
|
||||||
->end()
|
|
||||||
->children()
|
->children()
|
||||||
->arrayNode('documentation')
|
->arrayNode('documentation')
|
||||||
->useAttributeAsKey('key')
|
->useAttributeAsKey('key')
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
<?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\Tests\Controller;
|
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\ApiDocGenerator;
|
|
||||||
use Nelmio\ApiDocBundle\Controller\DocumentationController;
|
|
||||||
use Nelmio\ApiDocBundle\Controller\SwaggerUiController;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
class ControllersTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
* @expectedDeprecation Providing an instance of "Nelmio\ApiDocBundle\ApiDocGenerator" to "Nelmio\ApiDocBundle\Controller\SwaggerUiController::__construct()" is deprecated since version 3.1. Provide it an instance of "Psr\Container\ContainerInterface" instead.
|
|
||||||
*/
|
|
||||||
public function testSwaggerUiControllerInstanciation()
|
|
||||||
{
|
|
||||||
if (class_exists('Twig_Environment')) {
|
|
||||||
$twigMock = $this->createMock('Twig_Environment');
|
|
||||||
} else {
|
|
||||||
$twigMock = $this->createMock('Twig\Environment');
|
|
||||||
}
|
|
||||||
|
|
||||||
$controller = new SwaggerUiController(new ApiDocGenerator([], []), $twigMock);
|
|
||||||
$controller(new Request());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
* @expectedDeprecation Providing an instance of "Nelmio\ApiDocBundle\ApiDocGenerator" to "Nelmio\ApiDocBundle\Controller\DocumentationController::__construct()" is deprecated since version 3.1. Provide it an instance of "Psr\Container\ContainerInterface" instead.
|
|
||||||
*/
|
|
||||||
public function testDocumentationControllerInstanciation()
|
|
||||||
{
|
|
||||||
$controller = new DocumentationController(new ApiDocGenerator([], []));
|
|
||||||
$controller(new Request());
|
|
||||||
}
|
|
||||||
}
|
|
@ -144,39 +144,4 @@ class ConfigurationTest extends TestCase
|
|||||||
],
|
],
|
||||||
], $config['models']['names']);
|
], $config['models']['names']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testBothAreasAndRoutes()
|
|
||||||
{
|
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
|
||||||
$this->expectExceptionMessage('You must not use both `nelmio_api_doc.areas` and `nelmio_api_doc.routes` config options. Please update your config to only use `nelmio_api_doc.areas`.');
|
|
||||||
|
|
||||||
$processor = new Processor();
|
|
||||||
$config = $processor->processConfiguration(new Configuration(), [['areas' => [], 'routes' => []]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
* @expectedDeprecation The `nelmio_api_doc.routes` config option is deprecated. Please use `nelmio_api_doc.areas` instead (just replace `routes` by `areas` in your config).
|
|
||||||
*/
|
|
||||||
public function testDefaultConfig()
|
|
||||||
{
|
|
||||||
$processor = new Processor();
|
|
||||||
$config = $processor->processConfiguration(new Configuration(), [['routes' => ['path_patterns' => ['/foo']]]]);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
[
|
|
||||||
'default' => [
|
|
||||||
'path_patterns' => ['/foo'],
|
|
||||||
'host_patterns' => [],
|
|
||||||
'name_patterns' => [],
|
|
||||||
'with_annotation' => false,
|
|
||||||
'documentation' => [],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
$config['areas']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user