This morning, I started a new project with API Platform v2.4, and almost from scratch, I had to clear the cache to get my API documentation updated.
Create a new Symfony application api-platform-issue symfony new --full api-platform-issue.
Go to this new project (cd api-platform-issue).
Install API platform by using composer req api.
Install embedded web server composer req server and start it bin/console server:run.
Open API doc: http://localhost:8000/api
Create an entity Pizza:
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
/**
* @ApiResource
* @ORM\Entity
*/
class Pizza
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @var int
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}
Refresh your API doc, you don't see any change.
Delete your cache (rm -rf var/cache).
API is updated.
If you delete the annotation and update cache, you'll see no change.
Bug reproduced:
Probably related to https://github.com/api-platform/core/pull/2629... @teohhanhui can you take a look? Maybe should we revert this patch until it is properly tested and "edge cases" (this one is a basic case) are handled properly.
This is even more related to #2593 and it's not easy to take a decision that will not have an impact.
I prefer to favor DX than performance in dev env.
~Symfony uses cache in dev environment out of the box. We should do the same. If we require more manual cache:clear, then that's something we should fix.~
Okay, I was mistaken. Symfony does not use cache in dev environment out of the box:
Validator: https://github.com/symfony/symfony/blob/v4.2.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1134-L1136
Serializer: https://github.com/symfony/symfony/blob/v4.2.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1376-L1388
PropertyAccess: https://github.com/symfony/symfony/blob/v4.2.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1680-L1688
So @dunglas is right, we have to revert.
So we are back at square 1 with a lot of things to improve performance as it's so poor right now it's a also DX problem.
@bastnic Unfortunately, yeah...
About this case you can still use metadata_cache=true in your configuration but yeah...
@bastnic in the meantime you can set api_platform.metadata_cache to true if you don't mind running cache:clear manually. But I'm sure there are rooms for improvements that doesn't hurt DX.
If I remember correctly, the main issues are:
I'll look into it.
Closing as it's been reverted in #2648, but I'll look into https://github.com/api-platform/core/issues/2644#issuecomment-476205943