question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property and @Groups() annotation to YAML

See original GitHub issue

Given 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:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
maks-rafalkocommented, Aug 6, 2018

They can, indeed. The problem is for the end user (developer) that it’s not clear how to move Annotations to Yaml for 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 Yaml usage.

It will significantly improve DX.

1reaction
mikemilanocommented, Aug 4, 2018

Confirmed, and for anyone else wondering like me, .yaml (in addition to .yml) extension works for files in the serializer directory as well.

Thanks @borNfreee, I’ll get a docs PR going this weekend.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found