melody-chen / api-auto-doc
自动上传API到SDK平台
3.3
2020-09-11 07:42 UTC
Requires
- php: >=7.1
README
php自动生成API文档,无需依赖任何框架(基于crada/php-apidoc改动)。提供了查看某个API的页面,访问所有API需提供密码才能查看。
为php API应用程序生成文档。无依赖。无需框架。(基于crada/php-apidoc)
需求
PHP >= 7.1
安装
- 添加至composer.json
- 推荐的安装方式是通过composer。只需将以下行添加到您的composer.json中
composer require melody-chen/api-auto-doc
使用示例/使用示例
- 函数注释文档示例/函数注释文档示例
<?php
namespace Some\Namespace;
class User
{
/**
* @ApiDescription(section="User", description="Get information about user")
* @ApiMethod(type="get")
* @ApiRoute(name="/user/get/{id}")
* @ApiParams(name="id", type="integer", nullable=false, description="User id")
* @ApiParams(name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}")
* @ApiReturnHeaders(sample="HTTP 200 OK")
* @ApiReturn(type="object", sample="{
* 'transaction_id':'int',
* 'transaction_status':'string'
* }")
*/
public function get()
{
}
}
- 创建执行生成API文档/在您的项目根目录创建一个名为apidoc.php的文件,如下所示
# apidoc.php
<?php
require_once "vendor/autoload.php";
$api = new \ApiDoc\ApiDocBuilder();
//第一个参数为当前需要生成文档的类地址
//第二个参数为生成的API文件目录
//第三个参数为当前文件生成后的标题
//第四个参数为API文件名需加上后缀
//第五个参数为API文件的访问完整域名
//第六个参数为查看全部API的密码
$api->buildApiDoc(['ApiDoc\TestApi'],__DIR__ . '/apidocs/','测试API平台','api.html','apidocs/api.html','hello');
echo '创建完成';
- 然后通过CLI执行它
$ php apidoc.php
可用方法/函数注释
- @ApiDescription(section="...", description="...")
- @ApiMethod(type="(get|post|put|delete|patch")
- @ApiRoute(name="...")
- @ApiParams(name="...", type="...", nullable=..., description="...", [sample=".."])
- @ApiHeaders(name="...", type="...", nullable=..., description="...")
- @ApiReturnHeaders(sample="...")
- @ApiReturn(type="...", sample="...")
- @ApiBody(sample="...")
ps:无法展示图片,示例不展示。无论是tp还是laravel等等都可以使用该框架,这套主要用于做开放平台使用