## 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){
}
}
```