我剛剛將 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.
任何人都會知道為什么?
uj5u.com熱心網友回復:
api:upgrade-resource盡管您呼叫了該命令,但您的物體似乎仍采用 <= v2.6 格式。
請參閱遷移檔案:您應該使用新的元資料類,而不是
'get',等。'post'Get()Post()
您確定遷移命令沒有回傳錯誤嗎?在我的情況下(從 2.6 遷移到 3.0),遷移命令由于未知原因(未從控制臺找到)不可用。
嘗試手動將一個物體遷移到新格式并查看您的 openApi 檔案以查看您的端點是否已恢復。
編輯:為什么沒有api:upgrade-resource作業?
據我了解,v2.7 中提供了遷移命令以準備遷移到 3.0,但已從 v3.0 中洗掉。因此,根據檔案進行遷移的正確方法是:
- 遷移到 2.7
- 打電話
api:upgrade-resource檢查一切正常 - 然后遷移到 3.0
uj5u.com熱心網友回復:
就像@MendelYev 說我應該在升級之前運行 api upgrade 命令。現在我已經使用 PHP 屬性和 Doctrine 中的新元資料類手動升級我的物體
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/525529.html
