laravel-apidoc-generator是一个生成 laravel/lumen接口文档并支持快捷导入postman的库,在版本3.0.2中使用如下:
安装使用根据github使用说明。3.0需要 PHP > 7, Laravel >= 5.5
- 若使用
php artisan vendor:publish --provider=Mpociot\ApiDoc\ApiDocGeneratorServiceProvider --tag=config命令并没有在config目录下生成apidoc.php文件,可以使用php artisan vendor:publish手动选择 apidoc. - 在
apidoc.php里可以配置文档属性,比如在:'apply' => [ /* * Specify headers to be added to the example requests */ 'headers' => [ 'Authorization' => 'Bearer: {token}', // 'Api-Version' => 'v2', ],可以配置请求的
headers信息 - 注意在
'response_calls' => [
/*
* API calls will be made only for routes in this group matching these HTTP methods (GET, POST, etc).
* List the methods here or use '*' to mean all methods. Leave empty to disable API calls.
*/
'methods' => [],
methods需要改为[],默认是 get,如果是get的话如果有 get请求的接口,文档的导入到postman链接会失效。
- 生成文档时跳过某接口:
在接口的方法里:
/**
*@hideFromAPIDocumentation
*/
- api参数:
/** * upload_callback * 上传成功回调 * * @bodyParam path string required 上传路径 * @bodyParam device_no string required 设备ID * @bodyParam record_time int 视频录制时间 * @bodyParam upload_by int required 上传者 * @bodyParam project_id int required 当前项目ID * @bodyParam hash string required 文件的hash * @bodyParam upload_type int required 1->视频, 2->检测文件, 3->身份认证, 4->环境认证 * * @param UploadCallbackRequest $request * * @return \Illuminate\Http\JsonResponse */

- 导入到postman:
在运行php artisan apidoc:generate之后生成的api文档网页默认在public/doc目录下
打开网页,点击如果所示

复制网页里的内容,打开postman, 点击import

粘贴,点击import

在collections里面就会有刚导入的接口,已经自动填充了接口所需参数名