1

I created a symfony app for testing purposes and imported the NelmioApiDoc bundle.

I tried implementing almost identical logic and structure as Symfony demonstrates in their documentation here https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html.

However when I try to access the Swagger UI at http://localhost/api/docs Symfony reports an error: ... a Describer doesn't exist for type Reward ...

The problem is in the line: @SWG\Items(ref=@Model(type=Reward::class, groups={"full"})).

The documentation is not very beginner-friendly. Can you tell me what am I missing?

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)
    {
        // ...
    }
}
yukitmp
  • 15
  • 3

1 Answers1

0

So, I had the same problem, didnt figure out how to get the kind of

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

working.

What worked for me is using the path to the file, where the class is defined. Like

@OA\Response(response = 200, description="Return an Address",@OA\JsonContent(ref=@Model(type="App\Entity\CcAddresses")))

Note this is using the OpenApi lib instead of Swagger.