本文介绍了如何为我的属性(值对象)添加注释,以使API Platform能够生成其用于草率文档的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为Station
的实体.
此实体具有名为attributes
的属性,该属性是StationAttributes
值对象.
This entity has a property called attributes
which is StationAttributes
value object.
我尝试将属性设置为StationAttributes
:
/**
* @var StationAttributes
* @ORM\Column(name="attributes", type="station_attributes", nullable=true)
*/
private $attributes;
但是,API平台会生成如下所示的Station
模型:
However, the API Platform generates Station
model that looks like this:
{
...
"attributes": "string"
}
我希望它像这样:
{
...
"attributes": {
"field": true,
"field2": "value2",
}
}
我该如何实现?
推荐答案
我继续将StationAttributes
注册为ApiResource/Model,然后在属性属性中添加了大张旗鼓的上下文.
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;
这篇关于如何为我的属性(值对象)添加注释,以使API Platform能够生成其用于草率文档的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!