|
1 | 1 | # API Doctor Swagger for Laravel (Auto Generator).
|
2 |
| -A swagger OpenApi Documentation generator for laravel. This package **requires no phpDoc comments** |
| 2 | +A swagger OpenApi Documentation auto generator for laravel. This package **requires no phpDoc or any kind of comments** |
3 | 3 | <p align="left"> <img src="https://komarev.com/ghpvc/?username=laravel-api-doctor-swagger&label=Views&color=0e75b6&style=flat" alt="niamulhasan" /> </p>
|
4 | 4 |
|
5 |
| -## About |
6 |
| -All other swagger packages require you to write phpDoc comments. This package is different. It will generate swagger documentation from your routes and controllers. |
| 5 | +## Motivation |
| 6 | +When I was trying to generate swagger documentation for my laravel project, I found that all the available packages require you to write phpDoc or other form of comments. |
| 7 | +I didn't want to write comments for all my routes and controllers. as it is time-consuming and I am lazy. And the documentation gets outdated very quickly creating a maintenance headache and a source of inconsistency. |
| 8 | +So I decided to create a package that will generate the swagger documentation from the routes and controllers automatically without any form of comments. |
| 9 | + |
| 10 | +## Features |
| 11 | +- Generates swagger documentation automatically from the routes and controllers. |
| 12 | +- No need to write phpDoc or any other form of comments. |
| 13 | +- Generates documentation for URL parameters. |
| 14 | +- Generates documentation for Request body using the `Form Request` type. |
| 15 | + |
| 16 | +## Limitations |
| 17 | +- Currently, response documentation is not generated. |
| 18 | +- File upload and multipart form data are not supported. |
| 19 | + |
7 | 20 |
|
8 | 21 | ## Installation
|
9 | 22 | ### Step 1: Add these lines to your .env file
|
@@ -46,32 +59,45 @@ Example:
|
46 | 59 | }
|
47 | 60 | ```
|
48 | 61 |
|
| 62 | +### Step 3: Set the minimum stability |
49 | 63 | Set the `"minimum-stability": "dev"` in composer.json
|
50 | 64 |
|
51 |
| -### Step 3: Install the package |
| 65 | +### Step 4: Install the package |
52 | 66 | Then run the following command to install the package:
|
53 | 67 | ```bash
|
54 | 68 | composer require niamulhasan/api-doctor-swagger
|
55 | 69 | ```
|
56 |
| -### Step: 4 Edit your `config/app.php` file (Laravel 11 `bootstrap/providers.php`) |
| 70 | +### Step: 5 Add the provider |
57 | 71 | Add the following line to the `providers` array:
|
58 | 72 | ```php
|
59 | 73 | NiamulHasan\ApiDoctorSwagger\Providers\ApiDoctorProvider::class,
|
60 | 74 | ```
|
| 75 | + |
| 76 | +You can find the providers in `config/app.php` file |
| 77 | +for Laravel 11 it's in the `bootstrap/providers.php` file. |
| 78 | + |
61 | 79 | This will register the package's service provider for your project.
|
62 | 80 |
|
63 | 81 | ### Step 5: Publish the package's config file
|
64 | 82 | Run the following command to publish the package's config file:
|
| 83 | +```bash |
| 84 | +php artisan vendor:publish --provider="NiamulHasan\ApiDoctorSwagger\Providers\ApiDoctorProvider" |
| 85 | +``` |
65 | 86 |
|
66 |
| -### Step 6: If you face csrf_token missmatch issue |
| 87 | +### Step 6: Turn off CSRF protection for the API routes |
| 88 | +If you face csrf_token missmatch issue |
67 | 89 |
|
68 | 90 | `protected $except = [
|
69 | 91 | 'api/*'
|
70 | 92 | ];`
|
71 |
| -add this in your `app/Http/Middleware/VerifyCsrfToken.php` |
| 93 | +add this in your `app/Http/Middleware/VerifyCsrfToken.php` file |
72 | 94 |
|
73 |
| -#### For Laravel 11: in `bootstrap/app.php` |
74 |
| -add `$middleware->validateCsrfTokens(except: ['api/*']);` in middleware |
| 95 | +#### For Laravel 11: in `bootstrap/app.php` file |
| 96 | +add this |
| 97 | +```php |
| 98 | +$middleware->validateCsrfTokens(except: ['api/*']); |
| 99 | +``` |
| 100 | +in middleware |
75 | 101 | Like this
|
76 | 102 | ```php
|
77 | 103 | ->withMiddleware(function (Middleware $middleware) {
|
@@ -124,3 +150,8 @@ http://your-project-url/swagger-yaml-file-generated
|
124 | 150 |
|
125 | 151 | ## Conclusion
|
126 | 152 | This package is being developed for my own projects. I will be adding more features to it as I need them. If you have any suggestions or find any bug please feel free to open an issue or a pull request.
|
| 153 | + |
| 154 | +## Conclusion |
| 155 | +This package has been developed for our own needs. |
| 156 | +I will be adding more features and improvements to it as I need them. |
| 157 | +Feel free to open an issue or a pull request for bug fixes or new features. |
0 commit comments