How can I annotate my attribute which is Value Object in order that API Platform would generate its fields for swagger documentation?

你离开我真会死。 提交于 2019-12-24 19:16:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!