PHPackages                             ronasit/laravel-swagger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ronasit/laravel-swagger

ActiveLibrary[API Development](/categories/api)

ronasit/laravel-swagger
=======================

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

3.2.7(1mo ago)180132.3k↓42.2%49[10 issues](https://github.com/RonasIT/laravel-swagger/issues)[5 PRs](https://github.com/RonasIT/laravel-swagger/pulls)2MITPHPPHP ^8.3CI passing

Since Apr 5Pushed 2w ago9 watchersCompare

[ Source](https://github.com/RonasIT/laravel-swagger)[ Packagist](https://packagist.org/packages/ronasit/laravel-swagger)[ RSS](/packages/ronasit-laravel-swagger/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (14)Versions (102)Used By (2)

[![](resources/assets/images/hero.svg)](resources/assets/images/hero.svg)

Laravel Swagger plugin
======================

[](#laravel-swagger-plugin)

[![Total Downloads](https://camo.githubusercontent.com/3053dfa7e7008ce9f296f7da58575458ebdb2389d938c18efe784d20124e6029/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6e617369742f6c61726176656c2d73776167676572)](https://packagist.org/packages/ronasit/laravel-swagger)[![Latest Stable Version](https://camo.githubusercontent.com/67f6658d2ee803bb80d81939cdad100f4b49bdf3f94ab6d319639253a1aeca0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6e617369742f6c61726176656c2d73776167676572)](https://packagist.org/packages/ronasit/laravel-swagger)[![License](https://camo.githubusercontent.com/d02ffd695fef91c41ef4bf81a341dfd4b31f570dc2a714677bd15fb91cd20ac3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726f6e617369742f6c61726176656c2d73776167676572)](https://packagist.org/packages/ronasit/laravel-swagger)

[![Laravel Swagger](https://github.com/RonasIT/laravel-swagger/actions/workflows/laravel.yml/badge.svg?branch=master)](https://github.com/RonasIT/laravel-swagger/actions/workflows/laravel.yml)[![Coverage Status](https://camo.githubusercontent.com/10164aacc0fc3db31fcc76b7488c1a4f05f344e51210c0d5ad2c69b291df4182/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f526f6e617349542f6c61726176656c2d737761676765722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/RonasIT/laravel-swagger?branch=master)

Comparison to another documentation generators
----------------------------------------------

[](#comparison-to-another-documentation-generators)

LaravelSwagger[Scramble](https://github.com/dedoc/scramble)Force developers to write tests✅❌Guarantee that API works✅❌Works with any route types covered by tests✅❌Generate response schema using JSON Resource class❌✅Runtime documentation generation❌✅Introduction
------------

[](#introduction)

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

Installation
------------

[](#installation)

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

> ***Note***
>
> 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' => [
>     ...
>     RonasIT\AutoDoc\AutoDocServiceProvider::class,
> ],
> ```

2. Run

```
php artisan vendor:publish --provider=RonasIT\\AutoDoc\\AutoDocServiceProvider

```

3. Add `\RonasIT\AutoDoc\Http\Middleware\AutoDocMiddleware::class` middleware to the global HTTP middleware list `bootstrap\app.php`:

```
    return Application::configure(basePath: dirname(__DIR__))
        ->withMiddleware(function (Middleware $middleware) {
            $middleware->use([
                ...
                \RonasIT\AutoDoc\Http\Middleware\AutoDocMiddleware::class,
            ]);
        });
```

4. Add `\RonasIT\AutoDoc\Traits\AutoDocTestCaseTrait` trait to `tests/TestCase.php`
5. Configure documentation saving using one of the next ways:

- Add `SwaggerExtension` to the `` block of your `phpunit.xml`. **Please note that this way will be removed after updating****PHPUnit up to 10 version ([sebastianbergmann/phpunit#4676](https://github.com/sebastianbergmann/phpunit/issues/4676))**

```

            ./tests/Feature

```

- Call `php artisan swagger:push-documentation` console command after the `tests` stage in your CI/CD configuration

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

1. Create request class:

    ```
