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

swagger document passing JWT token #17

Closed weretyczx closed 4 years ago

weretyczx commented 4 years ago

Hi, me again. hahaha, have some problem here, some api needs to passing token, and for now, the generated document structural have't been support yet, have u consider to implement this issue by reading the middleware?

Route::group(['middleware' => ['auth:admin','jwt.auth']], function ($router) { 
  // and the following route document will add the input block to fill token 
  // to recognized authenticate route, can add a suffix to the title ' - (token required) '
})

After all, in order to persist the route nicely read, the less work to optimize the document can adding a artisan command option --sort, so the related api will generate together.

thanks !

mtrajano commented 4 years ago

Hey, this is an interesting idea. I think it would be difficult parsing every single middleware and guessing which ones are auth and what auth method they use, unless there was some sort of mapping for middleware name => what it means. But I can at least look into supporting this if the app is using Passport and whatever convention it uses. Need to think about this one a little more. Thanks for the suggestion!

mtrajano commented 4 years ago

Pushed out a decent solution for this if the consuming application is using Passport: https://github.com/mtrajano/laravel-swagger/pull/23 and https://github.com/mtrajano/laravel-swagger/commit/463320d4c26ddd762f5856dddf914421625d6e0d. If following the documentation given in: https://laravel.com/docs/5.8/passport including registering the Passport routes and middleware this should correctly generate the securityDefinitions and add the correct scopes to each operation object. Please pull down dev-master and let me know if that works for you. Feel free to submit a pr if you think you can make any improvements, thanks!