Skip to content

Summary of issues with api:upgrade-resource #4973

Description

@usu

API Platform version(s) affected: 3.0.0

Thanks for writing the upgrade-resource console command. I notice a few issues when using it.
Already corrected manually for my code, but fixing this might help others with the transition.

Removes ApiFilter if there is more than one

Edit: duplicate of #4966
Before:

#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['category'])]
#[ApiFilter(CustomFilter::class)]
#[ORM\Entity]
class Books {
}

After:

#[ApiResource]
#[ApiFilter(filterClass: CustomFilter::class)]
#[ORM\Entity]
class Books {
}

Looses reference to self:: variables and inserts the actual content

Before:

#[ApiResource(
    itemOperations: [
        'get' => [
            'normalization_context' => self::ITEM_NORMALIZATION_CONTEXT,
        ],
    ],
    denormalizationContext: ['groups' => ['write']],
    normalizationContext: ['groups' => ['read']],
)]
#[ORM\Entity]
class Category {
    public const ITEM_NORMALIZATION_CONTEXT = [
        'groups' => [
            'read',
            'Category:EmbeddedData',
        ],
    ];
}

After:

#[ApiResource(
    operations: [
        new Get(
            normalizationContext: ['groups' => ['read', 'Category:PreferredContentTypes', 'Category:ContentNodes'], 'swagger_definition_name' => 'read'],
        ),
    ],
    denormalizationContext: ['groups' => ['write']],
    normalizationContext: ['groups' => ['read']]
)]
#[ORM\Entity]
class Category {
    public const ITEM_NORMALIZATION_CONTEXT = [
        'groups' => [
            'read',
            'Category:EmbeddedData',
        ],
    ];
}

General observations

Some other general peculiarities and improvement ideas. Might be difficult to implement, though:

  • The complete ApiResource attribute is printed on a single line. Breaking the line for each operation or even for every property inside an operation would be nice.
  • Order of property attributes is changed. By purpose?
  • Some extra lines in code are removed (within entity logic). Is this coming from a formatter that could optionally be disabled?
  • All extra lines between properties are removed. Is this coming from a formatter that could optionally be disabled?
  • Some other changes that deviate from our code formatting, but they can easily be corrected/reverted by running cs-fixer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions