多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## Definition请求类型 在我们编写API文档时经常会遇到一些API的内容是重复的,现在我们就来学习如何抽取可以重新定义的内容,定义模型,来简化我们的文档。 示例1: 在index.php中的代码如下: ``` /** * @SWG\Response(response="200",description="ok",@SWG\Schema(ref="#/definitions/index")) */ ``` 实现自定义definition ``` /** * @SWG\Definition(definition="index",example={"code"=100,"data"={},"msg"="string"}) */ ``` 当然我们也可以通过定义一个类的方式来实现 示例2: 我们新建一个Definition.php ``` /** * @SWG\Definition() * @package app\index\controller */ class Definition{ /** * @SWG\Property(example=0) */ protected $code; /** * @SWG\Property(example={}) */ protected $data; /** * @SWG\Property(example="string") */ protected $msg; public function index($result){ } } ```