Swagger GET Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/** * @SWG\Get( * path="/api/testing/{mytest}", * summary="Get Testing", * operationId="testing", * @SWG\Response(response=200, description="successful operation"), * @SWG\Response(response=406, description="not acceptable"), * @SWG\Response(response=500, description="internal server error"), * @SWG\Parameter( * name="mytest", * in="path", * required=true, * type="string" * ), * ) * */ public function index(Request $request){ echo $request->mytest; } |
Swagger POST Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/** * @SWG\Post( * path="/api/admin/update_password", * tags={"Admin"}, * security={ * {"passport": {}}, * }, * summary="Update password", * operationId="update password", * @SWG\Response(response=200, description="successful operation"), * @SWG\Response(response=406, description="not acceptable"), * @SWG\Response(response=500, description="internal server error"), * @SWG\Parameter( * name="Parameters", * in="body", * description="Update all parameters", * required=true, * type="string", * @SWG\Schema(@SWG\Property(property="userid", type="string", example="123"), @SWG\Property(property="password", type="string", example="abc123")), * ) * ) * */ public function update_password(Request $request){ echo "userid:".$request->userid; echo "<br>"; echo "password:".$request->password; } |
Swagger PUT Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/** * * @SWG\Put( * path="/update_user", * tags={"users"}, * security={ * {"passport": {}}, * }, * summary="Update user entry", * operationId="update password", * @SWG\Response(response=200, description="successful operation"), * @SWG\Response(response=406, description="not acceptable"), * @SWG\Response(response=500, description="internal server error"), * @SWG\Parameter( * name="Parameters", * in="body", * description="Update all parameters", * required=true, * type="string", * @SWG\Schema(@SWG\Property(property="userid", type="string", example="123"), @SWG\Property(property="name", type="string", example="abcd"), @SWG\Property(property="email", type="string", example="[email protected]"), @SWG\Property(property="phone", type="string", example="+123123123")), * ) * ) * */ public function update_user(Request $request){ echo "userid:".$request->userid; echo "<br>"; echo "name:".$request->name; echo "<br>"; echo "email:".$request->email; echo "<br>"; echo "phone:".$request->phone; } |
Swagger DELETE Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/** * * @SWG\Delete( * path="/delete_user", * tags={"users"}, * security={ * {"passport": {}}, * }, * summary="Update user entry", * operationId="update password", * @SWG\Response(response=200, description="successful operation"), * @SWG\Response(response=406, description="not acceptable"), * @SWG\Response(response=500, description="internal server error"), * @SWG\Parameter( * name="Parameters", * in="body", * description="Update all parameters", * required=true, * type="string", * @SWG\Schema(@SWG\Property(property="userid", type="string", example="123"), @SWG\Property(property="parameter", type="string", example="abc123")), * ) * ) * */ public function delete_user(Request $request){ echo "userid:".$request->userid; echo "<br>"; echo "parameter:".$request->parameter; } |
If any error come in swagger and not able to fix, you can find the swagger issue by below command
1 |
php artisan l5-swagger:generate |
Leave a reply