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
API Platform version(s) affected: 3.1.x
Description
since #4996 with
extraProperties: ['standard_put' => true], thePUToperation behaves as a full replacement of the resource, and people should use thePATCHoperation as a replacement.There are 2 issues with this migration path:
application/merge-patch+jsonformat does not allow clients to set a value tonullstandard_putis set to true, ALL properties are reset, even the properties that are excluded from the denormalization groups, making this operation practically not usableHow to reproduce
Using the
demoapplication 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:
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
nullPossible Solution
standard_put=falsein ApiPlatform 4PATCHformat that accepts null values