我如何注释我的属性,即值对象,以便 API 平台为 swagger 文档生成其字段?

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

我有一个名为 Station 的实体。

此实体有一个名为 attributes 的 属性,它是 StationAttributes 值对象。

我尝试将 属性 设置为 StationAttributes:

/**
* @var StationAttributes
* @ORM\Column(name="attributes", type="station_attributes", nullable=true)
*/
private $attributes;

但是,API 平台生成的 Station 模型如下所示:

{
...
"attributes": "string"
}

我希望它是这样的:

{
...
"attributes": {
    "field": true,
    "field2": "value2",
  }
}

我怎样才能做到这一点?

我继续将 StationAttributes 注册为 ApiResource/Model 然后我将 swagger 上下文添加到属性 属性.

/**
 * @var StationAttributes
 *
 * @ApiProperty(
 *     attributes={
 *         "swagger_context"={
 *              "$ref"="#/definitions/StationAttributes"
 *          }
 *     }
 * )
 *
 * @ORM\Column(name="attributes", type="station_attributes", nullable=true)
 */
private $attributes;