我刚刚将API平台升级到3.0版。经过几次经典修改链接到版本升级后,尽管使用了:php bin/console api:upgrade-resource
我注意到当我访问API文档时,我的实体不再公开,如果我试图访问一个端点,我会得到一个路由错误:找不到用于"GET https://127.0.0.1:9000/api/XXX“的路由。
我替换了实体中的所有ApiResource用法,并重写了我的注释。
实体实例:
<?php
namespace App\Entity\Test;
use ApiPlatform\Metadata\ApiResource;
#[ApiResource(
collectionOperations: [
'get',
'post' => [
'denormalization_context' => ['groups' => ['create:xxx']]
]
],
itemOperations: [
'get' => [
'normalization_context' => ['groups' => ['read:fully:xxx']]
],
'put' => [
'denormalization_context' => ['groups' => ['update:xxx']]
],
'delete'
],
normalizationContext: ['groups' => ['read:xxx']]
)]
class Departement
{
....
}提前感谢!
好的,所以,我手动更新一个小实体,现在她暴露了!
<?php
namespace App\Entity\Agorha;
//use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use App\Entity\ChoixEcole;
use App\Repository\Agorha\EcoleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: EcoleRepository::class)]
#[ORM\Table(name: "agorha_ecole")]
#[ORM\HasLifecycleCallbacks()]
#[ApiResource(operations: [
new Get(),
new GetCollection()
])]
#[
UniqueEntity('code')
]
class Ecole
{
#[ORM\Id()]
#[ORM\GeneratedValue()]
#[ORM\Column(type: "integer")]
private $id;我没有看到升级命令的结果,结果是一个错误,因此什么也没做。事实上,它似乎并不存在。
Command "api:upgrade-resource" is not defined.有人会知道为什么吗?
发布于 2022-10-21 20:09:09
尽管您调用了<=命令,但您的实体似乎仍然采用api:upgrade-resource v2.6格式。
请参阅迁移文件:而不是'get'、'post'等,您应该使用新的元数据类Get()、Post()等等。
您确定迁移命令没有返回错误吗?在我的例子中(从2.6迁移到3.0),由于不起眼的原因(从控制台找不到),迁移命令不可用。
尝试手动将一个实体迁移到新的格式,并查看您的openApi文档,以查看端点是否返回。
编辑:为什么api:upgrade-resource不工作?
据我所知,迁移命令是在v2.7中提供的,用于准备迁移到3.0,但已经从v3.0中删除了。因此,根据文档进行迁移的正确方法是:
api:upgrade-resource,检查一切正常发布于 2022-10-24 11:03:24
就像@MendelYev说的那样,我应该在升级之前运行api升级命令。现在,我将使用PHP属性和Doctrine中的新元数据类手动升级实体。
https://stackoverflow.com/questions/74151427
复制相似问题