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

ActiveLibrary[API Development](/categories/api)

kai/l5-swagger
==============

Swagger Docs for Laravel

1.0(1y ago)041MITPHPPHP &gt;=7.3 || 8.\*

Since Jan 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/HoangVanChau/l5-swagger)[ Packagist](https://packagist.org/packages/kai/l5-swagger)[ RSS](/packages/kai-l5-swagger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Laravel Swagger Docs
====================

[](#laravel-swagger-docs)

Simple to use OAS3 compatible documentation generator.
Also includes Swagger UI.

About
-----

[](#about)

1. OAS3 support
2. Custom decorators
3. Custom responses
4. Automatic generation (assuming relevant configuration option is turned on)
5. Inclusion of Swagger UI
6. Models generations
7. Generate operation tags based on route prefix or controller's name

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

[](#installation)

#### Install package through composer

[](#install-package-through-composer)

```
composer require kai/l5-swagger
```

#### Publish configuration files and views

[](#publish-configuration-files-and-views)

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

#### Edit the `swagger.php` configuration file for your liking

[](#edit-the-swaggerphp-configuration-file-for-your-liking)

Usage
-----

[](#usage)

Laravel Swagger Docs 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 weather 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. I believe this makes reading the documentation easier by not leaving important information out. The file can be easily cleaned up afterward if the user chooses to leave out the defaults.

### Command line

[](#command-line)

Generating the swagger documentation is easy, simply run `php artisan swagger:generate` in your project root. The output of the command will be stored in your storage path linked in config file.

If you wish to generate docs for a subset of your routes, you can pass a filter using `--filter`, for example: `php artisan swagger:generate --filter="/api"`

You can also configure your swagger.php file to always generate schema when accessing Swagger UI or just by adding this line in your .env: `SWAGGER_GENERATE_ALWAYS=true`

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`

### @Request() decorator

[](#request-decorator)

You can have only one `@Request()` decorator.

```
/**
* You can also do this, first line will be "summary"
*
* And anything 1 * apart from the "summary" will count as "description"
*
* @Request({
*     summary: Title of the route,
*     description: This is a longer description for the route which will be visible once the panel is expanded,
*     tags: Authentication,Users
* })
*/
public function someMethod(Request $request) {}
```

### @Response() decorator

[](#response-decorator)

You can have multiple `@Response` decorators

- The `code` property is required and must be the first in proper
- You can use the optional `description` property to describe your response
- You can use the optional `ref` property to refer a model, you can also wrap that model in \[\] to refer an array of that model or use the full model path inside, finally you can use a schema builder

```
/**
* @Response({
*     code: 200
*     description: return user model
*     ref: User
* })
* @Response({
*     code: 400
*     description: Bad Request, array of APIError model
*     ref: [APIError]
* })
* @Response({
*     code: 302
*     description: Redirect
* })
* @Response({
*     code: 500
*     description: Internal Server Error
* })
*/
public function someMethod(Request $request) {}

/**
 * You can also refer object directly
 *
 *
 * @Response({
 *     code: 200
 *     description: direct user model reference
 *     ref: #/components/schemas/User
 * })
 */
public function someMethod2(Request $request) {}

/**
 * Using P schema builder for Laravel Pagination
 *
 * @Response({
 *     code: 200
 *     description: a laravel pagination instance with User model
 *     ref: P(User)
 * })
 */
public function someMethod3(Request $request) {}
```

### @Error() decorator

[](#error-decorator)

You can have only one `@Error()` decorator.

```
/**
 * Define error response
 *
 * @Error ({
 *     responses: [401, 403, 404, 500]
 * })
 */
public function someMethod(Request $request) {}
```

##### Note: You can see all available schema builder or create your own schema builder, explore swagger.schema\_builders config for more information.

[](#note-you-can-see-all-available-schema-builder-or-create-your-own-schema-builder-explore-swaggerschema_builders-config-for-more-information)

### Custom Validators

[](#custom-validators)

These validators are made purely for visual purposes, however, some of them can actually do validation

#### swagger\_default

[](#swagger_default)

```
$rules = [
    'locale'        =>  'swagger_default:en_GB'
];
```

#### swagger\_min

[](#swagger_min)

```
$rules = [
    'page'          =>  'swagger_default:1|swagger_min:1', // This will simply display the 'minimum' value in the documentation
    'page'          =>  'swagger_default:1|swagger_min:1:fail' // This will also fail if the `page` parameter will be less than 1
];
```

#### swagger\_max

[](#swagger_max)

```
$rules = [
    'take'          =>  'swagger_default:1|swagger_min:1|swagger_max:50', // This will simply display the 'maximum' value in the documentation
    'take'          =>  'swagger_default:1|swagger_min:1|swagger_max:50:fail' // This will also fail if the `take` parameter will be greater than 50
];
```

---

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance40

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

501d ago

### Community

Maintainers

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

---

Top Contributors

[![HoangVanChau](https://avatars.githubusercontent.com/u/32084801?v=4)](https://github.com/HoangVanChau "HoangVanChau (9 commits)")

### Embed Badge

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

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