3

我正在使用L5 SwaggerfromDarkOnLine使用 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"
 }
4

1 回答 1

5

你可以做:

@OA\Property(
  property="certification", 
  ref="#/components/schemas/Certification"
)

仅当@OA\Items您要指定数组内的属性是什么时才使用注释(请参阅数据类型:数组)。

在您的情况下,您只想描述一个对象,因此您只需在属性中引用对象的模式并删除@OA\Items

于 2019-01-30T05:20:14.423 回答