Skip to content

api:upgrade-resource removes every filters but the last one in each resource file #4966

@emmanuelballery

Description

@emmanuelballery

API Platform version(s) affected: 2.7.0

Description

Hi! I was expecting to upgrade a project to ApiPlatform 3. I just launched the api:upgrade-resource in it and saw in my git diff that every filters but the last ones were removed from my resources. It actually removed 200 ApiFilter attributes in my case ...

How to reproduce

symfony new bookshop-api
cd bookshop-api
composer require api-platform/core "^2"
composer require doctrine

Create this entity in src/Entity/:

<?php declare(strict_types=1);

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;

#[Entity]
#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['name'])]
#[ApiFilter(NumericFilter::class, properties: ['count'])]
class Test
{
    #[Column]
    #[GeneratedValue]
    #[Id]
    public ?int $id = null;

    #[Column]
    public ?string $name = null;

    #[Column]
    public int $count = 0;
}

You'll have to install phpunit because this package is missing nikic/php-parser dependency.

composer require test
php bin/console api:up

The SearchFilter disappeared.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions