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

AbandonedArchivedLibrary[API Development](/categories/api)

mreko/l5-swagger
================

Swagger integration to Laravel 5

5.6.8(7y ago)09MITPHPPHP &gt;=7.1.3

Since Mar 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/MrEko/L5-Swagger)[ Packagist](https://packagist.org/packages/mreko/l5-swagger)[ RSS](/packages/mreko-l5-swagger/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (8)Versions (52)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)[![Dependency Status](https://camo.githubusercontent.com/f740ecdbff44a044b1426d4e31e8c170f68e6e0fe8880165ca11f138da8c3231/68747470733a2f2f626574612e67656d6e617369756d2e636f6d2f6261646765732f6769746875622e636f6d2f4461726b614f6e4c696e652f4c352d537761676765722e737667)](https://beta.gemnasium.com/projects/github.com/DarkaOnLine/L5-Swagger)

L5 Swagger
==========

[](#l5-swagger)

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-Swagger5.1.x2.21.1, 1.2, 2.0`php composer require "darkaonline/l5-swagger:~3.0" `5.2.x2.21.1, 1.2, 2.0`php composer require "darkaonline/l5-swagger:~3.0" `5.3.x2.21.1, 1.2, 2.0`php composer require "darkaonline/l5-swagger:~3.0" `5.4.x2.21.1, 1.2, 2.0`php composer require "darkaonline/l5-swagger:~4.0" `5.4.x32.0`php composer require "darkaonline/l5-swagger:5.4.*" `5.5.x32.0, 3.0`php composer require "darkaonline/l5-swagger:5.5.*" `5.6.x32.0, 3.0`php composer require "darkaonline/l5-swagger:5.6.*" `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,
```

Swagger annotations and generating documentation
------------------------------------------------

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

In order to generate the Swagger 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 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/3.x/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.

Using [OpenApi 3.0 Specification](https://github.com/OAI/OpenAPI-Specification)
===============================================================================

[](#using-openapi-30-specification)

If you would like to use lattes OpenApi specifications (originally known as the Swagger Specification) in you project you should:

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

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

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

```
SWAGGER_VERSION=3.0

```

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

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

- Use examples provided here:

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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity71

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 ~36 days

Total

50

Last Release

2845d ago

Major Versions

v0.2 → v2.02015-05-05

1.0.x-dev → 2.12015-08-04

2.0.x-dev → 3.02016-02-23

3.2.1 → 4.0.x-dev2017-01-30

3.2.3 → 5.02017-06-05

PHP version history (6 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

### Community

Maintainers

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

---

Top Contributors

[![DarkaOnLine](https://avatars.githubusercontent.com/u/1171698?v=4)](https://github.com/DarkaOnLine "DarkaOnLine (133 commits)")[![MrEko](https://avatars.githubusercontent.com/u/3877358?v=4)](https://github.com/MrEko "MrEko (4 commits)")[![collegeman](https://avatars.githubusercontent.com/u/120316?v=4)](https://github.com/collegeman "collegeman (4 commits)")[![verwilst](https://avatars.githubusercontent.com/u/2114993?v=4)](https://github.com/verwilst "verwilst (4 commits)")[![bbs-smuller](https://avatars.githubusercontent.com/u/18079210?v=4)](https://github.com/bbs-smuller "bbs-smuller (2 commits)")[![fh-jashmore](https://avatars.githubusercontent.com/u/26600475?v=4)](https://github.com/fh-jashmore "fh-jashmore (2 commits)")[![jpuck](https://avatars.githubusercontent.com/u/15305396?v=4)](https://github.com/jpuck "jpuck (2 commits)")[![h2akim](https://avatars.githubusercontent.com/u/514048?v=4)](https://github.com/h2akim "h2akim (1 commits)")[![joseph-montanez](https://avatars.githubusercontent.com/u/110960?v=4)](https://github.com/joseph-montanez "joseph-montanez (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)")[![cyberhicham](https://avatars.githubusercontent.com/u/10002527?v=4)](https://github.com/cyberhicham "cyberhicham (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)")[![ejbogantes](https://avatars.githubusercontent.com/u/4172977?v=4)](https://github.com/ejbogantes "ejbogantes (1 commits)")[![paulhuisman](https://avatars.githubusercontent.com/u/37524?v=4)](https://github.com/paulhuisman "paulhuisman (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)")[![gert-fresh](https://avatars.githubusercontent.com/u/1530784?v=4)](https://github.com/gert-fresh "gert-fresh (1 commits)")

---

Tags

apilaravelswagger

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/mreko-l5-swagger/health.svg)](https://phpackages.com/packages/mreko-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)
