symfonydoctrine-ormapi-platform.comentities

Symfony doctrine reverse engineering and Apiplatform


Is there a way to create Apiplatform enabled entities directly from database schemas?

I successfully create the entities using php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity , but now i have to add manually the reference to Apiplatform resources in 120 entities like here. Is there another way? Thanks in advance.


Solution

  • This feature isn’t supported out of the box (but it would be nice to add it). There is an open issue to add this feature to MakerBundle, but this hasn’t been implemented at time of writing.

    However, you can easily achieve the same effect by using the "search and replace" feature of your IDE or by using sed: find every occurrences of @ORM\Entity and replace them with:

    @ORM\Entity
    @\ApiPlatform\Core\Annotation\ApiResource
    

    You may want to run PHP CS Fixer after that to change the fully qualified class name by a use statement.