# laravel-request > request层使用包 ## 1. pagination ### 1.1 swagger迁移 1. 删除api.php 下的参数定义 'pageSize','page'以及返回定义 'page' ``` /** * @OA\Schema( * schema="Page", * @OA\Property(property="current_page",type="integer",format="int32",description="当前页"), * @OA\Property(property="first_page_url",type="string",description="首页url"), * @OA\Property(property="last_page_url",type="string",description="最后url"), * @OA\Property(property="next_page_url",type="string",description="下一页地址"), * @OA\Property(property="prev_page_url",type="string",description="上一页地址"), * @OA\Property(property="path",type="string",description="url"), * @OA\Property(property="from",type="integer",description="从哪个过来的"), * @OA\Property(property="to",type="integer",description="下一页"), * @OA\Property(property="total",type="integer",description="总记录数"), * @OA\Property(property="last_page",type="integer",description="最后一页"), * @OA\Property(property="per_page",type="integer",format="int32",description="条数") * ) */ /** * @OA\Parameter( * parameter="page", * name="page", * description="当前页数", * @OA\Schema(type="integer",format="int64"), * in="query", * example="1" * ) * @OA\Parameter( * parameter="pageSize", * name="pageSize", * description="每页条数", * @OA\Schema(type="integer",format="int64"), * in="query", * example="10" * ) */ ``` 2. swagger文档添加参数 ``` Route::group([ 'prefix' => 'swagger', ], function () { Route::get('/', function () { echo app('swagger')->getJson([ ... //原有路径 base_path('vendor/yjtec/laravel-request/src/'), ]); }); }); ``` ### 1.2 request层使用 ``` use Yjtec\Request\Pagination\PageTrait; class RequestName{ use PageTrait; public function rules(){ return array_merge([ ...原有规则 ],$this->pageRules()) } ... public function attributes(){ return array_merge([ ...rules ],$this->pageAttributes()) } } ``` ### 1.3 resource定义携带pagination的返回 ``` /** * @OA\Schema( * schema="manageAccountListResponse", * type="object", * allOf={ * @OA\Schema(ref="#/components/schemas/Pagination"), * @OA\Schema( * @OA\Property( * property="data",type="array", * @OA\Items(ref="#/components/schemas/OtherDataResource") * ), * ) * } * ) */ ```