I just change all api annotations in my project to new format.
From
namespace App\Document\Account;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\SearchFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Document\Company\Brand;
use App\Document\Company\Company;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Description of Account.
*
* @MongoDB\Document()
* @ApiResource(
* collectionOperations={
* "get"={
* "method"="GET",
* "path"="/accounts",
* "access_control"="is_granted('ROLE_USER')",
* },
* },
* itemOperations={
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* }
* },
* attributes={
* "normalization_context"={"groups"={"account","account-read"}},
* "denormalization_context"={"groups"={"account", "account-write"}},
* "pagination_enabled"=false
* }
* )
*/
class Account
{
/**
* @MongoDB\Id
* @Groups({"account"})
* @ApiProperty(identifier=true)
*/
private $id;
/**
* @var string
* @MongoDB\Field(type="string")
* @Groups({"account"})
*/
private $accountNumber;
/**
* @var string
* @MongoDB\Field(type="string")
* @Groups({"account"})
*/
private $accountLabel;
/**
* @var ArrayCollection;
* @MongoDB\EmbedMany(targetDocument=Company::class)
* @Groups({"account"})
* @ApiFilter(SearchFilter::class, properties={"companies.companyID": "exact"})
*/
private $companies;
/**
* @var ArrayCollection;
* @MongoDB\EmbedMany(targetDocument=Brand::class)
* @Groups({"account"})
* @ApiFilter(SearchFilter::class, properties={"brands.brandID": "exact"})
*/
private $brands;
public function __construct()
{
$this->companies = new ArrayCollection();
$this->brands = new ArrayCollection();
}
.....
To :
namespace App\Document\Account;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Odm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use App\Document\Company\Brand;
use App\Document\Company\Company;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use phpDocumentor\Reflection\DocBlock\Tags\Property;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Description of Account.
*
* @MongoDB\Document ()
*/
#[ApiResource(
operations: [
new Get(security: 'is_granted(\'ROLE_USER\')'),
new GetCollection(uriTemplate: '/accounts', security: 'is_granted(\'ROLE_USER\')')
],
normalizationContext: ['groups' => ['account', 'account-read']],
denormalizationContext: ['groups' => ['account', 'account-write']]
)]
class Account
{
/**
* @var string
* @MongoDB\Id
* @Groups ({"account"})
*/
#[ApiProperty(identifier: true)]
private $id;
/**
* @var string
* @MongoDB\Field (type="string")
* @Groups ({"account"})
*/
#[ApiFilter(filterClass: SearchFilter::class, properties: ['accountNumber' => 'exact'])]
private $accountNumber;
/**
* @var string
* @MongoDB\Field (type="string")
* @Groups ({"account"})
*/
#[ApiFilter(filterClass: SearchFilter::class, properties: ['accountLabel' => 'partial'])]
private $accountLabel;
/**
* @var ArrayCollection;
* @MongoDB\EmbedMany (targetDocument=Company::class)
* @Groups ({"account"})
*/
#[ApiFilter(filterClass: SearchFilter::class, properties: ['companies.companyID' => 'exact'])]
private $companies;
/**
* @var ArrayCollection;
* @MongoDB\EmbedMany (targetDocument=Brand::class)
* @Groups ({"account"})
*/
#[ApiFilter(filterClass: SearchFilter::class, properties: ['brands.brandID' => 'exact'])]
private $brands;
public function __construct()
{
$this->companies = new ArrayCollection();
$this->brands = new ArrayCollection();
}
.....
I have a deprecation error when I call this nested mongodb document attributes Brands and Companies ArrayCollection with api platform route get : api/accounts.
[2022-11-28T10:45:50.037531+00:00] deprecation.INFO: User Deprecated: Since api-platform/core 2.7: An anonymous resource will use a Skolem IRI in API Platform 3.0. Use #[ApiProperty(genId: false)] to keep this behavior in 3.0. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Since api-platform/core 2.7: An anonymous resource will use a Skolem IRI in API Platform 3.0. Use #[ApiProperty(genId: false)] to keep this behavior in 3.0. at /var/www/app/vendor/api-platform/core/src/JsonLd/ContextBuilder.php:207)"} []
If I get 50 results it will appear 50 times in log file
1 - First i tried to comment arraycollection calls in class (Brands an Companies) the the error does not appear anymore. So i'm sure it's because Brands and Companies are not api Ressource but Nested Document (anonymous).
2 - I tried like they say to put the annotation
#[ApiProperty(genId: false)]
On $companies and $brands
then clear cache
It doensn't fix the problem.
Has anyone had the same problem updating the format of the api-platform annotations?