只有 Laravel 5.1 及以上版本和 Lumen 5.1 及以上版本可以使用
默認的,這個命令將把文檔輸出到 stdout
中,你可以使用管道將這個文件存儲到一個文件中或者推送到服務器上。
例子
將以下內容放到控制器的定義方法上面測試:
/**
* 註冊用戶
*
* 使用 `username` 和 `password` 註冊用戶。
*
* @Post("/")
* @Versions({"v1"})
* @Request({"username": "foo", "password": "bar"})
* @Response(200, body={"id": 10, "username": "foo"})
*/
$ php artisan api:docs --name Example --use-version v2
文件的輸出目錄 使用 --output-file
。
$ php artisan api:docs --name Example --use-version v2 --output-file /path/to/documentation.md
爲了避免手動定義名字和版本,你可以自定義配置到你的配置文件或者環境文件中。
實例
.env
API_NAME="center"
$ php artisan api:docs --use-version v1 --output-file /var/www/html/documentation.md
就會在對應路徑下生成documentation.md文件,內容爲
FORMAT: 1A
# center
# AppHttpControllersApiController
## 註冊用戶 [POST /]
使用 `username` 和 `password` 註冊用戶。
+ Request (application/json)
+ Body
{
"username": "foo",
"password": "bar"
}
+ Response 200 (application/json)
+ Body
{
"id": 10,
"username": "foo"
}
參考文檔:Link
擴展接口文檔:
Apidoc:apidoc
showdoc:showdoc