-
-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat-2207: Implement property describer for dictionary (#2208)
* feat-2207: Implement property describer for dictionary * feat-2207: style fix * feat-2207: update baseline * fix ci fail on php 7.2 * style fix * fix baseline merge * update changelog for 4.20.0
- Loading branch information
1 parent
2b5d3bd
commit 61c08f1
Showing
9 changed files
with
234 additions
and
2 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
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,42 @@ | ||
<?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\PropertyDescriber; | ||
|
||
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; | ||
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait; | ||
use Nelmio\ApiDocBundle\OpenApiPhp\Util; | ||
use OpenApi\Annotations as OA; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
final class DictionaryPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface, PropertyDescriberAwareInterface | ||
{ | ||
use ModelRegistryAwareTrait; | ||
use PropertyDescriberAwareTrait; | ||
|
||
public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) | ||
{ | ||
$property->type = 'object'; | ||
/** @var OA\AdditionalProperties $additionalProperties */ | ||
$additionalProperties = Util::getChild($property, OA\AdditionalProperties::class); | ||
|
||
$this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $groups, $schema, $context); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public function supports(array $types): bool | ||
{ | ||
return 1 === count($types) | ||
&& $types[0]->isCollection() | ||
&& 1 === count($types[0]->getCollectionKeyTypes()) | ||
&& Type::BUILTIN_TYPE_STRING === $types[0]->getCollectionKeyTypes()[0]->getBuiltinType(); | ||
} | ||
} |
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
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity\ArrayItems; | ||
|
||
// PHP 7.2 is not able to guess these types | ||
if (PHP_VERSION_ID < 70300) { | ||
class Dictionary | ||
{ | ||
} | ||
} else { | ||
class Dictionary | ||
{ | ||
/** | ||
* @var array<string, string> | ||
*/ | ||
public $options; | ||
|
||
/** | ||
* @var array<string, string|integer> | ||
*/ | ||
public $compoundOptions; | ||
|
||
/** | ||
* @var array<array<string, string|integer>> | ||
*/ | ||
public $nestedCompoundOptions; | ||
|
||
/** | ||
* @var array<string, Foo> | ||
*/ | ||
public $modelOptions; | ||
|
||
/** | ||
* @var array<int, string> | ||
*/ | ||
public $listOptions; | ||
|
||
/** | ||
* @var array<int, string>|array<string, string> | ||
*/ | ||
public $arrayOrDictOptions; | ||
|
||
/** | ||
* @var array<string, integer> | ||
*/ | ||
public $integerOptions; | ||
} | ||
} |
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