Reputation: 141
Oke, so I have the following use case. On some of my entities I use a file entity for example with the organization logo.
Now I want users to post either a link (I will then async get the file) or a base64 has of the file. But when the user does a get I want to present an JSON representation of the file entity (that also includes size, a thumbnail link etc).
The current setup that I have is two different properties on my entity, one for reading and one for posting with different logic. And then an event listener that handels the logic. That’s all fine and all but it causes the user to post a postLogo property in their json file, I would hower like them to post to a logo property in their json file.
Is there an annotation that I can use (for example name on ApiProperty) to achieve this or do I need to override the serializer?
/**
* @var File The logo of this organisation
*
* @ORM\ManyToOne(targetEntity="File")
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="#/components/schemas/File"
* }
* }
* )
* @Groups({"read"})
*/
public $logo;
/**
* @var string The logo of this organisation, a logo can iether be posted as a valid url to that logo or a base64 reprecentation of that logo.
*
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="url or base64"
* }
* }
* )
* @Groups({"write"})
*/
public $postLogo;
Upvotes: 2
Views: 3536
Reputation: 81
You can add a setter with a SerializedName annotation. Something like this should work
/**
* @Groups({"write"})
* @SerializedName("logo")
*
*/
public function setPostLogo($value)
{
$this->postLogo = $value;
}
Upvotes: 3