mtrajano / laravel-swagger

Auto generates the swagger documentation of a laravel project based on best practices and simple assumptions
167 stars 71 forks source link

[Proposal] Get additional middlewares defined on controllers #50

Open rogervila opened 3 years ago

rogervila commented 3 years ago

Description:

Hello,

Right now, the Generator checks if a specific route has a Passport middleware on the route definition only.

https://github.com/mtrajano/laravel-swagger/blob/master/src/Generator.php#L173

Middlewares can also be defined on the Controllers. I think that the Generator should also scan them to get additionally defined middlewares.

Example:

// Route
Route::get('/something', MyController::class);

// Controller
class MyController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:api');
    }
}

// If we call
app('App\Http\Controllers\API\MyController')->getMiddleware()

// returns

   [
     [
       "middleware" => "auth:api",
       "options" => [],
     ],
   ]

If you agree I can work on a PR that adds this functionality.

Thank you,

rogervila commented 3 years ago

@mtrajano The 'bug' label has been added automatically but is only a proposal

mtrajano commented 3 years ago

Hey yes this makes sense to me, there should be a helper method getMiddleware that retrieves all the middleware it can gather, whether it comes from the routes, controllers, etc.. A pr would be appreciated, let me know if you need help with implementation or tests

rogervila commented 3 years ago

Hey yes this makes sense to me, there should be a helper method getMiddleware that retrieves all the middleware it can gather, whether it comes from the routes, controllers, etc.. A pr would be appreciated, let me know if you need help with implementation or tests

OK, I'll open a PR as soon as I can