nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.22k stars 833 forks source link

Symfony's UserInterface roles variable #1478

Open Terroraapje opened 5 years ago

Terroraapje commented 5 years ago

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:

GuilhemN commented 5 years ago

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.

chrisguitarguy commented 2 years ago

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