Download the PHP package energon7/laravel-swagger-docs without Composer
On this page you can find all versions of the php package energon7/laravel-swagger-docs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-swagger-docs
Laravel Swagger Docs
Simple to use OAS3 compatible documentation generator.
Also includes Swagger UI.
About
This package is heavily inspired by the darki73/laravel-swagger and kevupton/laravel-swagger.
Usage is pretty similar to the mtrajano/laravel-swagger with the difference being:
- OAS3 support
- Custom decorators
- Custom responses
- Automatic generation (assuming relevant configuration option is turned on)
- Inclusion of Swagger UI
- Models generations
- Generate operation tags based on route prefix or controller's name
Installation
Install package through composer
Publish configuration files and views
Edit the swagger.php
configuration file for your liking
Usage
Laravel Swagger Docs 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.
Command line
Generating the swagger documentation is easy, simply run php artisan swagger:generate
in your project root. The output of the command will be stored in your storage path linked in config file.
If you wish to generate docs for a subset of your routes, you can pass a filter using --filter
, for example: php artisan swagger:generate --filter="/api"
You can also configure your swagger.php file to always generate schema when accessing Swagger UI or just by adding this line in your .env: SWAGGER_GENERATE_ALWAYS=true
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
@Request() decorator
You can have only one @Request()
decorator.
@Response() decorator
You can have multiple @Response
decorators
- The
code
property is required and must be the first in propery - You can use the optional
description
property to desscribe your response - You can use the optional
ref
property to refer a model, you can also wrap that model in [] to refer an array of that model or use the full model path inside, finally you can use a schema builder
Note: You can see all available schema builder or create your own schema builder, explore swagger.schema_builders config for more informations.
Custom Validators
These validators are made purely for visual purposes, however, some of them can actually do validation
swagger_default
swagger_min
swagger_max
All versions of laravel-swagger-docs with dependencies
doctrine/dbal Version *
phpdocumentor/reflection-docblock Version ^5.2