功能:
1 swagger-php根据自定义的规则生成api请求规则,通过phar生成json文件
2 打开swagger-ui/dist/index.html。输入json文件夹目录地址(需要同源),swagger-ui会根据请求的json生成api,页面很漂亮。输入请求参数后执行会获取返回值。
缺点:不能对返回的数据进行验证。功能类似chrome的插件postman。
api action测试参考代码:
resource/postaction.php
java代码 收藏代码
/**
* @swg\resource(
* apiversion=2.2.0,
* swaggerversion=1.2,
* basepath=http://test.xxx.com/api/post,
* resourcepath=/post,
* description=operations about post,
* produces=['application/json']
* )
*/
/**
* @swg\api(
* path=/apps,
* @swg\operation(
* method=post,
* summary=find app by buid,
* notes=returns apps based on buid,
* type=post,
* nickname=apps,
* authorizations={},
* @swg\parameter(
* name=apiversion,
* description=api version,
* required=true,
* type=integer,
* format=int64,
* paramtype=form,
* minimum=1.0,
* allowmultiple=false
* ),
* @swg\parameter(
* name=sessionid,
* description=user login session,
* required=true,
* type=string,
* paramtype=form,
* defaultvalue=9f6cdd0858a1e93b1426659b283a93ec,
* allowmultiple=false
* ),
* @swg\parameter(
* name=buid,
* description=bu id,
* required=true,
* type=int64,
* paramtype=form,
* allowmultiple=false
* ),
* @swg\responsemessage(code=400, message=invalid id supplied),
* @swg\responsemessage(code=404, message=post not found),
* @swg\responsemessage(code=405, message=invalid input),
* @swg\responsemessage(code=200, message=success)
* )
* )
*/
项目描述信息
info/api.php
java代码 收藏代码
/**
* @swg\info(
* title=my project,
* description= xxx,
* )
*
*/
readme
java代码 收藏代码
# usage of api docs
### raw spec structure
* info - general info.
* model - entity class
* resource - api endpoint
### compile api info.
* after modify the spec, run shell script, as follows.
`cd api-docs`
`./gendocumentation.sh`
* the compiled content (.json) is stored in documentation/output/
### view api docs
* visit http://{domain}/documenation/
sh 执行文件
java代码 收藏代码
#!/bin/sh
../swagger-php/swagger.phar ../output-docs -o ../documentation/output/