Download the PHP package vanyabrovary/laravel-swagger without Composer
On this page you can find all versions of the php package vanyabrovary/laravel-swagger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vanyabrovary/laravel-swagger
More information about vanyabrovary/laravel-swagger
Files in vanyabrovary/laravel-swagger
Package laravel-swagger
Short Description froked from mtrajano/laravel-swagger. Auto generates the swagger documentation for a laravel project
License MIT
Informations about the package laravel-swagger
Laravel Swagger
FORKED FROM mtrajano/laravel-swagger
Laravel Swagger scans your Laravel project's endpoints and auto generates a Swagger 2.0 documentation for you.
About
Laravel Swagger works based on recommended practices by Laravel. It will parse your routes and generate a path object for each one. If you inject Form Request classes in your controller's actions as request validation, it will also generate the parameters for each request that has them. For the parameters, it will take into account wether the request is a GET/HEAD/DELETE or a POST/PUT/PATCH request and make its best guess as to the type of parameter object it should generate. It will also generate the path parameters if your route contains them. Finally, this package will also scan any documentation you have in your action methods and add it as summary and description to that path, along with any appropriate annotations such as @deprecated.
One thing to note is this library leans on being explicit. It will choose to include keys even if they have a default. For example it chooses to say a route has a deprecated value of false rather than leaving it out. I believe this makes reading the documentation easier by not leaving important information out. The file can be easily cleaned up afterwards if the user chooses to leave out the defaults.
Installation
The package can easily be installed by running composer require vanyabrovary/laravel-swagger
in your project's root folder.
If you are running a version of Laravel < 5.5 also make sure you add Vanyabrovary\LaravelSwagger\SwaggerServiceProvider::class
to the providers
array in config/app.php
.
This will register the artisan command that will be available to you.
You can also override the default config provided by the application by running php artisan vendor:publish --provider "Vanyabrovary\LaravelSwagger\SwaggerServiceProvider"
in your projects root and change the configuration in the new config/laravel-swagger.php
file created.
Usage
Generating the swagger documentation is easy, simply run php artisan laravel-swagger:generate
in your project root. Keep in mind the command will simply print out the output in your console. If you want the docs saved in a file you can reroute the output like so: php artisan laravel-swagger:generate > swagger.json
If you wish to generate docs for a subset of your routes, you can pass a filter using --filter
, for example: php artisan laravel-swagger:generate --filter="/api"
By default, laravel-swagger prints out the documentation in json format, if you want it in YAML format you can override the format using the --format
flag. Make sure to have the yaml extension installed if you choose to do so.
Format options are:
json
yaml
Example
Say you have a route /api/users/{id}
that maps to UserController@show
Your sample controller might look like this:
And the FormRequest class might look like this:
Running php artisan laravel-swagger:generate > swagger.json
will generate the following file: