Thanks to visit codestin.com
Credit goes to github.com

Skip to content

No migration path for partial PUT operation in ApiPlatform 4 #5392

@jderusse

Description

@jderusse

API Platform version(s) affected: 3.1.x

Description

since #4996 with extraProperties: ['standard_put' => true], the PUT operation behaves as a full replacement of the resource, and people should use the PATCH operation as a replacement.

There are 2 issues with this migration path:

  • the application/merge-patch+json format does not allow clients to set a value to null
  • When standard_put is set to true, ALL properties are reset, even the properties that are excluded from the denormalization groups, making this operation practically not usable

How to reproduce

Using the demo application with few change.

I want my clients to be allowed to change the title of a Book (but they can not change the description). And they should be allowed to set the value to Null.

I've updated my entity in that way:

 #[Put(
+    denormalizationContext: ['groups' => ['book:put']],
+    extraProperties: ['standard_put' => true],
 )]
 class Book
 {
     /**
      * The title of the book.
      */
     #[ORM\Column]
     #[ApiFilter(SearchFilter::class, strategy: 'ipartial')]
     #[ApiProperty(types: ['https://schema.org/name'])]
     #[Assert\NotBlank]
-    #[Groups(groups: ['book:read', 'review:read'])]
+    #[Groups(groups: ['book:read', 'review:read', 'book:put'])]
     public ?string $title = null;

     /**
      * A description of the item.
      */
     #[ORM\Column(type: 'text')]
     #[ApiProperty(types: ['https://schema.org/description'])]
     #[Assert\NotBlank]
     #[Groups(groups: ['book:read'])]
     public ?string $description = null;

If clients use the PUT operation, they get the exception description: This value should not be blank.
If people use the PATCH operation, they cannot set the title to null

Possible Solution

  • Do not removed standard_put=false in ApiPlatform 4
  • Or provide a PATCH format that accepts null values

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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