2 回答

TA贡献1842条经验 获得超22个赞
在 api/config/packages/api_platform.yaml 通常有以下配置:
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
如果 aip 确实找到了您的资源,它可能是这样的:
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/ApiPlatform']
但是为了找到您的实体及其映射,它应该是这样的:
api_platform:
mapping:
paths:
- '%kernel.project_dir%/src/Entity'
- '%kernel.project_dir%/src/Resources/config/doctrine'
- '%kernel.project_dir%/src/ApiPlatform'
教义查找映射的实际文件夹可能不同,请查看 api/config/packages/doctrine.yaml 或配置教义的任何位置。

TA贡献1848条经验 获得超2个赞
首先,您的 Example 类缺少该$name属性。在 $uuid 之后添加private $name;,除非 EntityExample 具有该受保护/公共属性。
您的 ApiResource() 注释类似乎对任何属性都没有序列化组注释。 https://api-platform.com/docs/core/serialization/
<?php
declare(strict_types=1);
namespace ApiPlatform;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Entity\Example as EntityExample;
use Ramsey\Uuid\UuidInterface;
/**
* @ApiResource(
* normalizationContext={"groups"={"read"}},
* denormalizationContext={"groups"={"write"}}
* )
*/
class Example extends EntityExample
{
/**
* @ApiProperty(identifier=true)
* @var UuidInterface
*/
protected $uuid;
/**
* @Groups({"read", "write"})
*/
private $name;
/**
* @return UuidInterface
*/
public function getUuid() : UuidInterface
{
return $this->uuid;
}
/**
* @return string
* @Groups({"read", "write"})
*/
public function getName() : string
{
return $this->name;
}
/**
* @param UuidInterface $uuid
*/
public function setUuid(UuidInterface $uuid) : void
{
$this->uuid = $uuid;
}
/**
* @param string $name
*/
public function setName(string $name) : void
{
$this->name = $name;
}
}
如果您不想使用序列化组,请使用@ApiResource(ie and not ApiResource()) 注释实体。
- 2 回答
- 0 关注
- 164 浏览
添加回答
举报