core icon indicating copy to clipboard operation
core copied to clipboard

Deprecating the PUT method seems to have unintended side effects

Open pauljura opened this issue 10 months ago • 1 comments

API Platform version(s) affected: 4.1.5

Description
Say I have a resource that uses GET, PUT, and PATCH methods. This resource is also used as a property of another resource, using the POST method and different serialization groups. If I mark the PUT method as deprecated (because I prefer PATCH instead) then it gets marked as deprecated in the other resource and is missing from the Swagger documentation, even though it continues to work as expected.

How to reproduce
Class User:

#[ApiResource(
    normalizationContext: ['groups' => ['read']],
    denormalizationContext: ['groups' => ['update']],
)]
#[Get]
#[GetCollection]
#[Put(
    deprecationReason: 'Use PATCH instead',
)]
#[Patch]
class User
{
    #[Groups(['read', 'custom_read'])]
    private string $username;

    #[Groups(['custom_update', 'custom_read'])]
    private string $foo;

    public function getUsername(): string
    {
        return $this->username;
    }

    public function setUsername(string $username): User
    {
        $this->username = $username;
        return $this;
    }

    public function getFoo(): string
    {
        return $this->foo;
    }

    public function setFoo(string $foo): User
    {
        $this->foo = $foo;
        return $this;
    }
}

Class CustomUserAction:

#[ApiResource(
    operations: [
        new Post(),
    ],
    normalizationContext: ['groups' => ['custom_read']],
    denormalizationContext: ['groups' => ['custom_update']],
)]
class CustomUserAction
{
    #[Groups(['custom_update', 'custom_read'])]
    #[ApiProperty(required: true)]
    private User $user;

    public function getUser(): User
    {
        return $this->user;
    }

    public function setUser(User $user): CustomUserAction
    {
        $this->user = $user;
        return $this;
    }
}

Additional Context
If the PUT method is not deprecated, or not available at all, everything looks good:

Image

Image

If the PUT method exists and is deprecated, this happens:

Image

Image

Am I doing something wrong or is this a bug?

Thanks

pauljura avatar Apr 04 '25 05:04 pauljura

maybe that https://github.com/api-platform/core/pull/6960 can also fix this

soyuka avatar Apr 07 '25 14:04 soyuka