yii2 - 如何在 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 数组?
解决方案
使用type="array"
and定义数组属性@SWG\Items
:
* @SWG\Property(
* property="charsName",
* type="array",
* @SWG\Items(type="string"),
* example={"1","2","3"}
* )
推荐阅读
- laravel - 如何仅忽略标题形式的第一页
- python - jay 文件格式是否特定于 Python 数据表?
- collections - Binding 现已弃用的 Collection 一致性的干净替代方案?
- python-3.x - 尝试编写文本换行函数,但代码在所需输出后显示几个空行
- apache-spark-sql - 当 arrays_zip 数据源自嵌套时,Spark DataFrame 的输出将列名替换为“0”、“1”
- c++ - 无法增加 QToolButton 的大小(按钮样式设置为 Qt::ToolButtonTextBesideIcon)
- r - 如何使用 for 循环将所有股票价格乘以各自的单位数后求和?
- mysql - 为 Mysql 8.0 构建 docker 容器失败
- sql - 将部分结果放入列而不是行
- canvas - 同一页面的按钮点击不断触发CustomPaint的油漆颤动