Nelmio Apidocbundle。映射超类的属性

时间:2014-10-23 08:36:21

标签: symfony doctrine jmsserializerbundle

我有一个从实体B扩展的实体A.实体B是@ORM \ MappedSuperclass。 在我的控制器中,我有以下apidoc注释:

/**
 * Gets a A by its identifier
 *
 * @ApiDoc(
 *  resource=true,
 *  description="Gets a A by its identifier",
 *  tags={"stable"},
 *  https=true,
 *  output="Vendor\Bundle\VendorBundle\Entity\A",
 *  statusCodes={
 *      200="Returned when successful.",
 *      404="Returned when A with given identifier does not exist."
 *  }
 *
 * )
 *
 *
 * @param string $identifier The A's identifier
 * @throws \Vendor\Exception\ANotFoundException
 * @return JsonResponse
 *
 * @Route("/a/{identifier}")
 * @Method({"GET"})
 */

GET方法的结果apidoc返回部分将具有来自实体A的所有属性,但没有来自映射的超类实体B的所有属性。

有没有办法同时包含映射超类的属性?

提前致谢。

1 个答案:

答案 0 :(得分:0)

好的,没关系。我找到了解决方案。 nelmio / api-doc-bundle要求映射的超类在其属性上具有验证约束注释。

这不起作用:

use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Util\Inflector;
use Symfony\Component\HttpFoundation\Request;

/**
 * @ORM\MappedSuperclass
 * @ORM\HasLifecycleCallbacks
 */
class BaseEntity
{
    /**
     * @ORM\Column(name="id", type="integer", nullable=false, options={"unsigned"=true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

这将工作:

use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Util\Inflector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\MappedSuperclass
 * @ORM\HasLifecycleCallbacks
 */
class BaseEntity
{
    /**
     * @ORM\Column(name="id", type="integer", nullable=false, options={"unsigned"=true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @Assert\NotBlank()
     */
    protected $id;