何在swagger上添加多个示例项

时间:2017-09-20 08:53:40

标签: swagger swagger-ui swagger-2.0

在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,
        }
      ]

1 个答案:

答案 0 :(得分:2)

要在Swagger UI中显示包含多个项目的数组示例,您需要一个数组级class LineDetection(QtGui.QWidget): # ... other functions go here ... # Note the indentation of the next line def pickFile(self): global imgPath01 imgPath01 = QtGui.QFileDialog.getOpenFileName(self, 'Open File', "~/", "Images (*.png *.jpg)") print(imgPath01) self.refreshImage() ,例如:

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关键字定义了多项示例。

Swagger-PHP版本将是:

example