只有 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