-
-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b69f62
commit 6417521
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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\TypeDescriber; | ||
|
||
use OpenApi\Annotations\Schema; | ||
use Symfony\Component\TypeInfo\Type; | ||
use Symfony\Component\TypeInfo\Type\CollectionType; | ||
use Symfony\Component\TypeInfo\TypeFactoryTrait; | ||
|
||
/** | ||
* @implements TypeDescriberInterface<CollectionType> | ||
* | ||
* @experimental | ||
* | ||
* @internal | ||
*/ | ||
final class ArrayDescriber implements TypeDescriberInterface, TypeDescriberAwareInterface | ||
{ | ||
use TypeDescriberAwareTrait; | ||
|
||
public function describe(Type $type, Schema $schema, array $context = []): void | ||
{ | ||
if (!$type->getCollectionKeyType() instanceof Type\CompositeTypeInterface) { | ||
return; | ||
} | ||
|
||
$collections = array_map( | ||
fn (Type $keyType): CollectionType => TypeFactoryTrait::collection($type->getWrappedType(), $type->getCollectionValueType(), $keyType), | ||
Check failure on line 37 in src/TypeDescriber/ArrayDescriber.php GitHub Actions / PHPStan
|
||
$type->getCollectionKeyType()->getTypes(), | ||
); | ||
|
||
if ($type->getCollectionKeyType() instanceof Type\UnionType) { | ||
$describeType = Type::union(...$collections); | ||
} | ||
|
||
if ($type->getCollectionKeyType() instanceof Type\IntersectionType) { | ||
$describeType = Type::intersection(...$collections); | ||
} | ||
|
||
if (!isset($describeType)) { | ||
return; | ||
} | ||
|
||
$this->describer->describe($describeType, $schema, $context); | ||
} | ||
|
||
public function supports(Type $type, array $context = []): bool | ||
{ | ||
return $type instanceof CollectionType | ||
&& $type->getCollectionKeyType() instanceof Type\CompositeTypeInterface; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters