Download the PHP package digit-soft/laravel-swagger-generator without Composer
On this page you can find all versions of the php package digit-soft/laravel-swagger-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digit-soft/laravel-swagger-generator
More information about digit-soft/laravel-swagger-generator
Files in digit-soft/laravel-swagger-generator
Package laravel-swagger-generator
Short Description Swagger yaml generator
License MIT
Informations about the package laravel-swagger-generator
Swagger generator
This package is made to automate API documentation for Swagger (Open Auth 3.0)
Publish config
Usage
To generate doc file (YML) run following command:
To see problems with generation use diagnose
mode, where file will not be generated, only helpful information will be printed.
Describing your code
Annotations list
Name | Description | Places to use |
---|---|---|
@OA\Response | Describes raw response | Controller method |
@OA\ResponseParam | Describes response parameter in Response |
Inside {} of Response annotation |
@OA\ResponseClass | Describes response as class object | Controller method |
@OA\ResponseError | Describes error response (shortcut) | Controller method |
@OA\RequestBody | Describes request body | FormRequest class |
@OA\RequestBodyJson | Describes request body with application\json content type |
FormRequest class |
@OA\RequestParam | Describes request body parameter | Used as argument in @OA\RequestBody annotation |
@OA\RequestParamArray | Describes request body parameter. Shortcut for array type parameter | Used as argument in @OA\RequestBody annotation |
@OA\Parameter | Describes route parameter | Controller method, Controller class |
@OA\Property | Describes class property | Class used for response |
@OA\PropertyIgnore | Mark class property as ignored | Class used for response |
@OA\Secured | Describes route as secured | Controller method |
@OA\Tag | Describes route tags | Controller method, Controller class |
@OA\Ignore | Marks whole controller or it's action as ignored | Controller method, Controller class |
@OA\Symlink | Describes symlink to another class | Class used for response |
Responses
Responses are parsed only if explicitly documented by @Annotation
. It must be placed in PHPDoc of controller method that route use.
RAW response:
JSON RAW response:
or
Response from class properties:
In example above response data will be parsed from App\User
PHPDoc.
@property
descriptions (property name, type and description)@property-read
descriptions (if setwith
property inResponseClass
annotation)@OA\Property
annotations (property name, type, description, example etc.)
@OA\ResponseClass
use cases,
first is standard use but with additional properties
As items list
As paged items list
Error responses
Request bodies
Request data is parsed from ::rules()
method of FormRequest
class, that used in controller method for the route and it's annotations (@OA\RequestBody
, @OA\RequestBodyJson
, @OA\RequestParam
).
From ::rules()
method we can obtain only name and type of parameter and suggest some example,
but if you want fully describe parameters of request body you must place appropriate annotations in FormRequest
class for route.
Examples
Tags
Tags can be defined in Controller class or method that route uses.
Do not use space ` in tag names, link with such tag name will be broken in Swagger UI, so better idea to use dash
-or underscore
_, or even just a
CamelCased` tag names.
Tags defined in controller will be applied to ALL controller methods.
Secured
This annotation is used to mark route as secured
, and tells to swagger, that you must provide valid user credentials to access this route.
Place it in controller method.
Property
@OA\Property
annotation is used to describe class properties as an alternative or addition to PHPDoc @property
.
You can place example of property (if property is an associative array for example)
or fully describe property if you dont want to place @property
declaration for it.
PropertyIgnore
@OA\PropertyIgnore
annotation is used to remove given property from object description.
Symlink
This annotation can be used to describe symlink to another class (e.g. for response). All data in class PHPDoc in which it appears will be ignored.
You must use full namespace of annotations, e.g. OA\Property
.
Besides, you can import a namespace for better code completion as in example beyond.
More
There is abstract annotation class OA\DescriptionExtender
, you can use it for your own annotations, those must add some information to route's description.
Example is bellow.
You can use annotation from example:
and it will add following text into route's description
All versions of laravel-swagger-generator with dependencies
laravel/framework Version ^7.30.6||^8.75||^9.1.9||^10.0
symfony/yaml Version ^6.1
phpdocumentor/reflection-docblock Version ^4.3|^5.0
doctrine/annotations Version ^1.6