- 需要写title,不用每个文件都写,只要有一个就行。
/**
* @OA\Info(
* title="My Test API",
* version="1.0.0"
* )
*/
2. 写注释信息
/**
* @OA\Post(
* path="路径,比如:/test/push",
* tags={"标签"},
* summary="描述信息",
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json 请求格式",
* @OA\Schema(
* required={"id"},
* @OA\Property(
* property="id",
* type="int",
* description="id 参数"
* ),
* @OA\Property(
* property="sess",
* type="string",
* description="session 参数"
* ),
* example={"id": 1, "sess": "wdff"}
* )
* )
* ),
* @OA\Response(
* response=200,
* description="successful",
* @OA\JsonContent(
* type="array|object|string",
* @OA\Items(
* @OA\Property(property="seminarName", type="string", description="主会名"),
* @OA\Property(property="seminarId", type="int", description="主会id"),
* @OA\Property(
* property="items",
* type="object",
* @OA\Property(property="subSeminarId", type="int", description="分会id"),
* @OA\Property(property="subName", type="string", description="分会名")
*
* )
* )
* )
*
* )
* )
*/
3. 生成swagger文件
# 首选需要composer require
composer require zircote/swagger-php
# 命令
vendor/bin/openapi -o openapi.json test/
# -o 输出后的文件
# test/ 目录名,swagger会从此目录scan