Swagger OpenAPI 使用带有模式的对象而不是数组
Swagger OpenAPI use object with schema instead of array
我正在使用 DarkOnLine
中的 L5 Swagger
使用 OpenApi 原理图生成 Swagger 文档。
要使用模式我可以做到
@OA\Property(property="certification", type="array", @OA\Items(ref="#/components/schemas/Certification"))
它工作得很好,显示为
"certification": [
{
"certification_id": 0,
"name": "string"
}
],
。但是它创建了一个带有方括号的数组块,其中包含多个对象。
如何使用相同的工作但丢失数组。像
@OA\Property(property="certification", type="object", @OA\Items(ref="#/components/schemas/Certification")),
以便删除方括号并仅显示类似的对象。
"certification": {
"certification_id": 0,
"name": "string"
}
你可以这样做:
@OA\Property(
property="certification",
ref="#/components/schemas/Certification"
)
@OA\Items
注释仅在您要指定数组中的属性时使用(请参阅 Data Types: array)。
在您的情况下,您只想描述一个对象,因此您只需在 属性 中引用对象的架构并删除 @OA\Items
.
我正在使用 DarkOnLine
中的 L5 Swagger
使用 OpenApi 原理图生成 Swagger 文档。
要使用模式我可以做到
@OA\Property(property="certification", type="array", @OA\Items(ref="#/components/schemas/Certification"))
它工作得很好,显示为
"certification": [
{
"certification_id": 0,
"name": "string"
}
],
。但是它创建了一个带有方括号的数组块,其中包含多个对象。
如何使用相同的工作但丢失数组。像
@OA\Property(property="certification", type="object", @OA\Items(ref="#/components/schemas/Certification")),
以便删除方括号并仅显示类似的对象。
"certification": {
"certification_id": 0,
"name": "string"
}
你可以这样做:
@OA\Property(
property="certification",
ref="#/components/schemas/Certification"
)
@OA\Items
注释仅在您要指定数组中的属性时使用(请参阅 Data Types: array)。
在您的情况下,您只想描述一个对象,因此您只需在 属性 中引用对象的架构并删除 @OA\Items
.