Skip to content

Commit

Permalink
chore: 5.x update type from ObjectModelDescriber
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Nov 12, 2024
1 parent c042693 commit 6db970a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
4 changes: 3 additions & 1 deletion UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ This parameter was deprecated since `4.25.2`

## 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: Removed `Nelmio\ApiDocBundle\Exception\UndocumentedArrayItemsException`

## BC BREAK: Changed type of parameter `$propertyDescriber` in `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()` from `PropertyDescriberInterface|PropertyDescriberInterface[]` to `PropertyDescriberInterface`
30 changes: 8 additions & 22 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 @@ -190,17 +180,13 @@ private function camelize(string $string): string
*/
private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName, OA\Schema $schema): 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)) {
$this->propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext());

Check failure on line 187 in src/ModelDescriber/ObjectModelDescriber.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Nelmio\ApiDocBundle\PropertyDescriber\PropertyDescriberInterface::describe() invoked with 5 parameters, 2-3 required.

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

0 comments on commit 6db970a

Please sign in to comment.