FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 703 forks source link

Upgrading to 3.0 breaks body parsing for POST request #2258

Closed InjustFr closed 4 years ago

InjustFr commented 4 years ago

Hi,

I've upgraded to 3.0 from 2.8.2 and POST routes which were working fine before now won't

The body of the POST request seems to be completely ignored and not parsed into the request

Here is the body of my Request: {"test": "test"}

Here is a repo with an example not working: Repo

If you upgrade to 3.0 it breaks

Maybe I'm doing something wrong, but I'm haven't managed to figure it out on my own

Thanks in advance for your help

CraigPeden commented 4 years ago

I've also had this issue while upgrading from 2.7.2 to 3.0.2. The first parameter in my post method within the controller is name, and I thus get an InvalidParameterException with detail:

"Parameter \"name\" of value \"NULL\" violated a constraint \"This value should not be null.\"".

This occurs consistently even when stripping the body down to

{
    "name": "Functional test template"
}

Controller uses

use FOS\RestBundle\Controller\Annotations as Rest;

* @Rest\RequestParam(name="name", nullable=false, requirements=@Type(type="string"))
CraigPeden commented 4 years ago

My issue was solved by adding body_listener: true to fos_rest.yml, I hadn't noticed this was one of the breaking changes between 2.x and 3.x

xabbuh commented 4 years ago

This indeed looks the cause here. So I am going to close here.

@Thewolfs Please leave a comment if enabled the body listener doesn't fix it for you.

InjustFr commented 4 years ago

Thank you @CraigPeden, this indeed fixes it