github:https://github.com/qq15725/ddoc
安裝
composer require wxm/ddoc --dev
配置
Laravel
-
註冊 ServiceProvider (laravel 5.5 不需要註冊):
Wxm\DDoc\DDocServiceProvider::class
-
釋出配置:
php artisan vendor:publish --provider="Wxm\DDoc\DDocServiceProvider" --force
Lumen
-
註冊 ServiceProvider:
bootstrap/app.php
下新增// 本地環境註冊 if ($app->environment('local')) { $app->register(Wxm\DDoc\DDocServiceProvider::class); }
- 手動複製配置檔案
使用
-
開啟伺服器:
php artisan serve
-
訪問
http://localhost:8000/ddoc
介面註釋 生成文件
/**
* @Resource("登入令牌", uri="/token")
*/
class AuthController extends Controller
{
/**
* 獲取令牌
*
* > 透過手機號和密碼獲取會話`token`即登入憑證.
* > 需要認證的請求請攜帶此 Authorization 頭
* >
* > Authorization:Bearer {token}
* >
*
* @Post("/")
* @Versions({"v1"})
* @Response(200, body={"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkueHkudGVzdFwvc2Vzc2lvbiIsImlhdCI6MTU0NTIxNjM5OSwiZXhwIjoxNTQ1MjE5OTk5LCJuYmYiOjE1NDUyMTYzOTksImp0aSI6Im9pZjV4WTNqS2JkbEhzVmQiLCJzdWIiOjEsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.p3oAVkAxSCxTug5s6168N-ccfuCCywGDFiJ0b9zCXq8","token_type":"bearer","expires_in":3600})
* @Parameters({
* @Parameter("phone", type="integer", required=true, description="手機號."),
* @Parameter("password", type="string", required=true, description="密碼."),
* })
*/
public function login()
{
}
/**
* 銷燬當前令牌
*
* * 許可權要求:`登入使用者`
*
* > 銷燬成功返回 `204` 無內容 Http code
*
* @Delete("/")
* @Versions({"v1"})
* @Response(204)
*/
public function logout()
{
}
/**
* 重新整理獲取新令牌
*
* * 許可權要求:`登入使用者`
*
* > 銷燬當前令牌,獲取新令牌
*
* @Put("/")
* @Versions({"v1"})
* @Response(200, body={"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkueHkudGVzdFwvdG9rZW4iLCJpYXQiOjE1NDUyOTY3MzcsImV4cCI6MTU0NTMwMDM2NywibmJmIjoxNTQ1Mjk2NzY3LCJqdGkiOiI5Rk43TGJxZUlBc1JmZVRwIiwic3ViIjoxLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.qBCL-EfGYRnlxPZerpHpD9HVumjf89fVa2CBoXoFSvI","token_type":"bearer","expires_in":3600})
*/
public function refresh()
{
}
}
參考 API Blueprint Documentation.
參考圖
本作品採用《CC 協議》,轉載必須註明作者和本文連結