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

ActiveLibrary[API Development](/categories/api)

wotz/laravel-swagger-ui
=======================

Add Swagger UI to a Laravel application.

2.1.0(2mo ago)277321.8k↓13.1%38[7 issues](https://github.com/wotzebra/laravel-swagger-ui/issues)MITPHPPHP ^8.3|^8.4|^8.5CI passing

Since Oct 16Pushed 2mo ago8 watchersCompare

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

READMEChangelog (10)Dependencies (18)Versions (26)Used By (0)

Laravel Swagger UI
==================

[](#laravel-swagger-ui)

[![Latest Version on Packagist](https://camo.githubusercontent.com/145de322367395f535f4b24714c90d5dd412385d5f756fa3f65485f43f0d476c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776f747a2f6c61726176656c2d737761676765722d75692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wotz/laravel-swagger-ui)[![Total Downloads](https://camo.githubusercontent.com/dde3b176791693df274a408dafb6b521ef6b7eab161b5b0bf659eb60b12ff14f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776f747a2f6c61726176656c2d737761676765722d75692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wotz/laravel-swagger-ui)

This package makes it easy to make your project's Swagger (OpenAPI v3 JSON or YAML) file accessible in a Swagger UI right in your Laravel application.

The Swagger UI will automatically use your current project environment. It will set your api's base url to the active base url. Possible oauth2 configuration, such as urls and client-id/client-secret, can also be injected in Swagger UI via the configuration file.

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

[](#installation)

You can install the package via composer:

```
composer require wotz/laravel-swagger-ui
```

After installing Laravel Swagger UI, publish its service provider and configuration file using the `swagger-ui:install` Artisan command.

```
php artisan swagger-ui:install
```

Usage
-----

[](#usage)

### Customize authentication and authorization

[](#customize-authentication-and-authorization)

The Swagger UI is exposed at `/swagger`. By default, you will only be able to access it in the local environment. Within your `app/Providers/SwaggerUiServiceProvider.php` file, there is a `gate` method. This authorization gate controls access to Swagger UI in non-local environments. You can modify this gate as needed to restrict access to your Swagger UI and Swagger (OpenAPI v3) file:

```
/**
 * Register the Swagger UI gate.
 *
 * This gate determines who can access Swagger UI in non-local environments.
 *
 * @return void
 */
protected function gate()
{
    Gate::define('viewSwaggerUI', function ($user = null) {
        return in_array(optional($user)->email, [
            //
        ]);
    });
}
```

### Customize locations of Swagger (OpenAPI v3) files

[](#customize-locations-of-swagger-openapi-v3-files)

In the published `config/swagger-ui.php` file, you edit the path to the Swagger UI and the location of the Swagger (OpenAPI v3) file. By default, the package expects to find the OpenAPI file in 'resources/swagger' directory. You can also provide an url if the OpenAPI file is not present in the Laravel project itself. This is also where you can define multiple versions for the same api.

```
// in config/swagger-ui.php

return [
    // ...

    'path' => 'swagger',

    'versions' => [
        'v1' => resource_path('swagger/openapi.json')
    ],

    // ...
];
```

### Customize modifications to Swagger (OpenAPI v3) files and SwaggerUI

[](#customize-modifications-to-swagger-openapi-v3-files-and-swaggerui)

By default the package will customize the server url and the oauth urls in the OpenAPI file to the base url of the Laravel application. This can be disabled in the config.

```
// in config/swagger-ui.php

return [
    // ...

    'modify_file' => true,

    // ...
];
```

You can also set what variables that should be customizable for the server url in Swagger UI. Variable must be present with the same key (case-sensitive) in the url surrounded by curly brackets.

```
// in config/swagger-ui.php

return [
    // ...

    'server_url' => 'http://foo.bar/{Language}/api',

    'server_variables' => ['Language' => ['default' => 'en']],

    // ...
]
```

You can also set an oauth client ID and client secret. These values will be automatically prefilled in the authentication view in Swagger UI.

```
// in config/swagger-ui.php

return [
    // ...

    'oauth' => [
        'token_path' => 'oauth/token',
        'refresh_path' => 'oauth/token',
        'authorization_path' => 'oauth/authorize',

        'client_id' => env('SWAGGER_UI_OAUTH_CLIENT_ID'),
        'client_secret' => env('SWAGGER_UI_OAUTH_CLIENT_SECRET'),
    ];

    // ...
];
```

### Enable and configure MCP Server based on Swagger (OpenAPI v3) files

[](#enable-and-configure-mcp-server-based-on-swagger-openapi-v3-files)

If you want to use the mcp server that returns info about your swagger files, then you need to install the `laravel/mcp` composer package and enable the swagger server in the config:

```
// in config/swagger-ui.php

return [
    // ...

    'mcp' => [
        'enabled' => true,
    ],

    // ...
];
```

By default, the MCP server is protected by the `auth:api` middleware and the `viewSwaggerUI` gate. If you are using Laravel Passport, then you still have to enable the MCP OAuth routes by adding `Mcp::oauthRoutes()` and a Passport authorization view to your codebase.

### Testing

[](#testing)

```
composer test
```

Linting
-------

[](#linting)

```
composer lint
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Günther Debrauwer](https://github.com/gdebrauwer)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

67

—

FairBetter than 100% of packages

Maintenance87

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 85.2% 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 ~90 days

Total

23

Last Release

62d ago

Major Versions

0.10.1 → 1.0.02024-09-26

v1.x-dev → 2.0.02026-01-30

PHP version history (8 changes)0.1.0PHP ^7.4

0.2.0PHP ^7.4|^8.0

0.4.0PHP ^7.4|^8.0|^8.1

0.7.0PHP ^7.4|^8.0|^8.1|^8.2

0.8.0PHP ^8.1|^8.2

0.9.0PHP ^8.1|^8.2|^8.3

1.1.0PHP ^8.1|^8.2|^8.3|^8.4

2.0.0PHP ^8.3|^8.4|^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/739571b3160077a91cf01209a045409a0daf361b73fae482f37dfcf1db301a57?d=identicon)[gdebrauwer](/maintainers/gdebrauwer)

![](https://www.gravatar.com/avatar/15cf50c665151125e406b8daceaca4ce27096798f9295cbae2f17b29440241f6?d=identicon)[Who Owns The Zebra](/maintainers/Who%20Owns%20The%20Zebra)

---

Top Contributors

[![gdebrauwer](https://avatars.githubusercontent.com/u/22586858?v=4)](https://github.com/gdebrauwer "gdebrauwer (104 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")[![yinx](https://avatars.githubusercontent.com/u/1022847?v=4)](https://github.com/yinx "yinx (3 commits)")[![Bart-Kuenen-nextapps](https://avatars.githubusercontent.com/u/107543678?v=4)](https://github.com/Bart-Kuenen-nextapps "Bart-Kuenen-nextapps (2 commits)")[![bbeng89](https://avatars.githubusercontent.com/u/356577?v=4)](https://github.com/bbeng89 "bbeng89 (2 commits)")[![jan-claeys](https://avatars.githubusercontent.com/u/32668993?v=4)](https://github.com/jan-claeys "jan-claeys (2 commits)")[![matysekmichal](https://avatars.githubusercontent.com/u/10400972?v=4)](https://github.com/matysekmichal "matysekmichal (1 commits)")[![nathanaelhoun](https://avatars.githubusercontent.com/u/45119518?v=4)](https://github.com/nathanaelhoun "nathanaelhoun (1 commits)")[![samuelhgf](https://avatars.githubusercontent.com/u/16768378?v=4)](https://github.com/samuelhgf "samuelhgf (1 commits)")[![treb00](https://avatars.githubusercontent.com/u/43503234?v=4)](https://github.com/treb00 "treb00 (1 commits)")[![ls-paul-julien-vauthier](https://avatars.githubusercontent.com/u/54601900?v=4)](https://github.com/ls-paul-julien-vauthier "ls-paul-julien-vauthier (1 commits)")

---

Tags

laravelswaggeropenapiswagger-ui

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[harmbandstra/swagger-ui-bundle

Exposes swagger UI inside your Symfony project through a route (eg. /docs)

42867.3k](/packages/harmbandstra-swagger-ui-bundle)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[johnylemon/laravel-apidocs

Laravel API documentation generating tool

472.8k](/packages/johnylemon-laravel-apidocs)

PHPackages © 2026

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