Provided middleware for generating of swagger-documentation file by run testing of restful API.



Laravel Swagger plugin

Total Downloads Latest Stable Version License


This plugin is designed to generate documentation for your REST API during the passing PHPUnit tests.


  1. Install the package using the following command: composer require ronasit/laravel-swagger


    For Laravel 5.5 or later the package will be auto-discovered. For older versions add the AutoDocServiceProvider to the providers array in config/app.php as follow:

    'providers' => [
       // ...
  2. Run php artisan vendor:publish

  3. Add \RonasIT\Support\AutoDoc\Http\Middleware\AutoDocMiddleware::class middleware to the global HTTP middleware stack in Http/Kernel.php.

  4. Add \RonasIT\Support\AutoDoc\Tests\AutoDocTestCaseTrait trait to tests/TestCase.php

  5. Configure documentation saving using one of the next ways:

  • Add SwaggerExtension to the <extensions> block of your phpunit.xml. Please note that this way will be removed after updating PHPUnit up to 10 version (sebastianbergmann/phpunit#4676)
        <extension class="RonasIT\Support\AutoDoc\Tests\PhpUnitExtensions\SwaggerExtension"/>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
  • Call php artisan swagger:push-documentation console command after the tests stage in your CI/CD configuration


Basic usage

  1. Create test for API endpoint:

    public function testUpdate()
        $response = $this->json('put', '/users/1', [
            'name': 'Updated User',
            'is_active': true,
            'age': 22
  2. Create request class:

    namespace App\Http\Requests;  
    use Illuminate\Foundation\Http\FormRequest;
    * @summary Update user
    * @description
    * This request should be used for updating the user data
    * @_204 Successful
    * @is_active will indicate whether the user is active or not
    class UpdateUserDataRequest extends FormRequest
         * Determine if the user is authorized to make this request.
         * @return bool
        public function authorize()
            return true;
         * Validation Rules
         * @return array
        public function rules()
            return [
                'name' => 'string',
                'is_active' => 'boolean',
                'age' => 'integer|nullable'


    For correct working of plugin you'll have to dispose all the validation rules in the rules() method of your request class. Also, your request class must be connected to the controller via dependency injection. Plugin will take validation rules from the request class and generate fields description of input parameter.

  3. Run tests

  4. Go to route defined in the auto-doc.route config

  5. Profit!



You can use the following annotations in your request classes to customize documentation of your API endpoints:

  • @summary - short description of request
  • @description - implementation notes
  • @_204 - custom description of response code. You can specify any code as you want.
  • @some_field - description of the field from the rules method


If you do not use request class, the summary and description and parameters will be empty.


  • auto-doc.route - route for generated documentation
  • auto-doc.basePath - root of your API

Custom driver

You can specify the way to collect documentation by creating your own custom driver.

You can find example of drivers here.


Thank you for considering contributing to Laravel Swagger plugin! The contribution guide can be found in the Contributing guide.


Laravel Swagger plugin is open-sourced software licensed under the MIT license.