Skip to content

Commit

Permalink
chore: [5.x] remove deprecations (#2388)
Browse files Browse the repository at this point in the history
## Description

Removes all deprecations from `4.x`

## What type of PR is this? (check all applicable)
- [ ] Bug Fix
- [ ] Feature
- [ ] Refactor
- [ ] Deprecation
- [x] Breaking Change
- [ ] Documentation Update
- [ ] CI

## Checklist
- [ ] I have made corresponding changes to the documentation (`docs/`)
- [x] I have made corresponding changes to the changelog
(`CHANGELOG.md`)
  • Loading branch information
DjordyKoert authored Nov 12, 2024
1 parent ba50187 commit abd21f3
Show file tree
Hide file tree
Showing 30 changed files with 93 additions and 699 deletions.
35 changes: 35 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,39 @@ nelmio_api_doc:
- ^/api/foo
- with_annotation: true
+ with_attribute: true
```

## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\NullablePropertyTrait`
This class was deprecated since `4.17.0`

## Removed optional 4th param `bool $overwrite = false` from `Nelmio\ApiDocBundle\Describer\OpenApiPhpDescriber::__construct()`
This parameter was deprecated since `4.25.2`

## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\RequiredPropertyDescriber`

## BC BREAK: Removed `Nelmio\ApiDocBundle\Form\Extension::getExtendedType()`

## BC BREAK: Removed `null` as a possible type for parameter `$options` in `Nelmio\ApiDocBundle\Model\Model::__construct()` & `Nelmio\ApiDocBundle\Attribute\Model::__construct()`

## BC BREAK: Removed `Nelmio\ApiDocBundle\Exception\UndocumentedArrayItemsException`

## BC BREAK: Changed type of parameter `$propertyDescriber` in `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()` from `PropertyDescriberInterface|PropertyDescriberInterface[]` to `PropertyDescriberInterface`

## BC BREAK: Removed passing an indexed array with a collection of path patterns as argument 1 for `Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder::__construct()`

## BC BREAK: Updated `PropertyDescriberInterface::describe()` signature
```diff
- public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */ /* , array $context = [] */);
+ public function describe(array $types, Schema $property, array $context = []);
```

`$groups` are passed in `$context` and can be accessed via `$context['groups']`.

`$schema` has been removed with no replacement.

## BC BREAK: Updated `PropertyDescriberInterface::supports()` signature
Future proofing for potential future changes and keeping it consistent with `describe()`.
```diff
- public function supports(array $types): bool;
+ public function supports(array $types, array $context = []): bool;
```
40 changes: 0 additions & 40 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@ parameters:
count: 1
path: src/Describer/ExternalDocDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/ArrayPropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/CompoundPropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/DictionaryPropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/NullablePropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/PropertyDescriber.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$context$#"
count: 1
path: src/PropertyDescriber/PropertyDescriberInterface.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$schema$#"
count: 1
path: src/PropertyDescriber/PropertyDescriberInterface.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/RequiredPropertyDescriber.php

-
message: "#^Call to method render\\(\\) on an unknown class Twig_Environment\\.$#"
count: 2
Expand Down
7 changes: 1 addition & 6 deletions src/Attribute/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,9 @@ public function __construct(
array $properties = [],
string $type = Generator::UNDEFINED,
?array $groups = null,
?array $options = [],
array $options = [],
array $serializationContext = []
) {
if (null === $options) {
trigger_deprecation('nelmio/api-doc-bundle', '4.33.4', 'Passing null to the "$options" argument of "%s()" is deprecated, pass an empty array instead.', __METHOD__);
$options = [];
}

parent::__construct($properties + [
'type' => $type,
'groups' => $groups,
Expand Down
6 changes: 1 addition & 5 deletions src/Describer/OpenApiPhpDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ final class OpenApiPhpDescriber
private ControllerReflector $controllerReflector;
private LoggerInterface $logger;

public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, LoggerInterface $logger, bool $overwrite = false)
public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, LoggerInterface $logger)
{
if ($overwrite || func_num_args() > 4) {
trigger_deprecation('nelmio/api-doc-bundle', '4.25.2', 'The "$overwrite" argument of "%s" is unused and therefore deprecated.', __METHOD__);
}

$this->routeCollection = $routeCollection;
$this->controllerReflector = $controllerReflector;
$this->logger = $logger;
Expand Down
58 changes: 0 additions & 58 deletions src/Exception/UndocumentedArrayItemsException.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Form/Extension/DocumentationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@ public function configureOptions(OptionsResolver $resolver): void
->setAllowedTypes('documentation', ['array', 'bool']);
}

/**
* @deprecated since Symfony 4.2, use getExtendedTypes() instead.
*
* @return string
*/
public function getExtendedType()
{
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.28.1',
'Calling %s is deprecated since Symfony 4.2, call %s instead',
__METHOD__,
'DocumentationExtension::getExtendedTypes()',
);

return self::getExtendedTypes()[0];
}

public static function getExtendedTypes(): iterable
{
return [FormType::class];
Expand Down
9 changes: 2 additions & 7 deletions src/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@ final class Model

/**
* @param string[]|null $groups
* @param mixed[]|null $options
* @param mixed[] $options
* @param mixed[] $serializationContext
*/
public function __construct(Type $type, ?array $groups = null, ?array $options = [], array $serializationContext = [])
public function __construct(Type $type, ?array $groups = null, array $options = [], array $serializationContext = [])
{
if (null === $options) {
trigger_deprecation('nelmio/api-doc-bundle', '4.33.4', 'Passing null to the "$options" argument of "%s()" is deprecated, pass an empty array instead.', __METHOD__);
$options = [];
}

$this->type = $type;
$this->options = $options;
$this->serializationContext = $serializationContext;
Expand Down
34 changes: 10 additions & 24 deletions src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,25 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar

private PropertyInfoExtractorInterface $propertyInfo;
private ?ClassMetadataFactoryInterface $classMetadataFactory;
/** @var PropertyDescriberInterface|PropertyDescriberInterface[] */
private $propertyDescriber;
private PropertyDescriberInterface $propertyDescriber;
/** @var string[] */
private array $mediaTypes;
/** @var (NameConverterInterface&AdvancedNameConverterInterface)|null */
private ?NameConverterInterface $nameConverter;
private bool $useValidationGroups;

/**
* @param PropertyDescriberInterface|PropertyDescriberInterface[] $propertyDescribers
* @param (NameConverterInterface&AdvancedNameConverterInterface)|null $nameConverter
* @param string[] $mediaTypes
*/
public function __construct(
PropertyInfoExtractorInterface $propertyInfo,
$propertyDescribers,
PropertyDescriberInterface $propertyDescribers,
array $mediaTypes,
?NameConverterInterface $nameConverter = null,
bool $useValidationGroups = false,
?ClassMetadataFactoryInterface $classMetadataFactory = null
) {
if (is_iterable($propertyDescribers)) {
trigger_deprecation('nelmio/api-doc-bundle', '4.17', 'Passing an array of PropertyDescriberInterface to %s() is deprecated. Pass a single PropertyDescriberInterface instead.', __METHOD__);
} else {
if (!$propertyDescribers instanceof PropertyDescriberInterface) {
throw new \InvalidArgumentException(sprintf('Argument 3 passed to %s() must be an array of %s or a single %s.', __METHOD__, PropertyDescriberInterface::class, PropertyDescriberInterface::class));
}
}

$this->propertyInfo = $propertyInfo;
$this->propertyDescriber = $propertyDescribers;
$this->mediaTypes = $mediaTypes;
Expand Down Expand Up @@ -151,7 +141,7 @@ public function describe(Model $model, OA\Schema $schema)
throw new \LogicException(sprintf('The PropertyInfo component was not able to guess the type of %s::$%s. You may need to add a `@var` annotation or use `#[OA\Property(type="")]` to make its type explicit.', $class, $propertyName));
}

$this->describeProperty($types, $model, $property, $propertyName, $schema);
$this->describeProperty($types, $model, $property, $propertyName);
}

$this->markRequiredProperties($schema);
Expand Down Expand Up @@ -188,19 +178,15 @@ private function camelize(string $string): string
/**
* @param Type[] $types
*/
private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName, OA\Schema $schema): void
private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName): void
{
$propertyDescribers = is_iterable($this->propertyDescriber) ? $this->propertyDescriber : [$this->propertyDescriber];

foreach ($propertyDescribers as $propertyDescriber) {
if ($propertyDescriber instanceof ModelRegistryAwareInterface) {
$propertyDescriber->setModelRegistry($this->modelRegistry);
}
if ($propertyDescriber->supports($types)) {
$propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext());
if ($this->propertyDescriber instanceof ModelRegistryAwareInterface) {
$this->propertyDescriber->setModelRegistry($this->modelRegistry);
}
if ($this->propertyDescriber->supports($types, $model->getSerializationContext())) {
$this->propertyDescriber->describe($types, $property, $model->getSerializationContext());

return;
}
return;
}

throw new \Exception(sprintf('Type "%s" is not supported in %s::$%s. You may use the `#[OA\Property(type="")]` annotation to specify it manually.', $types[0]->getBuiltinType(), $model->getType()->getClassName(), $propertyName));
Expand Down
26 changes: 4 additions & 22 deletions src/PropertyDescriber/ArrayPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,24 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'array';
/** @var OA\Items $property */
$property = Util::getChild($property, OA\Items::class);

foreach ($types[0]->getCollectionValueTypes() as $type) {
// Handle list pseudo type
// https://symfony.com/doc/current/components/property_info.html#type-getcollectionkeytypes-type-getcollectionvaluetypes
if ($this->supports([$type]) && [] === $type->getCollectionValueTypes()) {
if ($this->supports([$type], $context) && [] === $type->getCollectionValueTypes()) {
continue;
}

$this->propertyDescriber->describe([$type], $property, $groups, $schema, $context);
$this->propertyDescriber->describe([$type], $property, $context);
}
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
if (1 !== count($types) || !$types[0]->isCollection()) {
return false;
Expand Down
22 changes: 2 additions & 20 deletions src/PropertyDescriber/BooleanPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,12 @@ class BooleanPropertyDescriber implements PropertyDescriberInterface
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'boolean';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_BOOL === $types[0]->getBuiltinType();
}
Expand Down
Loading

0 comments on commit abd21f3

Please sign in to comment.