Property and @Groups() annotation to YAML
See original GitHub issueGiven the entity below, how do I move the id and name, along with their annotated serialization groups, into the API Platform resource YAML (defined below the entity)?
I’ll create a PR for the docs project once I get this working.
src/Entity/Org.php
<?php declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass="App\Repository\OrgRepository")
*/
class Org
{
/**
* @var int
*
* @Groups({"read"})
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string
*
* @Groups({"read", "write"})
* @ORM\Column(type="string", length=128, unique=true, nullable=false)
*/
private $name;
// ...
config/api_platform/resources/Org.yaml
resources:
App\Entity\Org:
attributes:
normalization_context:
groups: ['read']
denormalization_context:
groups: ['write']
collectionOperations:
get: ~
post: ~
itemOperations:
get: ~
put: ~
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
24. Externalized Configuration - Spring
You can use properties files, YAML files, environment variables, and command-line arguments ... @PropertySource annotations on your @Configuration classes.
Read more >Inject a Map from a YAML File with Spring - Baeldung
This annotation is introduced to easily inject external properties from configuration files directly into Java objects. In this section, we'll ...
Read more >How can I pass properties placeholder to annotations from ...
I want to map values from application yaml (namly config.websocket.topic) to annotation SendTo in my controller class. I want to do this because ......
Read more >Reading Nested Properties in Spring Boot - amitph
Spring Boot @ConfigurationProperties annotation provides an easy way to read and bind application configurations from a properties or a yaml file into a ......
Read more >Mapping configuration to objects - Quarkus
With config mappings it is possible to group multiple configuration properties in a single interface that share the same prefix.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

They can, indeed. The problem is for the end user (developer) that it’s not clear how to move
AnnotationstoYamlfor api-platform without this knowledge.We tried to find example in the api-platform’s docs, we tried to check api-platform’s tests, we tried to debug and eventually found an answer in github issues.
All of these can be avoided with a properly documented case for
Yamlusage.It will significantly improve DX.
Confirmed, and for anyone else wondering like me,
.yaml(in addition to.yml) extension works for files in theserializerdirectory as well.Thanks @borNfreee, I’ll get a docs PR going this weekend.