带有自定义标识符的子资源uri

问题描述 投票:1回答:1

我有一个带有Custom IdentifierSubresource的实体。

虽然Organization实体工作正常(/api/organisation/ABC),所以应该具有类似于/api/organisation/ABC/users的端点。

但是不。子资源的uri为/api/organisation/1/users。这是输出:

{
  "@context": "/api/contexts/Organisation",
  "@id": "/api/organisations/1/users", <-- $id used as identifier
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/api/users/1",
      "@type": "User",
      "organisation": {
        "@id": "/api/organisations/ABC",  <-- $code used as identifier
        "@type": "Organisation",
        "id": 701,
        "code": "VB",
        "createdAt": "2019-11-08T08:38:18+01:00",
        "updatedAt": "2019-11-08T08:38:52+01:00"
      },
    }
  ]
}

我正在使用api-platform/api-pack v1.2.2api-platform/core v2.5.5。此行为isn't documented

use ApiPlatform\Core\Annotation as Api;

class Organisation
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @Api\ApiProperty(identifier=false)
     */
    protected ?int $id = null;

    /**
     * @ORM\Column(type="text", nullable=true)
     *
     * @Api\ApiProperty(identifier=true, description="Code")
     */
    protected ?string $code = null;

    /**
     * @var Collection|User[]
     *
     * @ORM\OneToMany(targetEntity="User", mappedBy="organisation")
     *
     * @Api\ApiSubresource(maxDepth=1)
     */
    protected $users;
}

为什么我的自定义标识符在子资源上不起作用?

symfony api-platform.com
1个回答
0
投票

虽然对我来说似乎不太可能,但事实证明是个错误:

© www.soinside.com 2019 - 2024. All rights reserved.