问题
I have an Entity called Station
.
This entity has a property called attributes
which is StationAttributes
value object.
I try to set the property to be StationAttributes
:
/**
* @var StationAttributes
* @ORM\Column(name="attributes", type="station_attributes", nullable=true)
*/
private $attributes;
However, the API Platform generates Station
model that looks like this:
{
...
"attributes": "string"
}
I want it to be like this:
{
...
"attributes": {
"field": true,
"field2": "value2",
}
}
How can I achieve this?
回答1:
I went ahead and registered StationAttributes
as ApiResource/Model and then I've added swagger context to attributes property.
/**
* @var StationAttributes
*
* @ApiProperty(
* attributes={
* "swagger_context"={
* "$ref"="#/definitions/StationAttributes"
* }
* }
* )
*
* @ORM\Column(name="attributes", type="station_attributes", nullable=true)
*/
private $attributes;
来源:https://stackoverflow.com/questions/56275937/how-can-i-annotate-my-attribute-which-is-value-object-in-order-that-api-platform