-
-
Notifications
You must be signed in to change notification settings - Fork 975
Closed
Description
API Platform version(s) affected: x.y.z
Description
when i make my normalization context on symfony 5.1.99 in api ressource like that :
normalizationContext={"groups"={"read:question"}}
my model disapear in the api documentation and the api return 200 code but don't return element from database, only context from hydra
How to reproduce
normalizationContext={"groups"={"read:question"}} in api ressource and @groups in a entity.
and serializer: { enable_annotations: true } in config/package/framework.yamls
Possible Solution
i think it's cause it's a newest version.
Additional Context
karol-may
Activity
kelvin2200 commentedon Jul 7, 2020
did you add the same normalization group to every property in your entity?
redha-ax2lan commentedon Jul 8, 2020
I tested in both cases and it doesn't work, with all property in the same group and with 2 propertie in the group and here is only one group in this entity.
kelvin2200 commentedon Jul 8, 2020
from the little you provided, the route seems to be returning the expected result. Can you post the entire entity here? I think you are messing up somewhere with the denormalization groups.
redha-ax2lan commentedon Jul 9, 2020
I do not have denormalization groups just a normalization, it is not necessary to create a group. my code worked on symfony 5.0 and 4.4
kelvin2200 commentedon Jul 10, 2020
well, if you don't want to post your entity, I don't know how to help. I'm running 5.1 and I have no issues. Do you have custom normalizers defined?
redha-ax2lan commentedon Jul 15, 2020
`<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\QuestionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
@ApiResource(normalizationContext={"groups"={"read:quest"}}, collectionOperations={"get"}, itemOperations={"get"})
@Orm\Entity(repositoryClass="App\Repository\QuestionRepository")
/
class Question
{
/*
*/
private $id;
/**
*/
private $libelle;
/**
*/
private $reponses;
public function __construct()
{
$this->reponses = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLibelle(): ?string
{
return $this->libelle;
}
public function setLibelle(string $libelle): self
{
$this->libelle = $libelle;
}
/**
*/
public function getReponses(): Collection
{
return $this->reponses;
}
public function addReponse(Reponse $reponse): self
{
if (!$this->reponses->contains($reponse)) {
$this->reponses[] = $reponse;
$reponse->setIdQuestion($this);
}
}
public function removeReponse(Reponse $reponse): self
{
if ($this->reponses->contains($reponse)) {
$this->reponses->removeElement($reponse);
// set the owning side to null (unless already changed)
if ($reponse->getIdQuestion() === $this) {
$reponse->setIdQuestion(null);
}
}
}
}
`
redha-ax2lan commentedon Jul 15, 2020
this is my entity i don't have custom normalizer
romainderocle commentedon Oct 23, 2020
did you find a solution ?
redha-ax2lan commentedon Oct 23, 2020
not really, I downgraded symfony to 5.0 and it works, I haven't tried again since
dParadiz commentedon Oct 27, 2020
Try to run
./bin/console cache:clear
redha-ax2lan commentedon Oct 28, 2020
there is no cache that does not fix the bug
TadjerouniMohamedAdel commentedon Nov 1, 2020
for me
./bin/console cache:clear
solved the issuesymfony :5.1
redha-ax2lan commentedon Nov 2, 2020
after trying it works! thanks for the help !
Tchekda commentedon Nov 14, 2020
Worked also for me !!
Is there a way to disable this cache in dev environment ?
Thanks
angelomelonas commentedon Dec 7, 2020
@dParadiz clearing the cache solved my problem after 3 hours of wondering why a simple
get
was not returning the entity data!gediminasnn commentedon Jan 14, 2021
Same problem but with post operation, cache clearing does not fix it...
gediminasnn commentedon Jan 14, 2021
Bus somewhy if I add write group to setter method it magically works...
NouraToukabriACF commentedon Sep 24, 2021
Worked for me!! thank youu
abdojulari commentedon Apr 7, 2022
In my own case, I did, out of 5, only two appeared in the api documentation.