I just upgraded API platform to version 3.0.
After the few classical modifications linked to the version upgrade, and despite the use of: php bin/console api:upgrade-resource
I notice that my entities are not exposed anymore when I go to the API documentation and if I try to access an endpoint, I get a route error: No route found for "GET https://127.0.0.1:9000/api/XXX
I replaced all the ApiResource uses in my entities and rewrote my annotations.
example of an entity:
<?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
{
....
}
Thanks in advance!
ok so, i update a little entity manually and now she is exposed !
<?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;
i didn't see the results of the upgrade command, which ended up being an error and therefore did nothing. in fact, it does not seem to exist
Command "api:upgrade-resource" is not defined.
anyone would know why ?
CodePudding user response:
It looks like your entities are still in the <= v2.6 format despite your call to the api:upgrade-resource
command.
See the migration documentation: instead of
'get'
, 'post'
, etc. you should use new Metadata classes Get()
, Post()
, etc.
Are you sure that the migration command returned no error? In my case (migration from 2.6 to 3.0) the migration command was not available for unknwon reason (not found from the console).
Try migrating manually one entity to the new format and watch your openApi documentation to see if your endpoints are back.
Edit: Why didn't api:upgrade-resource
work ?
As far as I understand, the migration command is provided in v2.7 to prepare migration to 3.0 but has been dropped from v3.0. So the proper way to migrate according to the doc is:
- migrate to 2.7
- call
api:upgrade-resource
and check all is working - THEN migrate to 3.0
CodePudding user response:
like @MendelYev says i should run the api upgrade command before upgrade. now i ve to upgrade manually my entities using PHP attributes and new Metadata classes from Doctrine