如何在 swagger 上添加多个示例项目
Ho to add multiple example items on swagger
需要有关如何在 swagger 上执行此操作的帮助。
@SWG\Property(property="LineItems", type="array", @SWG\Items(ref="#/definitions/LineItem"))
@SWG\Definition(
definition="LineItem",
required={"Description","Quantity","UnitAmount"},
@SWG\Property(property="Description", type="string", example="Item 1"),
@SWG\Property(property="Quantity", type="integer", example=100),
@SWG\Property(property="UnitAmount", type="float", example=11)
)
@SWG\Definition(
definition="LineItem2",
required={"Description","Quantity","UnitAmount"},
@SWG\Property(property="Description", type="string", example="Item 2"),
@SWG\Property(property="Quantity", type="integer", example=10),
@SWG\Property(property="UnitAmount", type="float", example=21)
)
我想在 LineItems 上添加 LineItem 和 LineItem2 属性,我希望输出应该是这样的
"LineItems": [
{
"Description": "Item 1",
"Quantity": 100,
"UnitAmount": 11,
},
{
"Description": "Item 2",
"Quantity": 100,
"UnitAmount": 22,
}
]
要在 Swagger UI 中显示包含多个项目的数组示例,您需要一个数组级 example
,例如:
LineItems:
type: array
items:
$ref: '#/definitions/LineItem'
# Multi-item example
example:
- Description: Item 1
Quantity: 100
UnitAmount: 11
- Description: Item 2
Quantity: 100
UnitAmount: 22
即数组项只有一个定义(LineItem
),而多项示例是在数组级别使用example
关键字定义的。
Swagger-PHP 版本为:
* @SWG\Property(
* property="LineItems",
* type="array",
* @SWG\Items(ref="#/definitions/LineItem"),
* example = {
* {"Description": "Item 1", "Quantity": 100, "UnitAmount": 11},
* {"Description": "Item 2", "Quantity": 100, "UnitAmount": 22}
* }
* )
需要有关如何在 swagger 上执行此操作的帮助。
@SWG\Property(property="LineItems", type="array", @SWG\Items(ref="#/definitions/LineItem"))
@SWG\Definition(
definition="LineItem",
required={"Description","Quantity","UnitAmount"},
@SWG\Property(property="Description", type="string", example="Item 1"),
@SWG\Property(property="Quantity", type="integer", example=100),
@SWG\Property(property="UnitAmount", type="float", example=11)
)
@SWG\Definition(
definition="LineItem2",
required={"Description","Quantity","UnitAmount"},
@SWG\Property(property="Description", type="string", example="Item 2"),
@SWG\Property(property="Quantity", type="integer", example=10),
@SWG\Property(property="UnitAmount", type="float", example=21)
)
我想在 LineItems 上添加 LineItem 和 LineItem2 属性,我希望输出应该是这样的
"LineItems": [
{
"Description": "Item 1",
"Quantity": 100,
"UnitAmount": 11,
},
{
"Description": "Item 2",
"Quantity": 100,
"UnitAmount": 22,
}
]
要在 Swagger UI 中显示包含多个项目的数组示例,您需要一个数组级 example
,例如:
LineItems:
type: array
items:
$ref: '#/definitions/LineItem'
# Multi-item example
example:
- Description: Item 1
Quantity: 100
UnitAmount: 11
- Description: Item 2
Quantity: 100
UnitAmount: 22
即数组项只有一个定义(LineItem
),而多项示例是在数组级别使用example
关键字定义的。
Swagger-PHP 版本为:
* @SWG\Property(
* property="LineItems",
* type="array",
* @SWG\Items(ref="#/definitions/LineItem"),
* example = {
* {"Description": "Item 1", "Quantity": 100, "UnitAmount": 11},
* {"Description": "Item 2", "Quantity": 100, "UnitAmount": 22}
* }
* )