'API Platform: Hide properties in /api/contexts/<entity>
When working with the API platform (Symfony) I only expose some of my entity's properties to the API. That works pretty good with groups, the output DTO and DataTransformer. When opening the API under /api/<entity> I get the results with only the defined/grouped properties.
However when having a opening the contexts under /api/contexts/<entity> ALL properties are listed. How can I reduce those properties as well?
Symfony Version: 6
Api Platform Version: 2.6.8
Entity:
/**
* @ORM\Entity(repositoryClass=EntityRepository::class)
* @ORM\HasLifecycleCallbacks()
* @ApiResource(
* normalizationContext={"groups" = {"api:read"}},
* collectionOperations={"get"},
* itemOperations={"get"},
* order={"title"="ASC"},
* paginationEnabled=false,
* output=EntityApiOutput::class
* )
*/
class Entity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"api:read"}) */
private $id;
// other properties without '@Groups'
EntityApiOutput:
class EntityApiOutput
{
/** @Groups({"api:read"}) */
public int $id;
/** @Groups({"api:read"}) */
public string $title;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
