DEV Community

Cover image for Laravel Api Documentation with Swagger and Passport

Laravel Api Documentation with Swagger and Passport

Abishek Dongol on June 11, 2020

First, let’s see what we are going to have in this article: Brief introduction about Swagger and its Importance. Install and configure Laravel wi...
Collapse
 
aysegeertsma profile image
Ayse Geertsma

Thanks for this. Have been using swagger in Symfony. This is a nice introduction into laravel.

I have found some errors in the router

Route::post('v1/user-login', 'API\ V1\AuthController@login');

should be without a space:

Route::post('v1/user-login', 'API\V1\AuthController@login');

Further you introduced the namespace App\Http\Controllers\API\Mobile\V1 but reference to it without the Mobile part.

Lastly, my default laravel doesn't seem to have a field mobile_number in it.

Collapse
 
miguel_rr profile image
Rodriguez Miguel

It is a good tutorial, but I would add that it is necessary to add the ui for login.
I fixed it after running the following commands and comment this line
'title' => 'Integration Swagger in Laravel with Passport Auth',

composer require laravel/ui

// Generate basic scaffolding...(any of these)
php artisan ui bootstrap
php artisan ui vue
php artisan ui react

// Generate login / registration scaffolding...(any of these)
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth

npm install
npm run dev

Collapse
 
jerry2491 profile image
jerry2491

I am using swagger(8.0) with Laravel(8.40). Everything is fine but not able to create dynamic url for the swagger documentation. It always create documentation with 127.0.0.1:8000/api/docs. I want dynamic host so that I can also share this documentation with others after upload my project on the live server.

Collapse
 
kvinay3 profile image
kvinay3

instead of using passport i want to use my jwt token in header but i want user to add email / password in auth modal and the token should automatically set to header,
we do not want user to copy and paste the token in auth modal manually, when using apiKey securitySchemes
is that possible to achieve
dev-to-uploads.s3.amazonaws.com/up...
dev-to-uploads.s3.amazonaws.com/up...

refer 2nd screenshot i want to set token automatically here
or if possible provide email / password input and after response add that into header

Collapse
 
milantarami profile image
Milan Tarami • Edited

why are you sending form data as query parameter in POST request

Collapse
 
brnathanlima profile image
Nathanael Lima

I asked the same question to myself. I'm now looking for how to move it to the request body. Have you find out?

Collapse
 
milantarami profile image
Milan Tarami

You can achieve from the following example

post data

Thread Thread
 
brnathanlima profile image
Nathanael Lima

Thank you buddy!!

Collapse
 
akashkaintura profile image
AKASH KAINTURA

Not working for Laravel 8

Collapse
 
lorddubbs profile image
lorddubbs

Sweet, you can do for Laravel Sanctum next.

Collapse
 
darshanmultiqos profile image
darshanmultiqos

in laravel 8 getting on thi command
php artisan l5-swagger: generate

L5Swagger\Exceptions\L5SwaggerException

Documentation config not found
please help |

Collapse
 
farhanriuzaki profile image
Farhan Riuzaki

Halo, I have read your article..
but I have a problem because Authorize Button is not showing, how to fix that issue?

Collapse
 
ace113 profile image
ace113

Awesome!
Is there a plugin or an extension i can use to write these annotation quicker with vscode editor?

Collapse
 
bushmusi profile image
Bushra Mustofa

Guys I couldn't authorize, Where could i find username and password

Collapse
 
fahdshaykh profile image
fahd shaykh • Edited

after following the steps i run
composer require "darkaonline/l5-swagger"
i am getting this error,
Call to undefined method Laravel\Passport\Passport::routes()

i am following step by step.