The ObjectModelDescriber can support interfaces

This commit is contained in:
Baptiste Lafontaine 2022-07-18 17:02:33 +02:00
parent 1cf58fbae0
commit 9050994bd4
3 changed files with 28 additions and 1 deletions

View File

@ -215,6 +215,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
public function supports(Model $model): bool
{
return Type::BUILTIN_TYPE_OBJECT === $model->getType()->getBuiltinType() && class_exists($model->getType()->getClassName());
return Type::BUILTIN_TYPE_OBJECT === $model->getType()->getBuiltinType()
&& (class_exists($model->getType()->getClassName()) || interface_exists($model->getType()->getClassName()));
}
}

View File

@ -11,6 +11,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;
use Functional\Entity\ArticleInterface;
use Nelmio\ApiDocBundle\Annotation\Areas;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Operation;
@ -51,6 +52,23 @@ class ApiController80
{
}
/**
* @OA\Get(
* @OA\Response(
* response="200",
* description="Success",
* @Model(type=ArticleInterface::class, groups={"light"}))
* )
* )
* @OA\Parameter(ref="#/components/parameters/test")
* @Route("/article-interface/{id}", methods={"GET"})
* @OA\Parameter(name="Accept-Version", in="header", @OA\Schema(type="string"))
* @OA\Parameter(name="Application-Name", in="header", @OA\Schema(type="string"))
*/
public function fetchArticleInterfaceAction()
{
}
/**
* The method LINK is not supported by OpenAPI so the method will be ignored.
*

View File

@ -0,0 +1,8 @@
<?php
namespace Functional\Entity;
interface ArticleInterface
{
public function getAuthor(): string;
}