Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Get additional middlewares defined on controllers #50

Open
rogervila opened this issue Oct 5, 2020 · 3 comments
Open

[Proposal] Get additional middlewares defined on controllers #50

rogervila opened this issue Oct 5, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@rogervila
Copy link
Contributor

  • Laravel Swagger Version: dev-master
  • Laravel Version: 8.8.0
  • PHP Version: 7.4.11

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 rogervila added the bug Something isn't working label Oct 5, 2020
@rogervila
Copy link
Contributor Author

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

@mtrajano
Copy link
Owner

mtrajano commented Oct 6, 2020

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants