Deviltechs
Deviltechs

Reputation: 11

Symfony 5.4 + Api Platform Post response send back two json

I have a web app that use Symfony 5.4 and api platform 2.6.8. When I do a POST request, normally I obtain in the response a JSON with the information about the object created (see below):

{
    "@context": "/api/contexts/Zone",
    "@id": "/api/zones/26",
    "@type": "Zone",
    "id": 26,
    "name": "test8"
} 

But around 50% of the time, I receive the following response that contain the body sent in the request + the expected answer:

{
    "name": "test9"
}{
    "@context": "/api/contexts/Zone",
    "@id": "/api/zones/27",
    "@type": "Zone",
    "id": 27,
    "name": "test9"
}

There is no information in the logs that explain this different behavior. All the POST requests are concerned by this strange behavior.

Bellow the code of one entity impacted by this issue:

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
 * Zone
 *
 * @ORM\Table(name="zone")
 * @ORM\Entity(repositoryClass="App\Repository\ZoneRepository")
 * @ApiResource
 */
class Zone
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=50, unique=true)
     */
    private $name;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return Zone
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
}
?>

The api platform's config (config/packages/api_platform.yaml):

api_platform:
    mapping:
        paths: ['%kernel.project_dir%/src/Entity']
    patch_formats:
        json: ['application/merge-patch+json']
    swagger:
        versions: [3]

In dev mode, the symfony profiler show the following info: Profiler info

Upvotes: 0

Views: 507

Answers (1)

Deviltechs
Deviltechs

Reputation: 11

I solved the issue by adding the following line in my ngnix config:

fastcgi_param PHP_VALUE "auto_prepend_file= \n allow_url_include=Off" ;

Upvotes: 1

Related Questions