core icon indicating copy to clipboard operation
core copied to clipboard

Class property of the ApiResource annotation doesn't propagate to operations

Open hafkenscheid opened this issue 8 months ago • 4 comments

API Platform version(s) affected: 4.1.12

Symfony version: 6.4

Description
Configuring the class property on an #[ApiResource] does not propagate to the class at the operation level.

How to reproduce The following doesn't work:

#[ApiResource(
    class: TestEntity::class,
)]
class TestEntityApiResource
{

}

If I configure it like this, it does work:

#[ApiResource(
    operations: [
        new Post(class: TestEntity::class),
        new Get(class: TestEntity::class),
        new GetCollection(class: TestEntity::class),
        new Patch(class: TestEntity::class), 
        new Delete(class: TestEntity::class), 
    ]
)]
class TestEntityApiResource
{

}

Possible Solution
Use the class property of the resource, override it if set on the operation.

hafkenscheid avatar May 30 '25 10:05 hafkenscheid

you shouldn't really change the class but indeed we should fix this

soyuka avatar Jun 02 '25 13:06 soyuka

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 01 '25 14:08 stale[bot]

Sill an issue

hafkenscheid avatar Aug 02 '25 06:08 hafkenscheid

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 02 '25 00:10 stale[bot]