NelmioApiDocBundle icon indicating copy to clipboard operation
NelmioApiDocBundle copied to clipboard

Symfony's UserInterface roles variable

Open Terroraapje opened this issue 7 years ago • 2 comments

Hello,

I'm getting the following exception: Property \"GamePoint\\Entity\\User\\Player:roles\" is an array, but no indication of the array elements are made. Use e.g. string[] for an array of string.

I have a User class with implements Symfony's UserInterface (Symfony\Component\Security\Core\User\UserInterface).

Player extends User.

class User implements UserInterface
{
    const ROLE_ADMIN = 'ROLE_ADMIN';
    const ROLE_SUPERADMIN = 'ROLE_SUPERADMIN';
    const ROLE_TESTER = 'ROLE_TESTER';
    /**
     * @ORM\Column(type="string", length=255, unique=true)
     * @SWG\Property(description="Name used ingame of the User")
     */
    private $username;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @SWG\Property(description="Encrypted password of the User")
     */
    private $password;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @SWG\Property(description="Emailaddress of the User")
     */
    private $email;

    /**
     * @ORM\Column(type="integer", nullable=true)
     * @SWG\Property(description="Status of the User")
     */
    private $status;

    /**
     * @SWG\Property(type="array", @SWG\Items(type="string"))
     * @ORM\Column(type="array", nullable=true)
     */
    private $roles;
}
class Player extends User
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @SWG\Property(description="ID of the Player")
     */
    private $id;
}

The really weird part is, is when I move the complete $roles section (getters, setters, has ....) to Player, everything works fine.

What am I doing wrong here? And how to fix?

Thing I have tried:

  • add @var string[] and remove Swagger Annotation

Terroraapje avatar Feb 27 '19 13:02 Terroraapje

The issue is that property_exists returns false for private parent properties (in https://github.com/nelmio/NelmioApiDocBundle/blob/master/ModelDescriber/ObjectModelDescriber.php#L61), I'm not sure how to fix that properly...

Meanwhile, you can use @SWG\Definition and define your type there.

GuilhemN avatar Mar 06 '19 20:03 GuilhemN

Related: https://github.com/nelmio/NelmioApiDocBundle/issues/1432

chrisguitarguy avatar Mar 28 '22 13:03 chrisguitarguy