基于DTO创建了一个非常简单的资源。所有逻辑都将通过自定义
DataProvider
,对于该项目,不使用注释。
资源的配置为:
<resources xmlns="https://api-platform.com/schema/metadata">
<resource class="App\Domain\Dto\ProductUpgradePrice">
<collectionOperations>
<collectionOperation name="get"/>
</collectionOperations>
<itemOperations>
<itemOperation name="get"/>
</itemOperations>
</resource>
</resources>
实际的DTO是:
<?php declare(strict_types=1);
namespace App\Domain\Dto;
/** @psalm-immutable */
class ProductUpgradePrice
{
public function __construct(
public string $productId,
public int $regularPrice,
public int $upgradePrice
) {}
}
当我试图
GET /api/product_upgrade_prices
我得到:
没有为App\Domain\Dto\ProductUpgradePrice类型的资源定义标识符
这是有道理的。
这个
docs
提到使用注释
@ApiProperty
,但正如我前面提到的,这个项目没有注释。
(我向
update
自从我发布这个问题以来,这些文档被合并了,所以希望未来的用户不会遇到同样的情况。)
我已尝试将此添加到资源配置中:
<property name="productId">
<attribute name="identifier">true</attribute>
</property>
但是得到了同样的结果。
我如何在不使用注释的情况下进行配置?