Skip to content

Commit

Permalink
re-add manually iterating over describers
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Jan 2, 2024
1 parent f3d6af2 commit c07abe0
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Nelmio\ApiDocBundle\Model\Model;
use Nelmio\ApiDocBundle\ModelDescriber\ModelDescriberInterface;
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Annotations as OA;
use OpenApi\Generator;
Expand All @@ -18,6 +19,14 @@ final class SymfonyMapQueryStringDescriber implements InlineParameterDescriberIn
{
use ModelRegistryAwareTrait;

/**
* @param ModelDescriberInterface[] $modelDescribers
*/
public function __construct(
private iterable $modelDescribers
) {
}

public function supports(ArgumentMetadata $argumentMetadata): bool
{
if (!$argumentMetadata->getAttributes(MapQueryString::class, ArgumentMetadata::IS_INSTANCEOF)) {
Expand All @@ -32,12 +41,23 @@ public function describe(OA\OpenApi $api, OA\Operation $operation, ArgumentMetad
$model = new Model(new Type(Type::BUILTIN_TYPE_OBJECT, $argumentMetadata->isNullable(), $argumentMetadata->getType()));

$modelRef = $this->modelRegistry->register($model);
$this->modelRegistry->registerSchemas($model->getHash());

$nativeModelName = str_replace(OA\Components::SCHEMA_REF, '', $modelRef);

$schemaModel = Util::getSchema($api, $nativeModelName);

foreach ($this->modelDescribers as $modelDescriber) {
if ($modelDescriber instanceof ModelRegistryAwareInterface) {
$modelDescriber->setModelRegistry($this->modelRegistry);
}

if ($modelDescriber->supports($model)) {
$modelDescriber->describe($model, $schemaModel);

break;
}
}

// There are no properties to map to query parameters
if (Generator::UNDEFINED === $schemaModel->properties) {
return;
Expand Down

0 comments on commit c07abe0

Please sign in to comment.