Я хочу интегрировать Генератор документации Laravel API для генерации документов.Я пытался с помощью следующего кода нет параметра запроса в документации.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\ACMRolesModel;
use App\Utility;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
/**
* @resource ACM Roles
*
* This API manage roles for Access Control
*/
class ACMRolesController extends Controller
{
public $successStatus = 200;
public $errorStatus = 400;
/**
*List of roles
*This api use to get all role
*
* @param Request None
* @return Response
*/
public function getAllRole(){
$result = ACMRolesModel::all()->count();
if($result) {
$result=ACMRolesModel::all();
return Utility::sendResponse('success',$result,$this->successStatus);
}
else{
return Utility::sendResponse('success',['Sorry, there is no role in available!'],$this->errorStatus);
}
}
/**
* Get Role API
*
* @Post("/")
* @Versions({"v1"})
* @Transaction({
* @Response(200, body={{
* "message": "success",
*"data": {
"id": 4,
"name": "Super Admin",
"description": "User have all permission",
"deleted_at": null,
"uuid": "a6536264-6a01-4196-b63a-9df23ab6a087",
"created_at": "2018-10-04 10:26:55",
"updated_at": null
}
} })
* })
* @Parameters({
* @Parameter("uuid", type="string", required=true, description="Unique id to get role")
* })
*/
public function viewRoleDetail(Request $request){
$validator = Validator::make($request->all(), [
'id' => 'required'
]);
if ($validator->fails()) {
return Utility::sendResponse('Id is required paremeter.',$validator->errors()->all(),$this->errorStatus);
//return response()->json(['error'=>$validator->errors()], $this->unauthenticatedStatus);
}
$result = ACMRolesModel::where('uuid', $request->id)->first();
if(!$result) {
return Utility::sendResponse('success',['No role match.'],$this->errorStatus);
}
else{
return Utility::sendResponse('success',$result,$this->successStatus);
}
}
/**
* Create Role
*
* This api used to create normal users. Only users which have api token can acces this api
* Users who have app account can have api token
*
* @param Request $request
* @return json response
* @rules title = required|max:255
*
*/
public function createRole(Request $request){
$this->rules();
$validator = Validator::make($request->all(), [
'name' =>'required',
'description'=>'required'
]);
if ($validator->fails()) {
return Utility::sendResponse('Error with perameter.',$validator->errors()->all(),$this->errorStatus);
}
$role = new ACMRolesModel();
$role->name=$request->name;
$role->description=$request->description;
$role->is_active=$request->isactive;
$role->uuid=(string) Str::uuid();
$result = $role->save();
if(!$result) {
return Utility::sendResponse('success',['No role match.'],$this->errorStatus);
}
else{
return Utility::sendResponse('success',['Role created success fully'],$this->successStatus);
}
}
/**
* Update Role
* This api use to update existing role
*
*
* @param Request $request
* @return Response
*/
public function updateRole(Request $request){
$this->rules();
$validator = Validator::make($request->all(), [
'name' =>'required',
'description'=>'required',
'uuid'=>'required',
'isactive' =>'required'
]);
if ($validator->fails()) {
return Utility::sendResponse('Error with perameter.',$validator->errors()->all(),$this->errorStatus);
}
$role = ACMRolesModel::firstOrFail()->where('uuid','=',$request->uuid);
$role->name=$request->name;
$role->description=$request->description;
$role->is_active=$request->isactive;
$role->uuid=(string) Str::uuid();
$result = $role->save();
if(!$result) {
return Utility::sendResponse('success',['No role match.'],$this->errorStatus);
}
else{
return Utility::sendResponse('success',['Role created success fully'],$this->successStatus);
}
}
/**
* This api use to create new role
*
*
* @param Request $request
* @return Response
*/
public function DeleteRole(Request $request){
$validator = Validator::make($request->all(), [
'name' =>'required',
'description'=>'required',
'uuid'=>'required',
'isactive' =>'required'
]);
if ($validator->fails()) {
return Utility::sendResponse('Error with perameter.',$validator->errors()->all(),$this->errorStatus);
}
$role = ACMRolesModel::firstOrFail()->where('uuid','=',$request->uuid);
$role->name=$request->name;
$role->description=$request->description;
$role->is_active=$request->isactive;
$role->uuid=(string) Str::uuid();
$result = $role->save();
if(!$result) {
return Utility::sendResponse('success',['No role match.'],$this->errorStatus);
}
else{
return Utility::sendResponse('success',['Role created success fully'],$this->successStatus);
}
}
public function rules()
{
return [
'title' => 'required|max:255',
'body' => 'required',
'type' => 'in:foo,bar',
'thumbnail' => 'required_if:type,foo|image',
];
}
}