Swagger 中的 Laravel(发布、删除、放置)路由

2024-05-02

我已经更新了 get 方法的代码,如下所示,它可以正常工作 大摇大摆地。

任何人都可以向我推荐用于发布、放置、删除的 swagger 代码及其 laravel 路由、控制器代码。 (正如我在 GET 中提到的)

路线/web.php

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

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' => '[email protected] /cdn-cgi/l/email-protection'
                ]
            ],
        ],
        'message'   => '',
        'type'      => 'success',
        'status'    => 0
    ]);
}  

用于 swagger 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');

For Post

   /**
     * @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"
     *      ),
     */

For Put

   /**
     * @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"
     *      ),
     */

For Get

    /**
     * @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"
     *      ),
     */
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Swagger 中的 Laravel(发布、删除、放置)路由 的相关文章

随机推荐