Bonjour à tous,
j'essaye d'implémenter une API REST sur un code assez lourd contenant pas mal de resources.
Il y en a une qui me pose problème, quelque soit la configuration des groups et du serializer, dans la réponse j'ai toujours et uniquement 2 attributs : id et label
PHP 7.4, Symfony 4.4, APi-Plateform 2.6.8
L'entité (simplifiée, il y a des getter et setter pour chaque attribut):
/**
* Structure.
*
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="por_structure")
* @ORM\Entity(repositoryClass="Common\StructureBundle\Repository\StructureRepository")
* @UniqueEntity(fields={"parent", "code", "status"}, errorPath="code", message="common.structure.code.unique")
* @UniqueEntity(fields={"parent", "label", "status"}, errorPath="label", message="common.structure.label.unique")
*/
class Structure
{
/**
* ID of the structure node.
*
* @var int
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Label of the structure node.
*
* @var string
* @Assert\NotBlank()
* @ORM\Column(name="label", type="string", length=255, nullable=false)
*/
private $label;
/**
* External ID of the structure node.
*
* @var string
* @Assert\NotBlank()
* @ORM\Column(name="code", type="string", length=255, nullable=false)
*/
private $code;
/**
* Accounting code of the structure node.
*
* @var string
* @ORM\Column(name="accounting_code", type="string", length=255, nullable=true)
*/
private $accountingCode;
J'aimerai que cette resource me renvoie tous les attributs dans le GET du collectionOperations.
le resources.yaml :
resources:
#Structure
Common\StructureBundle\Entity\Structure:
shortName: 'Common/Structure'
collectionOperations:
get:
openapi_context:
summary: 'Récupère une collection de Structure'
description: 'Récupère une collection de Structure'
normalization_context:
groups: [ 'a2:read:Structure']
openapi_definition_name: 'collection-read'
le serializer.yaml :
Common\StructureBundle\Entity\Structure:
attributes:
id:
groups: [ 'a2:read:Structure' ]
label:
groups: [ 'a2:read:Structure' ]
code:
groups: [ 'a2:read:Structure' ]
status:
groups: [ 'a2:read:Structure' ]
[...]
Et voici ce que j'obtient en réponse, même si je ne met aucun attribut dans le fichier yaml :
{
"@context": "\/api\/contexts\/Common\/Structure",
"@id": "\/api\/v2\/common\/structures",
"@type": "hydra:Collection",
"hydra:member": [
{
"id": 1,
"label": "SOCIETE 1 (FR)"
},
{
"id": 2,
"label": "Défaut"
},
{
"id": 3,
"label": "ZForfait jours"
},
Alors que dans la doc de l'API le schema est bon :
{
"hydra:member": [
{
"@id": "string",
"@type": "string",
"@context": "string",
"id": 0,
"label": "string",
"code": "string",
"accountingCode": "string",
"status": true,
[...]
Vous avez une idée d'où cela peut venir ?