Skip to content

@Groups and @ApiProperty annotations not inherited from parent classes and/or traits #3184

@lopezio

Description

@lopezio

API Platform version(s) affected: 2.5.0

Description
Inheritance of Serializer @groups or @ApiProperty items seems not to be honoured when extending classes or adding Traits to a class.

How to reproduce
Example class:

/**
 * @ORM\MappedSuperclass()
 * @ORM\HasLifecycleCallbacks()
 */
abstract class BaseEntity
{
    /**
     * @ApiProperty()
     * @ORM\Column(type="datetime")
     * @Groups({"base:internal"})
     */
    private $created;

    /**
     * @ApiProperty()
     * @ORM\Column(type="datetime")
     * @Groups({"base:internal"})
     */
    private $modified;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
     * @Groups({"base:internal"})
     */
    private $creator;
    ...
}

Classes extending this one have correct fields in Doctrine, but the ApiPlatform Groups and other annotations in ApiProperty are not honored.
The same happens if I add properties and getters/setters via a a corresponding Trait, e.g.

/**
 * Trait TimeStampedEntityTrait
 * @package App\Entity
 */
trait TimeStampedEntityTrait
{
    /**
     * @ORM\Column(type="datetime")
     * @Groups({"base:internal"})
     */
    private $created;

    /**
     * @ApiProperty()
     * @ORM\Column(type="datetime")
     * @Groups({"base:internal"})
     */
    private $modified;
    ...
}

I would expect the annotations to be carried on into all children.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions