Search code examples
api-platform.com

How to configure the ApiResource annotation


I have added this annotation to one of my entities as I see in the last version of the docs with annotations instead of attributes (https://api-platform.com/docs/v2.5/core/serialization/):

 * @ApiResource(attributes={
 *     "normalization_context"={"enable_max_depth"=true}}
 * )

And I get this error:

An error occurred while instantiating the annotation @ApiResource declared on class App\Entity\Client: "Argument 1 passed to ApiPlatform\Metadata\ApiResource::__construct() must be of the type string or null, array given

I'm using API Platform 2.7 because I'm still on PHP 7.4.

Any suggestions?


Solution

  • Never mind... I had imported \ApiPlatform\Metadata\ApiResource instead of \ApiPlatform\Core\Annotation\ApiResource. 😞