laravel如何生成swagger接口文档
生活随笔
收集整理的這篇文章主要介紹了
laravel如何生成swagger接口文档
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
php artisan serve --host 0.0.0.0
php artisan serve --port 8080
地址:
http://127.0.0.1/blogkjh/public/api/documentation
1、安裝包
composer require darkaonline/l5-swagger
2、配置
php artisan vendor:publish --provider “L5Swagger\L5SwaggerServiceProvider”
3、啟動服務
php artisan serve
剛開始啟動會報錯,因為還沒有寫注釋文檔
注釋文檔可以這樣寫
/*** @OA\Info(title="查詢api", version="0.1")*//*** @OA\Get(* path="/article",* @OA\Response(response="200", description="An example resource")* )*/然后命令行輸入:
php artisan l5-swagger:generate
生成
關于注釋:
@SWG,現在最新版本使用的是 @OA 做為標識
標題添加參數
/*** @OA\Post(* path="/article",* summary="Adds a new user",* @OA\RequestBody(* @OA\MediaType(* mediaType="application/json",* @OA\Schema(* @OA\Property(* property="title",* type="string"* ),* @OA\Property(* property="content",* type="string"* ),* example={"title": "a3fb6", "content": "Jessica Smith"}* )* )* ),* @OA\Response(* response=200,* description="OK"* )* )*/熱更新
全局搜索generate_always
增加請求體里的內容:
概覽
@OA\Parameter(name="userId", in="query", @OA\Schema(type="intger"), required=true, description="用戶ID"),in
in中的內容可以是query也可以是path
單個api介紹:
summary="根據 ID 獲取文章信息",標簽分類
tags={"用戶管理"},參考博客:
https://learnku.com/articles/37313
總結
以上是生活随笔為你收集整理的laravel如何生成swagger接口文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: article之api文档
- 下一篇: 内存不足The following ex