首页 > 解决方案 > 如何在 swagger yii2 中将数组添加到参数?

问题描述

如何在 swagger ( yii2) 中的请求中将此类参数的描述添加到正文中。

作曲家要求

"yii2mod/yii2-swagger": "*"

我尝试使用 swagger 在 api 中编写一个方法

这就是他的回报:

{
"parent_id":"",
"name":"testCategory3",
"position":"0",
"status":"1",
"publish-status":"1",
"charsName":["1","2","3"]
}

我的描述:

   /**
     * @SWG\Put(path="/api/createCategory",
     *     tags={"Category"},
     *     summary="Create Category",
     *     @SWG\Parameter(
     *         name="Authorization",
     *         in="header",
     *         description=" ID",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="body",
     *         in="body",
     *         required=true,
     *         @SWG\Schema(
     *             type="object",
     *             @SWG\Property(property="parent_id", type="integer" ),
     *             @SWG\Property(property="status", type="integer" ),
     *             @SWG\Property(property="publish-status", type="integer" ),
     *             @SWG\Property(property="position", type="integer" ),
     *             @SWG\Property(property="name", type="string" ),
     *         )
     *     ),
     *     @SWG\Response(
     *         response = 200,
     *         description = "Ok",
     *         @SWG\Schema(ref = "#/")
     *     ),
     *     @SWG\Response(
     *         response = 400,
     *         description = "Bad Request",
     *         @SWG\Schema(ref = "#/")
     *     ),
     *     @SWG\Response(
     *         response = 404,
     *         description = "Not Found",
     *         @SWG\Schema(ref = "#/")
     *     ),
     *     @SWG\Response(
     *         response = 500,
     *         description = "Internal Server Error"
     *     )
     * )
     */

如何添加 charsName 数组?

在招摇页面

标签: yii2swagger

解决方案


使用type="array"and定义数组属性@SWG\Items

     *             @SWG\Property(
     *               property="charsName",
     *               type="array",
     *               @SWG\Items(type="string"),
     *               example={"1","2","3"}
     *             )

推荐阅读