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

ActiveLibrary[API Development](/categories/api)

hasnhasan/laravel-swagger
=========================

Auto generates the swagger documentation for a laravel project

1.5(5y ago)01.2k↓33.3%MITPHP

Since Oct 31Pushed 5y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

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

[](#laravel-swagger)

This package scans your laravel project's routes and auto generates a Swagger 2.0 documentation for you. 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. 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 you route contains them.

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

[](#installation)

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

If you are running a version of Laravel &lt; 5.5 also make sure you add `hasnhasan\LaravelSwagger\SwaggerServiceProvider::class` to the `providers` array in `config/app.php`.

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

Usage
-----

[](#usage)

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 > 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"`

If you want to change the change the host name, you can pass a host using `--host`, for example: `php artisan laravel-swagger:generate --host="localhost/laravel"`

If you want to apply authentication(currently supports only jwt), you can pass a auth using `--auth`, for example: `php artisan laravel-swagger:generate --auth="jwt"`

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`

Example
-------

[](#example)

Say you have a route `/api/users/{id}` that maps to `UserController@show`

Your sample controller might look like this:

```
class UserController extends Controller
{
    public function show(UserShowRequest $request, $id)
    {
        return User::find($id);
    }
}
```

And the FormRequest class might look like this:

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

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

```
{
    "swagger": "2.0",
    "info": {
        "title": "Laravel",
        "description": "Test",
        "version": "1.0.1"
    },
    "host": "http:\/\/localhost",
    "basePath": "\/",
    "paths": {
        "\/api\/user\/{id}": {
            "get": {
                "description": "GET \/api\/user\/{id}",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                },
                "parameters": [
                    {
                        "in": "path",
                        "name": "id",
                        "type": "integer",
                        "required": true,
                        "description": ""
                    },
                    {
                        "in": "query",
                        "name": "fields",
                        "type": "array",
                        "required": false,
                        "description": ""
                    },
                    {
                        "in": "query",
                        "name": "show_relationships",
                        "type": "boolean",
                        "required": true,
                        "description": ""
                    }
                ]
            },
            ...
        }
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.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 ~38 days

Total

5

Last Release

1867d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e435ed1449668c86ad57fb8a0cf99d1bdd37131f26c8f4eed40844d6d90afca?d=identicon)[hasnhasan](/maintainers/hasnhasan)

---

Top Contributors

[![goldsteam](https://avatars.githubusercontent.com/u/102119261?v=4)](https://github.com/goldsteam "goldsteam (5 commits)")[![hasnhasan](https://avatars.githubusercontent.com/u/3776411?v=4)](https://github.com/hasnhasan "hasnhasan (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[devio/pipedrive

Complete Pipedrive API client for PHP and/or Laravel

1691.8M](/packages/devio-pipedrive)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)

PHPackages © 2026

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