PHPackages                             mymdz/l5-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. mymdz/l5-swagger

ActiveLibrary[API Development](/categories/api)

mymdz/l5-swagger
================

Swagger integration to Laravel 5

6.0.3(6y ago)02.0kMITPHPPHP ^7.2

Since Mar 23Pushed 4y agoCompare

[ Source](https://github.com/mymdz/L5-Swagger)[ Packagist](https://packagist.org/packages/mymdz/l5-swagger)[ RSS](/packages/mymdz-l5-swagger/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (8)Versions (73)Used By (0)

[![Total Downloads](https://camo.githubusercontent.com/926092d8dc14b9e5982b32eda06b46b117585e1f6f62238c6e1345d591cd3180/68747470733a2f2f706f7365722e707567782e6f72672f4461726b614f6e4c696e652f4c352d537761676765722f646f776e6c6f6164732e737667)](https://packagist.org/packages/DarkaOnLine/L5-Swagger)[![Build Status](https://camo.githubusercontent.com/825f70738d2930ac87468ce7b993b95b9e48d2fb924b76a5bf5495a2f4d42b9c/68747470733a2f2f7472617669732d63692e6f72672f4461726b614f6e4c696e652f4c352d537761676765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/DarkaOnLine/L5-Swagger)[![Coverage Status](https://camo.githubusercontent.com/ed45802f411b41bd90991501de36a2b310c59f08f2b1d2ebcafaa6fa4d44ef2e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4461726b614f6e4c696e652f4c352d537761676765722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/DarkaOnLine/L5-Swagger?branch=master)[![Code Climate](https://camo.githubusercontent.com/ea5a6c02db371c58cfec65aaba48c9bbc36b6ff8c7af3eafc18ef7af1ec5ce62/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4461726b614f6e4c696e652f4c352d537761676765722f6261646765732f6770612e737667)](https://codeclimate.com/github/DarkaOnLine/L5-Swagger)[![StyleCI](https://camo.githubusercontent.com/b499d07049ce0030ac0175b4f6526c268d571ceaea707e360402358cbfb921d4/68747470733a2f2f7374796c6563692e696f2f7265706f732f33323331353631392f736869656c64)](https://styleci.io/repos/32315619)

L5 Swagger - OpenApi or Swagger Specification for your Laravel project made easy.
=================================================================================

[](#l5-swagger---openapi-or-swagger-specification-for-your-laravel-project-made-easy)

Swagger 2.0 for Laravel &gt;=5.1

This package is a wrapper of [Swagger-php](https://github.com/zircote/swagger-php) and [swagger-ui](https://github.com/swagger-api/swagger-ui) adapted to work with Laravel 5.

Installation
============

[](#installation)

LaravelSwagger UIOpenAPI Spec compatibilityL5-Swagger6.0.x33.0, 2.0`composer require "darkaonline/l5-swagger"`

⚠️ !!! run `composer require 'zircote/swagger-php:2.*'` if you need old **@SWG (SWAGGER annotations)** support. !!!5.8.x33.0, 2.0`composer require "darkaonline/l5-swagger:5.8.*"`

⚠️ !!! run `composer require 'zircote/swagger-php:2.*'` if you need old **@SWG (SWAGGER annotations)** support. !!!5.7.x OR 5.6.x33.0, 2.0`composer require "darkaonline/l5-swagger:5.7.*"`

⚠️ !!! run `composer require 'zircote/swagger-php:2.*'` if you need old **@SWG (SWAGGER annotations)** support. !!!5.6.x32.0`composer require "darkaonline/l5-swagger:5.6.*"`5.5.x32.0`composer require "darkaonline/l5-swagger:5.5.*"`5.4.x32.0`composer require "darkaonline/l5-swagger:5.4.*"`5.4.x2.21.1, 1.2, 2.0`composer require "darkaonline/l5-swagger:~4.0"`5.3.x2.21.1, 1.2, 2.0`composer require "darkaonline/l5-swagger:~3.0"`5.2.x2.21.1, 1.2, 2.0`composer require "darkaonline/l5-swagger:~3.0"`5.1.x2.21.1, 1.2, 2.0`composer require "darkaonline/l5-swagger:~3.0"`You can publish L5-Swagger's config and view files into your project by running:

```
$ php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
```

For Laravel &gt;=5.5, no need to manually add `L5SwaggerServiceProvider` into config. It uses package auto discovery feature. Skip this if you are on &gt;=5.5, if not:

Open your `AppServiceProvider` (located in `app/Providers`) and add this line in `register` function

```
$this->app->register(\L5Swagger\L5SwaggerServiceProvider::class);
```

or open your `config/app.php` and add this line in `providers` section

```
L5Swagger\L5SwaggerServiceProvider::class,
```

You can access your documentation at `/api/documentation` endpoint.

Swagger/OpenApi annotations and generating documentation
--------------------------------------------------------

[](#swaggeropenapi-annotations-and-generating-documentation)

In order to generate the Swagger/OpenApi documentation for your API, Swagger offers a set of annotations to declare and manipulate the output. These annotations can be added in your controller, model or even a seperate file. An example of [OpenApi annotations can be found here](https://github.com/DarkaOnLine/L5-Swagger/blob/master/tests/storage/annotations/OpenApi/Anotations.php) and [Swagger annotations can be found here](https://github.com/DarkaOnLine/L5-Swagger/blob/master/tests/storage/annotations/Swagger/Anotations.php). For more info check out Swagger's ["pet store" example](https://github.com/zircote/swagger-php/tree/master/Examples/petstore-3.0) or the [Swagger OpenApi Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).

After the annotiations have been added you can run `php artisan l5-swagger:generate` to generate the documentation. Alternatively, you can set `L5_SWAGGER_GENERATE_ALWAYS` to `true` in your `.env` file so that your documentation will automatically be generated. Make sure your settings in `config/l5-swagger.php` are complete.

I am still using Swagger @SWG annotation
========================================

[](#i-am-still-using-swagger-swg-annotation)

If still using Swagger @SWG annotations in you project you should:

- Explicitly require `swagger-php` version 2.\* in your projects composer by running:

```
composer require 'zircote/swagger-php:2.*'
```

- Set environment variable `SWAGGER_VERSION` to **2.0** in your `.env` file:

```
SWAGGER_VERSION=2.0

```

or in your `config/l5-swagger.php`:

```
'swagger_version' => env('SWAGGER_VERSION', '2.0'),
```

Using Swagger UI with Passport
==============================

[](#using-swagger-ui-with-passport)

The easiest way to build and test your Laravel-based API using Swagger-php is to use Passport's `CreateFreshApiToken` middleware. This middleware, built into Laravel's core, adds a cookie to all responses, and the cookie authenticates all subsequent requests through Passport's `TokenGuard`.

To get started, first publish L5-Swagger's config and view files into your own project:

```
$ php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
```

Next, edit your `config/l5-swagger.php` configuration file. Locate the `l5-swagger.routes.middleware` section, and add the following middleware list to the `api` route:

```
'api' => [
  \App\Http\Middleware\EncryptCookies::class,
  \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
  \Illuminate\Session\Middleware\StartSession::class,
  \Illuminate\View\Middleware\ShareErrorsFromSession::class,
  \App\Http\Middleware\VerifyCsrfToken::class,
  \Illuminate\Routing\Middleware\SubstituteBindings::class,
  \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
  'auth',
]
```

TIPS
====

[](#tips)

L5\_SWAGGER\_GENERATE\_ALWAYS
-----------------------------

[](#l5_swagger_generate_always)

One of the setting I find useful to enable is `l5-swagger.generate_always`, which will cause your Swagger doc to be regenerated each time you load the Swagger UI (not intended for production use!). All you have to do to enable this in your dev environment is add an environment variable to `.env` named `L5_SWAGGER_GENERATE_ALWAYS` and set it to `true`.

oauth2 + passport = Bearer &lt;token&gt;
----------------------------------------

[](#oauth2--passport--bearer-token)

Follow instruction in [issue #57](https://github.com/DarkaOnLine/L5-Swagger/issues/57).

Changes in 5.0
==============

[](#changes-in-50)

- Swagger UI 3.
- Configuration changes.
- Assets dependency dropped. Now includes from composer package.
- [See migration](#migrate-from-3040-to-50)

Changes in 4.0
==============

[](#changes-in-40)

- Laravel 5.4 support

Changes in 3.2.1
================

[](#changes-in-321)

- Middleware support for routes (#43) (@tantam)

Changes in 3.2
==============

[](#changes-in-32)

- Allow to change swagger base path in generation process
- Allow to define constants in config which can be used later in annotations
- Tests fix form L5.3 and PHP &gt;= 5.6
- Update swagger UI to 2.1.5

Changes in 3.1
==============

[](#changes-in-31)

- Closure routes moved to controller and got names (thanks to @bbs-smuller [\#19](https://github.com/DarkaOnLine/L5-Swagger/pull/19))
- Added option to rename generated API .json file name

Changes in 3.0
==============

[](#changes-in-30)

- More accurate naming and structured config
- Swagger UI - v2.1.4
- Tests

Migrate from 2.0 to 3.0
=======================

[](#migrate-from-20-to-30)

- Replace `$this->app->register('\Darkaonline\L5Swagger\L5SwaggerServiceProvider');` with `$this->app->register(\L5Swagger\L5SwaggerServiceProvider::class);` in your `AppServiceProvider`or add `\L5Swagger\L5SwaggerServiceProvider::class` line in your `config/app.php` file
- Run `l5-swagger:publish-config` to publish new config and make your changes if needed
- Remove `public/vendor/l5-swagger` directory
- Remove `resources/views/vendor/l5-swagger` directory
- Run `l5-swagger:publish-assets` to publish new swagger-ui assets
- Run `l5-swagger:publish-views` to publish new views

Migrate from 3.0|4.0 to 5.0
===========================

[](#migrate-from-3040-to-50)

- Remove `config/l5-swagger.php` file (make a copy if needed)
- Remove `public/vendor/l5-swagger` directory
- Remove `resources/views/vendor/l5-swagger` directory
- Run `l5-swagger:publish` to publish new swagger-ui view and configuration
- Edit your `config/l5-swagger.php` file

Configuration
=============

[](#configuration)

### For versions &lt; 5.5

[](#for-versions--55)

- Run `l5-swagger:publish` to publish everything
- Run `l5-swagger:publish-config` to publish configs (`config/l5-swagger.php`)
- Run `l5-swagger:publish-assets` to publish swagger-ui to your public folder (`public/vendor/l5-swagger`)
- Run `l5-swagger:publish-views` to publish views (`resources/views/vendor/l5-swagger`) - only for versions &lt;= 4.0

### For all versions

[](#for-all-versions)

- Run `l5-swagger:generate` to generate docs or set `generate_always` param to `true` in your config or .env file

Swagger-php
===========

[](#swagger-php)

The actual Swagger spec is beyond the scope of this package. All L5-Swagger does is package up swagger-php and swagger-ui in a Laravel-friendly fashion, and tries to make it easy to serve. For info on how to use swagger-php [look here](http://zircote.com/swagger-php/). For good examples of swagger-php in action [look here](https://github.com/zircote/swagger-php/tree/master/Examples/petstore.swagger.io).

Support on Beerpay
------------------

[](#support-on-beerpay)

Hey dude! Help me out for a couple of 🍻!

[![Beerpay](https://camo.githubusercontent.com/05a943f347e2ae7cce58e2ab4a63b30f8d87da0c0371052ec4aa4b4db082e9a3/68747470733a2f2f626565727061792e696f2f4461726b614f6e4c696e652f4c352d537761676765722f62616467652e7376673f7374796c653d626565722d737175617265)](https://beerpay.io/DarkaOnLine/L5-Swagger) [![Beerpay](https://camo.githubusercontent.com/c0b3871e4a1b5c82e24dd3ee98e88b9cd6e3075a915bd524caede9c3391e9488/68747470733a2f2f626565727061792e696f2f4461726b614f6e4c696e652f4c352d537761676765722f6d616b652d776973682e7376673f7374796c653d666c61742d737175617265)](https://beerpay.io/DarkaOnLine/L5-Swagger?focus=wish)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 81.1% 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 ~25 days

Recently: every ~16 days

Total

69

Last Release

2374d ago

Major Versions

2.0.x-dev → 3.02016-02-23

3.2.1 → 4.0.x-dev2017-01-30

3.2.3 → 5.02017-06-05

5.8.2 → 6.02019-09-04

5.8.3 → 6.0.12019-09-04

PHP version history (7 changes)v0.1PHP &gt;=5.4.0

3.0PHP &gt;=5.5.9

4.0.x-devPHP &gt;=5.6.4

5.0PHP ^7.0

5.6.0PHP &gt;=7.1.3

5.5.7PHP ~7.0

6.0PHP ^7.2

### Community

Maintainers

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

---

Top Contributors

[![DarkaOnLine](https://avatars.githubusercontent.com/u/1171698?v=4)](https://github.com/DarkaOnLine "DarkaOnLine (167 commits)")[![verwilst](https://avatars.githubusercontent.com/u/2114993?v=4)](https://github.com/verwilst "verwilst (4 commits)")[![collegeman](https://avatars.githubusercontent.com/u/120316?v=4)](https://github.com/collegeman "collegeman (4 commits)")[![fh-jashmore](https://avatars.githubusercontent.com/u/26600475?v=4)](https://github.com/fh-jashmore "fh-jashmore (2 commits)")[![bbs-smuller](https://avatars.githubusercontent.com/u/18079210?v=4)](https://github.com/bbs-smuller "bbs-smuller (2 commits)")[![ymhuang0808](https://avatars.githubusercontent.com/u/2720857?v=4)](https://github.com/ymhuang0808 "ymhuang0808 (2 commits)")[![jpuck](https://avatars.githubusercontent.com/u/15305396?v=4)](https://github.com/jpuck "jpuck (2 commits)")[![LiamBull](https://avatars.githubusercontent.com/u/17298523?v=4)](https://github.com/LiamBull "LiamBull (2 commits)")[![IlyaVorozhbit](https://avatars.githubusercontent.com/u/5056861?v=4)](https://github.com/IlyaVorozhbit "IlyaVorozhbit (1 commits)")[![joemugen](https://avatars.githubusercontent.com/u/14120614?v=4)](https://github.com/joemugen "joemugen (1 commits)")[![Azuka](https://avatars.githubusercontent.com/u/129810?v=4)](https://github.com/Azuka "Azuka (1 commits)")[![joshstrange](https://avatars.githubusercontent.com/u/462796?v=4)](https://github.com/joshstrange "joshstrange (1 commits)")[![josiasmontag](https://avatars.githubusercontent.com/u/1945577?v=4)](https://github.com/josiasmontag "josiasmontag (1 commits)")[![markokeeffe](https://avatars.githubusercontent.com/u/1211393?v=4)](https://github.com/markokeeffe "markokeeffe (1 commits)")[![matriphe](https://avatars.githubusercontent.com/u/277262?v=4)](https://github.com/matriphe "matriphe (1 commits)")[![paulhuisman](https://avatars.githubusercontent.com/u/37524?v=4)](https://github.com/paulhuisman "paulhuisman (1 commits)")[![rodrigowbazevedo](https://avatars.githubusercontent.com/u/6214250?v=4)](https://github.com/rodrigowbazevedo "rodrigowbazevedo (1 commits)")[![stefanullrich](https://avatars.githubusercontent.com/u/3226657?v=4)](https://github.com/stefanullrich "stefanullrich (1 commits)")[![tantam](https://avatars.githubusercontent.com/u/3469994?v=4)](https://github.com/tantam "tantam (1 commits)")[![tomcastleman](https://avatars.githubusercontent.com/u/1532660?v=4)](https://github.com/tomcastleman "tomcastleman (1 commits)")

---

Tags

apilaravelswagger

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mymdz-l5-swagger/health.svg)

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M111](/packages/darkaonline-l5-swagger)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3372.3M3](/packages/darkaonline-swagger-lume)

PHPackages © 2026

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