Skip to content

Commit

Permalink
remove doctrine reader from ModelDescribers
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Oct 24, 2024
1 parent b2bdf21 commit 940c49c
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 27 deletions.
5 changes: 4 additions & 1 deletion UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public int $negative;
```

This causes the following breaking changes in classes that used on annotations:
- BC BREAK: Removed 3rd parameter `?Reader $annotationReader` from `Nelmio\ApiDocBundle\Describer\OpenApiPhpDescriber::__construct()`
- BC BREAK: Removed 3rd parameter `?Reader $annotationReader` from `Nelmio\ApiDocBundle\Describer\OpenApiPhpDescriber::__construct()`
- BC BREAK: Removed 2nd parameter `?Reader $annotationReader` from `Nelmio\ApiDocBundle\ModelDescriber\FormModelDescriber::__construct()`
- BC BREAK: Removed 2nd parameter `?Reader $annotationReader` from `Nelmio\ApiDocBundle\ModelDescriber\JMSModelDescriber::__construct()`
- BC BREAK: Removed 2nd parameter `?Reader $annotationReader` from `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()`
1 change: 0 additions & 1 deletion config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@

<service id="nelmio_api_doc.model_describers.object" class="Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber" public="false">
<argument type="service" id="property_info" />
<argument type="service" id="annotations.reader" on-invalid="null"/>
<argument type="service" id="nelmio_api_doc.object_model.property_describer" />
<argument />
<argument type="service" id="serializer.name_converter.metadata_aware" on-invalid="ignore" />
Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/Compiler/ConfigurationPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Nelmio\ApiDocBundle\ModelDescriber\FormModelDescriber;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;

/**
Expand All @@ -30,7 +29,6 @@ public function process(ContainerBuilder $container): void
$container->register('nelmio_api_doc.model_describers.form', FormModelDescriber::class)
->setPublic(false)
->addArgument(new Reference('form.factory'))
->addArgument(new Reference('annotations.reader', ContainerInterface::NULL_ON_INVALID_REFERENCE))
->addArgument($container->getParameter('nelmio_api_doc.media_types'))
->addArgument($container->getParameter('nelmio_api_doc.use_validation_groups'))
->addArgument($container->getParameter('form.type_extension.csrf.enabled'))
Expand Down
3 changes: 1 addition & 2 deletions src/DependencyInjection/NelmioApiDocExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function load(array $configs, ContainerBuilder $container): void
));

$container->getDefinition('nelmio_api_doc.model_describers.object')
->setArgument(3, $config['media_types']);
->setArgument(2, $config['media_types']);

// Add autoconfiguration for model describer
$container->registerForAutoconfiguration(ModelDescriberInterface::class)
Expand Down Expand Up @@ -246,7 +246,6 @@ public function load(array $configs, ContainerBuilder $container): void
->setPublic(false)
->setArguments([
new Reference('jms_serializer.metadata_factory'),
new Reference('annotations.reader', ContainerInterface::NULL_ON_INVALID_REFERENCE),
$config['media_types'],
$jmsNamingStrategy,
$container->getParameter('nelmio_api_doc.use_validation_groups'),
Expand Down
4 changes: 0 additions & 4 deletions src/ModelDescriber/FormModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Nelmio\ApiDocBundle\ModelDescriber;

use Doctrine\Common\Annotations\Reader;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Nelmio\ApiDocBundle\Model\Model;
Expand Down Expand Up @@ -39,7 +38,6 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
use SetsContextTrait;

private ?FormFactoryInterface $formFactory;
private ?Reader $doctrineReader;

/**
* @var string[]
Expand All @@ -53,13 +51,11 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
*/
public function __construct(
?FormFactoryInterface $formFactory = null,
?Reader $reader = null,
?array $mediaTypes = null,
bool $useValidationGroups = false,
bool $isFormCsrfExtensionEnabled = false
) {
$this->formFactory = $formFactory;
$this->doctrineReader = $reader;

if (null === $mediaTypes) {
$mediaTypes = ['json'];
Expand Down
5 changes: 0 additions & 5 deletions src/ModelDescriber/JMSModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Nelmio\ApiDocBundle\ModelDescriber;

use Doctrine\Common\Annotations\Reader;
use JMS\Serializer\Context;
use JMS\Serializer\ContextFactory\SerializationContextFactoryInterface;
use JMS\Serializer\Exclusion\GroupsExclusionStrategy;
Expand Down Expand Up @@ -42,8 +41,6 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn

private ?PropertyNamingStrategyInterface $namingStrategy;

private ?Reader $doctrineReader;

/**
* @var array<string, Context>
*/
Expand Down Expand Up @@ -71,15 +68,13 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
*/
public function __construct(
MetadataFactoryInterface $factory,
?Reader $reader,
array $mediaTypes,
?PropertyNamingStrategyInterface $namingStrategy = null,
bool $useValidationGroups = false,
?SerializationContextFactoryInterface $contextFactory = null
) {
$this->factory = $factory;
$this->namingStrategy = $namingStrategy;
$this->doctrineReader = $reader;
$this->mediaTypes = $mediaTypes;
$this->useValidationGroups = $useValidationGroups;
$this->contextFactory = $contextFactory;
Expand Down
4 changes: 0 additions & 4 deletions src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Nelmio\ApiDocBundle\ModelDescriber;

use Doctrine\Common\Annotations\Reader;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Nelmio\ApiDocBundle\Model\Model;
Expand All @@ -33,7 +32,6 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar

private PropertyInfoExtractorInterface $propertyInfo;
private ?ClassMetadataFactoryInterface $classMetadataFactory;
private ?Reader $doctrineReader;
/** @var PropertyDescriberInterface|PropertyDescriberInterface[] */
private $propertyDescriber;
/** @var string[] */
Expand All @@ -49,7 +47,6 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
*/
public function __construct(
PropertyInfoExtractorInterface $propertyInfo,
?Reader $reader,
$propertyDescribers,
array $mediaTypes,
?NameConverterInterface $nameConverter = null,
Expand All @@ -65,7 +62,6 @@ public function __construct(
}

$this->propertyInfo = $propertyInfo;
$this->doctrineReader = $reader;
$this->propertyDescriber = $propertyDescribers;
$this->mediaTypes = $mediaTypes;
$this->nameConverter = $nameConverter;
Expand Down
5 changes: 1 addition & 4 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Nelmio\ApiDocBundle\Tests\Functional;

use Doctrine\Common\Annotations\Reader;
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Annotations as OAAnnotations;
use OpenApi\Attributes as OAAttributes;
Expand Down Expand Up @@ -62,9 +61,7 @@ public function testFetchArticleAction(string $articleRoute): void

public static function provideArticleRoute(): \Generator
{
if (interface_exists(Reader::class)) {
yield 'Annotations' => ['/api/article/{id}'];
}
yield 'Annotations' => ['/api/article/{id}'];

yield 'Attributes' => ['/api/article_attributes/{id}'];
}
Expand Down
5 changes: 1 addition & 4 deletions tests/ModelDescriber/FormModelDescriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Nelmio\ApiDocBundle\Tests\ModelDescriber;

use Doctrine\Common\Annotations\Reader;
use Nelmio\ApiDocBundle\Model\Model;
use Nelmio\ApiDocBundle\Model\ModelRegistry;
use Nelmio\ApiDocBundle\ModelDescriber\FormModelDescriber;
Expand Down Expand Up @@ -56,14 +55,12 @@ public function testDescribeCreatesTokenPropertyDependingOnOptions(bool $csrfPro
->method('create')
->willReturn($formMock);

$annotationReader = $this->createMock(Reader::class);

$api = new OpenApi();
$model = new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, FormType::class));
$schema = $this->initSchema();
$modelRegistry = new ModelRegistry([], $api);

$describer = new FormModelDescriber($formFactoryMock, $annotationReader, [], false, true);
$describer = new FormModelDescriber($formFactoryMock, [], false, true);
$describer->setModelRegistry($modelRegistry);

$describer->describe($model, $schema);
Expand Down

0 comments on commit 940c49c

Please sign in to comment.