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



我有一个带有自定义标识符和子资源的实体。

虽然组织实体工作正常(/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.此行为未记录在案。

use ApiPlatformCoreAnnotation as Api;
class Organisation
{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*
* @ApiApiProperty(identifier=false)
*/
protected ?int $id = null;
/**
* @ORMColumn(type="text", nullable=true)
*
* @ApiApiProperty(identifier=true, description="Code")
*/
protected ?string $code = null;
/**
* @var Collection|User[]
*
* @ORMOneToMany(targetEntity="User", mappedBy="organisation")
*
* @ApiApiSubresource(maxDepth=1)
*/
protected $users;
}

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

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

  • https://github.com/api-platform/core/issues/3585
  • https://github.com/api-platform/api-platform/issues/1542

最新更新