ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1.安装swagger。 ~~~bash composer require darkaonline/l5-swagger ~~~ 2.创建config/l5-swagger.php配置文件。 ~~~ php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider" ~~~ 3.使用。 ``` php artisan l5-swagger:generate ``` 使用phpartisan l5-swagger:generate生成文档,此时会在storage/api-docs,生成一个api-docs.json的文件,一会每次生成都会覆盖此文件。如果需要开启自动生成,可在配置文件或.env文件中设置`generate_always`参数为`true``。这个时候访问你的项目域名+`[*/ api / documentation*](http://vrm-service-url/api/documentation)。你会看到。 4.相关注释详情。[链接](https://www.sdk.cn/details/9pPQD6wqK09L8ozvNy) ~~~ /** * @OA\OpenApi( * @OA\Server( * url="http://cs.laravel.com/api/v1", * description="后台接口前缀" * ), * @OA\Info( * title="系统管理相关接口", * version="1.0.0", * description="描述", * termsOfService="http://example.com/terms/", * @OA\Contact( * name="宋博", * url="http://www.lvacms.cn", * email="997786358@qq.com" * ), * @OA\License( * name="Apache 2.0", * url="http://www.lvacms.cn" * ) * ) * ) */ /** *@OA\Tag(name="UnAuthorize", description="No user login required") */ /** * @OA\SecurityScheme( * type="apiKey", * description="全局添加API Token鉴权", * name="authorization", * in="header", * securityScheme="Authorization-Bearer" * ) */ /** * @OA\SecurityScheme( * type="apiKey", * description="全局添加key", * name="apikey", * in="header", * securityScheme="Authorization-key" * ) */ ~~~ ~~~ /** * @OA\Get( * path="/index", * operationId="getListOfUsers", * tags={"Admin"}, * description="接口描述", * security={{ "Authorization-Bearer":{},"Authorization-key":{} }}, * @OA\Parameter( * name="offset", * @OA\Schema( * type="integer", * format="int64" * ), * in="query", * description="offset", * example=0, * required=true, * ), * @OA\Parameter( * name="limit", * @OA\Schema( * type="integer", * format="int64" * ), * in="query", * description="offset", * example=10, * required=true, * ), * @OA\Response( * response=200, * description="success", * @OA\JsonContent(type="object", * @OA\Property(property="message", type="string"), * @OA\Property(property="data", type="array", * @OA\Items(type="object", * @OA\Property(property="id", type="integer"), * @OA\Property(property="name", type="string"), * @OA\Property(property="email", type="string",format="111",description="其他二外参数") * ), * ), * ), * ) * ) */ ~~~