I am unable to display the payload of the request and the response according to the serialization groups defined with JmsSerialiazer-bundle
as shown in this screenshot :
I want to display the fields of campaignDeserializer
group in a json example of http request, and the fields of campaignSerializer
group in a json example of http response.
I am using the annotation of NelmioApiDoc-bundle ^ 4.1
on Symfony 5.4 LTS
with PHP 7.4
.
Could you help me to configure display of attributes of entities in DOC API by serialization groups defined in entities ?
Here is the code I tried:
In my controller above an
add
method :/** * @Rest\Post( * path="/", * name="new", * options={ "method_prefix" = false } * ) * @Rest\View(StatusCode=201, serializerGroups={"campaignSerializer"}) * @ParamConverter( * "campaign", * converter="fos_rest.request_body", * options={"deserializationContext"={"groups"={"campaignDeserializer"}}} * ) * @OA\Post( * tags={"Campaigns"}, * summary="Add campaign", * * @OA\Response( * response="201", * description="Returned when resource created", * @OA\Schema( * type="array", * @OA\Items(ref=@Model(type=Campaign::class, groups={"campaignSerializer"})) * ) * ), * @OA\Response(response="400", description="Returned when invalid data posted"), * @OA\Response(response="401", description="Returned when not authenticated"), * @OA\Response(response="403", description="Returned when token not valid or expired"), * ) */
In my entity :
<?php
namespace App\Entity;
use App\Repository\CampaignRepository;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use OpenApi\Annotations as OA;
/**
* @ORM\Entity(repositoryClass=CampaignRepository::class)
* @Serializer\ExclusionPolicy("ALL")
*/
class Campaign
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @OA\Property(type="integer", description="ID of the campaign")
* @Serializer\Groups({"campaignSerializer", "sessionSerializer"})
* @Serializer\Expose()
*/
private $id;
/**
* @ORM\Column(type="string", length=50, unique=true)
* @OA\Property(type="string")
* @Serializer\Groups({"campaignSerializer", "sessionSerializer"})
* @Serializer\Expose()
*/
private $identifier;
/**
* @ORM\Column(type="string", length=255)
* @OA\Property(type="string")
* @Serializer\Groups({"campaignSerializer", "campaignDeserializer"})
* @Serializer\Expose()
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
* @OA\Property(type="text")
* @Serializer\Groups({"campaignSerializer", "campaignDeserializer"})
* @Serializer\Expose()
*/
private $description;
/**
* @ORM\Column(type="datetime_immutable")
* @OA\Property(type="datetime_immutable")
* @Serializer\Groups({"campaignSerializer"})
* @Serializer\Expose()
*/
private $dateCreation;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @OA\Property(type="datetime_immutable")
* @Serializer\Groups({"campaignSerializer"})
* @Serializer\Expose()
*/
private $dateUpdate;