1

我创建了一个用于测试目的的 symfony 应用程序并导入了 NelmioApiDoc 包。

我尝试实现与 Symfony 在其文档https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html中演示的几乎相同的逻辑和结构。

但是,当我尝试在 http://localhost/api/docs 访问 Swagger UI 时,Symfony 报告错误:... a Describer doesn't exist for type Reward ...

问题在于:@SWG\Items(ref=@Model(type=Reward::class, groups={"full"}))

该文档对初学者不太友好。你能告诉我我错过了什么吗?

namespace AppBundle\Controller;

use AppBundle\Entity\User;
use AppBundle\Entity\Reward;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\Routing\Annotation\Route;

class UserController
{
    /**
     * List the rewards of the specified user.
     *
     * This call takes into account all confirmed awards, but not pending or refused awards.
     *
     * @Route("/api/{user}/rewards", methods={"GET"})
     * @SWG\Response(
     *     response=200,
     *     description="Returns the rewards of an user",
     *     @SWG\Schema(
     *         type="array",
     *         @SWG\Items(ref=@Model(type=Reward::class, groups={"full"}))
     *     )
     * )
     * @SWG\Parameter(
     *     name="order",
     *     in="query",
     *     type="string",
     *     description="The field used to order rewards"
     * )
     * @SWG\Tag(name="rewards")
     * @Security(name="Bearer")
     */
    public function fetchUserRewardsAction(User $user)
    {
        // ...
    }
}
4

0 回答 0