PHPackages                             laxity7/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. laxity7/laravel-swagger

ActiveLibrary[API Development](/categories/api)

laxity7/laravel-swagger
=======================

Auto generates the swagger documentation for a laravel project

v1.0.6(2y ago)124MITPHP

Since Mar 27Pushed 2y agoCompare

[ Source](https://github.com/laxity7/laravel-swagger)[ Packagist](https://packagist.org/packages/laxity7/laravel-swagger)[ Docs](https://github.com/laxity7/laravel-swagger)[ RSS](/packages/laxity7-laravel-swagger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (24)Used By (0)

Laravel Swagger
===============

[](#laravel-swagger)

Laravel Swagger scans your Laravel project's endpoints and auto generates a Swagger 2.0 documentation for you.

[![Total Downloads](https://camo.githubusercontent.com/03a64af55730edb0751e271ddb49917531e1869f759b9cebb49b8035f8ac7347/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6178697479372f646f74656e762e737667)](https://packagist.org/packages/laxity7/laravel-swagger)[![Latest Stable Version](https://camo.githubusercontent.com/7cb29b9075c5c80c947ffe224c893fd5dcb4444ac09f123414a256e35639413d/68747470733a2f2f706f7365722e707567782e6f72672f6c6178697479372f6c61726176656c2d737761676765722f762f737461626c65)](https://packagist.org/packages/laxity7/laravel-swagger)[![License](https://camo.githubusercontent.com/83cef52d4a1c571be8a06fe8576e7fc435cc4b199feafa81ae8529046fd02152/68747470733a2f2f706f7365722e707567782e6f72672f6c6178697479372f6c61726176656c2d737761676765722f6c6963656e7365)](https://packagist.org/packages/laxity7/laravel-swagger)

About
-----

[](#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 whether 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. The file can be easily cleaned up afterward if the user chooses to leave out the defaults.

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

[](#installation)

The package can easily be installed by running `composer require laxity7/laravel-swagger` in your project's root folder.

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 "Laxity7\LaravelSwagger\SwaggerServiceProvider"` in your projects root and change the configuration in the new `config/laravel-swagger.php` file created.

Usage
-----

[](#usage)

Write code as you normally would, using the recommended practices by Laravel. This package will scan your routes and controllers and generate the documentation for you. 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 -o 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` (`-f`) flag. Make sure to have the yaml extension or `symfony/yaml` package installed if you choose to do so. By default, format options are: `json` or `yaml`. You can add your own format by adding a new class that implements the `Laxity7\LaravelSwagger\Generators\FormatGenerator` interface and add it to the `'formats'` array in the `config/laravel-swagger.php` file.

By default, prints out the documentation to the console, if you want it in a file, you can override the output using the `--output` (`-o`) flag.

### Usage in code

[](#usage-in-code)

You can also use the package in your code by using the `Laxity7\LaravelSwagger\Generator` class.

```
use Laxity7\LaravelSwagger\Generator;

$generator = new Generator();
$generator->generate();
```

Customization
-------------

[](#customization)

Custom request generators
-------------------------

[](#custom-request-generators)

You can add your own custom request generators to the package by adding a new class that implements the `Laxity7\LaravelSwagger\Parsers\Requests\Generators\ParameterParser` interface and add it to the `'parameterParsers'` array in the `config/laravel-swagger.php` file.

For example, let's say you have a custom request generator class called `App\Swagger\CustomBodyParameterGenerator`. You can add it to the `'parameterParsers'` array like this:

```
'parameterParsers' => [
    \Laxity7\LaravelSwagger\Parsers\Requests\Parameters\PathParameterParser::class,
    \Laxity7\LaravelSwagger\Parsers\Requests\Parameters\QueryParameterParser::class,
    \App\Swagger\CustomBodyParameterGenerator::class,
],
```

Example
-------

[](#example)

Your route file might look like this:

```
Route::get('/api/user/{id}', ['UserController', 'show']);
Route::get(
    '/api/user/{id}/check',
    /**
    * Check user exist
    * @param int $id User ID
    */
    fn(int $id) => User::where('id', $id)->exists();
);
```

Your sample controller might look like this:

```
use Laxity7\LaravelSwagger\Attributes\Request;

class UserController extends Controller
{
    /**
    *  Return all the details of a user
    *
    * Returns the user's first name, last name and address
    * Please see the documentation [here](https://example.com/users) for more information
    *
    * @deprecated
    *
    * @param int $id User ID
    */
    public function show(UserShowRequest $request, int $id)
    {
        return User::find($id);
    }

    /**
    * @request UserShowRequest
    */
    public function show(int $id)
    {
        $showRelationships = request()->get('show_relationships')
        return User::find($id);
    }

    #[Request(UserShowRequest::class)]
    public function show(int $id)
    {
        $showRelationships = request()->get('show_relationships')
        return User::find($id);
    }

    /**
    * @ignore
    */
    public function notShow(int $id)
    {
        return User::find($id);
    }
}
```

And the FormRequest class might look like this: The field description is taken from the property docblock or the property annotation from the class docblock.

```
use Illuminate\Foundation\Http\FormRequest;
/**
 * @property array $fields List of user fields
 */
class UserShowRequest extends FormRequest
{
    /** Is it necessary to show the relationship? */
    public $show_relationships;

    public function rules(): array
    {
        return [
            'fields' => 'array'
            'show_relationships' => 'boolean|required'
        ];
    }
}
```

Running `php artisan swagger:generate -o swagger.json` will generate the following file:

```
{
    "swagger": "2.0",
    "info": {
        "title": "Laravel",
        "description": "Test",
        "version": "1.0.1"
    },
    "host": "localhost:80",
    "basePath": "/",
    "paths": {
        "/api/user/{id}": {
            "get": {
                "summary": "Return all the details of a user",
                "description": "Returns the user's first name, last name and address Please see the documentation [here](https://example.com/users) for more information",
                "deprecated": true,
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                },
                "parameters": [
                    {
                        "in": "path",
                        "name": "id",
                        "type": "integer",
                        "required": true,
                        "description": "User ID"
                    },
                    {
                        "in": "query",
                        "name": "fields",
                        "type": "array",
                        "required": false,
                        "description": "List of user fields"
                    },
                    {
                        "in": "query",
                        "name": "show_relationships",
                        "type": "boolean",
                        "required": true,
                        "description": "Is it necessary to show the relationship?"
                    }
                ]
            }
        },
        "/api/user/{id}/check": {
            "get": {
                "summary": "Check user exist",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                },
                "parameters": [
                    {
                        "in": "path",
                        "name": "id",
                        "type": "integer",
                        "required": true,
                        "description": "User ID"
                    }
                ]
            }
        }
    }
}
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 68.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~95 days

Recently: every ~1 days

Total

22

Last Release

958d ago

Major Versions

v0.6.4 → v1.0.02023-08-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9b526de35a63bf1110afac0fd4273cd7ae65b360a56504364ff06c1c5ffc533?d=identicon)[laxity7](/maintainers/laxity7)

---

Top Contributors

[![mtrajano](https://avatars.githubusercontent.com/u/4333381?v=4)](https://github.com/mtrajano "mtrajano (52 commits)")[![laxity7](https://avatars.githubusercontent.com/u/6792144?v=4)](https://github.com/laxity7 "laxity7 (13 commits)")[![overint](https://avatars.githubusercontent.com/u/16414140?v=4)](https://github.com/overint "overint (4 commits)")[![rogervila](https://avatars.githubusercontent.com/u/6053012?v=4)](https://github.com/rogervila "rogervila (3 commits)")[![hugef666](https://avatars.githubusercontent.com/u/54015484?v=4)](https://github.com/hugef666 "hugef666 (2 commits)")[![bav55](https://avatars.githubusercontent.com/u/2253306?v=4)](https://github.com/bav55 "bav55 (1 commits)")[![pleaz](https://avatars.githubusercontent.com/u/2572689?v=4)](https://github.com/pleaz "pleaz (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laxity7-laravel-swagger/health.svg)

```
[![Health](https://phpackages.com/badges/laxity7-laravel-swagger/health.svg)](https://phpackages.com/packages/laxity7-laravel-swagger)
```

###  Alternatives

[phpdocumentor/phpdocumentor

Documentation Generator for PHP

4.4k3.1M878](/packages/phpdocumentor-phpdocumentor)[googleads/googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP

67410.3M25](/packages/googleads-googleads-php-lib)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[felixfbecker/advanced-json-rpc

A more advanced JSONRPC implementation

25578.7M6](/packages/felixfbecker-advanced-json-rpc)[overblog/graphql-bundle

This bundle provides tools to build a GraphQL server in your Symfony App.

8027.9M28](/packages/overblog-graphql-bundle)[api-platform/api-pack

A pack for API Platform

5236.7M40](/packages/api-platform-api-pack)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
