Swagger中的Laravel(发布,删除,放置)路线 [英] Laravel (Post, Delete, Put) routes in Swagger

查看:393
本文介绍了Swagger中的Laravel(发布,删除,放置)路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经更新了get方法的代码,如下所示可以正常工作 昂首阔步.

I have update the code for get method as follows which working properly in swagger.

任何人都可以建议我用它的Laravel路线张贴,张贴,删除的摇头代码,控制器代码. (正如我在GET中提到的那样)

Can any one please suggest me the swagger code for post, put, delete with its laravel route, controller code. (As I mention follows for GET)

route/web.php

route/web.php

        Route::group(['prefix' => 'api/'], function () {
           Route::get('dashboard', 'DashboardController@index');
        });

DashboardController.php

DashboardController.php

 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\JsonResponse
 *
 * @SWG\Get(
 *     path="/api/dashboard",
 *     description="Returns dashboard overview.",
 *     operationId="api.dashboard.index",
 *     produces={"application/json"},
 *     tags={"dashboard"},
 *     @SWG\Response(
 *         response=200,
 *         description="Dashboard overview."
 *     ),
 *     @SWG\Response(
 *         response=401,
 *         description="Unauthorized action.",
 *     )
 * )
 */

public function index(Request $request)
{
    return response()->json([
        'result'    => [
            'statistics' => [
                'users' => [
                    'name'  => 'Name',
                    'email' => 'user@example.com'
                ]
            ],
        ],
        'message'   => '',
        'type'      => 'success',
        'status'    => 0
    ]);
}  

推荐答案

用于拉长Post/Put/Delete的小laravel路线.

Route::post('/api/user', 'DashboardController@store');
Route::put('/api/user/{user_id}', 'DashboardController@edit');
Route::delete('/api/user/{user_id}', 'DashboardController@delete');
Route::get('/api/users', 'DashboardController@getData');
Route::get('/api/user/{user_id}', 'DashboardController@getDataById');

用于发布

   /**
     * @SWG\Post(
     *      path="/api/user",
     *      tags={"User"},
     *      operationId="ApiV1saveUser",
     *      summary="Add User",
     *      consumes={"application/x-www-form-urlencoded"},
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="name",
     *          in="formData",
     *          required=true, 
     *          type="string" 
     *      ),
     *      @SWG\Parameter(
     *          name="phone",
     *          in="formData",
     *          required=true, 
     *          type="number" 
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="Success"
     *      ),
     */

认沽权

   /**
     * @SWG\Put(
     *      path="/api/user/{user_id}",
     *      tags={"User"},
     *      operationId="ApiV1UpdateUser",
     *      summary="Update User",
     *      consumes={"application/x-www-form-urlencoded"},
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="user_id",
     *          in="path",
     *          required=true, 
     *          type="string" 
     *      ),
     *      @SWG\Parameter(
     *          name="name",
     *          in="formData",
     *          required=true, 
     *          type="string" 
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="Success"
     *      ),
     */

用于按ID删除

   /**
     * @SWG\Delete(
     *      path="/api/users",
     *      tags={"User"},
     *      operationId="ApiV1DeleteUser",
     *      summary="Delete User",
     *      @SWG\Parameter(
     *          name="user_id",
     *          in="path",
     *          required=true, 
     *          type="string" 
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="Success"
     *      ),
     */

获取

    /**
     * @SWG\Get(
     *      path="/api/users",
     *      tags={"User"},
     *      operationId="ApiV1GetUsers"
     *      summary="Get Users",
     *      @SWG\Response(
     *          response=200,
     *          description="Success"
     *      ),
     */

用于获取ID

    /**
     * @SWG\Get(
     *      path="/api/user/{user_id}",
     *      tags={"User"},
     *      operationId="ApiV1GetUserById",
     *      summary="Get User by user id",
     *      @SWG\Parameter(
     *          name="user_id",
     *          in="path",
     *          required=true, 
     *          type="string" 
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="Success"
     *      ),
     */

这篇关于Swagger中的Laravel(发布,删除,放置)路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆