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

Subresource uri with custom identifier

我有一个 Custom Identifier and a Subresource 的实体。

虽然 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;
}

为什么我的自定义标识符不适用于子资源?

虽然我觉得不太可能,但事实证明这是一个错误: