Skip to content

Commit a6c5f98

Browse files
authored
Merge pull request #2815 from teohhanhui/add-note-in-changelog-about-empty-request-content-bugfix
Add a note in the CHANGELOG about empty request content bugfix
2 parents e43e9c3 + fd4c775 commit a6c5f98

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@
1818
* Metadata: Fix identifier support when using an interface as resource class
1919
* Metadata: the HTTP method is now always uppercased
2020
* Allow to disable listeners per operation (fix handling of empty request content)
21+
22+
Previously, empty request content was allowed for any `POST` and `PUT` operations. This was an unsafe assumption which caused [other problems](https://github.com/api-platform/core/issues/2731).
23+
24+
If you wish to allow empty request content, please add `"deserialize"=false` to the operation's attributes. For example:
25+
26+
```php
27+
<?php
28+
// api/src/Entity/Book.php
29+
30+
use ApiPlatform\Core\Annotation\ApiResource;
31+
use App\Controller\PublishBookAction;
32+
33+
/**
34+
* @ApiResource(
35+
* itemOperations={
36+
* "put_publish"={
37+
* "method"="PUT",
38+
* "path"="/books/{id}/publish",
39+
* "controller"=PublishBookAction::class,
40+
* "deserialize"=false,
41+
* },
42+
* },
43+
* )
44+
*/
45+
class Book
46+
{
47+
```
48+
49+
You may also need to add `"validate"=false` if the controller result is `null` (possibly because you don't need to persist the resource).
50+
2151
* Return the `204` HTTP status code when the output class is set to `null`
2252
* Be more resilient when normalizing non-resource objects
2353
* Replace the `data` request attribute by the return of the data persister

0 commit comments

Comments
 (0)