mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
d932b06bbb
* Add support for compound properties * Fix CS & Tests * Another fixing :D * Final CS fix * Allow complex compound properties * cs * Update the Upgrading guide * Update php doc * Add Support for Nullable properties * Fix CS * Fix CS * Add Support for Nullable Types & Schemas as in OA3 * Update Nullable Property handling * CS * Fix tests * Accept also nullable config for Alternative model names * Refactor nullable refs * Fix CS & Tests * Another CS * Revert "Another CS" This reverts commit 03ada32b3263f3537d2af63f0abe79bd4a9ac0b5. * Revert "Fix CS & Tests" This reverts commit 369f2ccd170aebeeb9d87e9e00cba5cea62d5529. * Revert "Refactor nullable refs" This reverts commit 91cdf6fd0130f3ebf415de99f8a91edbc764255e. * Revert "Revert "Refactor nullable refs"" This reverts commit 0e50fc1938ce3e620fc655a7d1e9284a9f8c24f0. * Revert "Revert "Fix CS & Tests"" This reverts commit 228d3ca994eb4622c4db81aaa5f32845862e5616. * Revert "Revert "Another CS"" This reverts commit a5b08dedf5bca8fb711b816c62bed2de9f1c9521. * Improve nullable refs description Co-authored-by: Filip Benčo <filip.benco@websupport.sk> Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com>
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?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;
|
|
|
|
class CompoundPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
|
|
{
|
|
use ModelRegistryAwareTrait;
|
|
|
|
/** @var PropertyDescriberInterface[] */
|
|
private $propertyDescribers;
|
|
|
|
public function __construct(iterable $propertyDescribers)
|
|
{
|
|
$this->propertyDescribers = $propertyDescribers;
|
|
}
|
|
|
|
public function describe(array $types, OA\Schema $property, array $groups = null)
|
|
{
|
|
$property->oneOf = OA\UNDEFINED !== $property->oneOf ? $property->oneOf : [];
|
|
|
|
foreach ($types as $type) {
|
|
$property->oneOf[] = $schema = Util::createChild($property, OA\Schema::class, []);
|
|
foreach ($this->propertyDescribers as $propertyDescriber) {
|
|
if ($propertyDescriber instanceof ModelRegistryAwareInterface) {
|
|
$propertyDescriber->setModelRegistry($this->modelRegistry);
|
|
}
|
|
if ($propertyDescriber->supports([$type])) {
|
|
$propertyDescriber->describe([$type], $schema, $groups);
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function supports(array $types): bool
|
|
{
|
|
return count($types) >= 2;
|
|
}
|
|
}
|