【发布时间】:2020-02-18 06:31:07
【问题描述】:
我想在 api/doc 视图中包含对象数组。但我无法理解。
从下面的代码:
@SWG\Schema(
@SWG\Property(property="project-name", type="string"),
@SWG\Property(property="project-detail", type="array",
@SWG\Items(type="object",
@SWG\Property(property="name", type="string", ),
@SWG\Property(property="category", type="string",),
),
@SWG\Items(type="object",
@SWG\Property(property="new_name", type="string", ),
@SWG\Property(property="new_category", type="string",),
),
),
),
我得到了输出:
{
"project-name": "string",
"project-detail": [
{
"name": "string",
"category": "string"
}
]
}
但我想要以下一个:
{
"project-name": "string",
"project-detail": [
{
"name": "string",
"category": "string"
},
{
"new_name": "string",
"new_category": "string"
},
]
}
请帮帮我。
【问题讨论】:
-
Swagger 2 不支持复合类型 (
Type1|Type2),这仅添加到 OpenApi 3 中(请参阅 swagger.io/docs/specification/data-models/oneof-anyof-allof-not/…)。不幸的是,要使用它,您必须升级到 NelmioApiDocBundle v4(请参阅github.com/nelmio/NelmioApiDocBundle/blob/master/…)。 -
以项目详细级别属性为例。示例="{{}、{}、{}、{}}"
标签: annotations swagger-php nelmioapidocbundle