PHPackages                             zentlix/swagger-php - 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. zentlix/swagger-php

ActiveLibrary[API Development](/categories/api)

zentlix/swagger-php
===================

Swagger-php integration package for Spiral Framework.

1.x-dev(2y ago)37.5k↓45.8%[2 PRs](https://github.com/zentlix/swagger-php/pulls)MITPHPPHP ^8.1

Since Dec 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/zentlix/swagger-php)[ Packagist](https://packagist.org/packages/zentlix/swagger-php)[ Docs](https://github.com/zentlix/swagger-php)[ RSS](/packages/zentlix-swagger-php/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelogDependencies (12)Versions (3)Used By (0)

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

[](#swagger-php)

[![PHP Version Require](https://camo.githubusercontent.com/86abc21eddd2a2e4b287203e76541f2a835c9c8d253a464d92274208701623a9/68747470733a2f2f706f7365722e707567782e6f72672f7a656e746c69782f737761676765722d7068702f726571756972652f706870)](https://packagist.org/packages/zentlix/swagger-php)[![Latest Stable Version](https://camo.githubusercontent.com/4155cf45d434b22eb637847d622cc397a73f5541c05281d6db5f82e42ae1439a/68747470733a2f2f706f7365722e707567782e6f72672f7a656e746c69782f737761676765722d7068702f762f737461626c65)](https://packagist.org/packages/zentlix/swagger-php)[![phpunit](https://github.com/zentlix/swagger-php/actions/workflows/phpunit.yml/badge.svg)](https://github.com/zentlix/swagger-php/actions)[![psalm](https://github.com/zentlix/swagger-php/actions/workflows/psalm.yml/badge.svg)](https://github.com/zentlix/swagger-php/actions)[![Codecov](https://camo.githubusercontent.com/b6d9b4a05661e55309322a9bd9b48c22e0e9224ee120edb66a25335bfa97f5d1/68747470733a2f2f636f6465636f762e696f2f67682f7a656e746c69782f737761676765722d7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/zentlix/swagger-php)[![Total Downloads](https://camo.githubusercontent.com/7b75ad5ebb51b07614b5eb89f6544337cb528b832adc3537713ab5e6b4de26d3/68747470733a2f2f706f7365722e707567782e6f72672f7a656e746c69782f737761676765722d7068702f646f776e6c6f616473)](https://packagist.org/packages/zentlix/swagger-php)[![type-coverage](https://camo.githubusercontent.com/a383771c036ff7ea8cf132f3c4b0447044e39540982db069c71f5fef9d890938/68747470733a2f2f73686570686572642e6465762f6769746875622f7a656e746c69782f737761676765722d7068702f636f7665726167652e737667)](https://shepherd.dev/github/zentlix/swagger-php)[![psalm-level](https://camo.githubusercontent.com/b046654c4cd097260a2d57c11fc17c070b53372ed4f7a54367c633b29be8d096/68747470733a2f2f73686570686572642e6465762f6769746875622f7a656e746c69782f737761676765722d7068702f6c6576656c2e737667)](https://shepherd.dev/github/zentlix/swagger-php)

[**zircote/swagger-php**](https://github.com/zircote/swagger-php) integration package for Spiral Framework.

Requirements
------------

[](#requirements)

Make sure that your server is configured with following PHP version and extensions:

- PHP 8.1+
- Spiral framework 3.5+

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

[](#installation)

You can install the package via composer:

```
composer require zentlix/swagger-php
```

To enable the package in your Spiral Framework application, you will need to add the `Spiral\OpenApi\Bootloader\SwaggerBootloader` class to the list of bootloaders in your application:

```
protected const LOAD = [
    // ...
    \Spiral\OpenApi\Bootloader\SwaggerBootloader::class,
];
```

> **Note**If you are using [`spiral-packages/discoverer`](https://github.com/spiral-packages/discoverer), you don't need to register bootloader by yourself.

Configuration
-------------

[](#configuration)

The configuration file should be located at `app/config/swagger.php`, and it allows you to set options. Here is an example of how the configuration file might look:

```
use Spiral\OpenApi\Config\SwaggerConfig;
use Spiral\OpenApi\Generator\Parser\ConfigurationParser;
use Spiral\OpenApi\Generator\Parser\OpenApiParser;
use Spiral\OpenApi\Renderer\HtmlRenderer;
use Spiral\OpenApi\Renderer\JsonRenderer;
use Spiral\OpenApi\Renderer\YamlRenderer;

return [
    'documentation' => [
        'info' => [
            'title' => 'My App',
            'description' => 'API documentation',
            'version' => '1.0.0',
        ],
    ],
    'parsers' => [
        ConfigurationParser::class,
        OpenApiParser::class,
    ],
    'renderers' => [
        JsonRenderer::FORMAT => JsonRenderer::class,
        YamlRenderer::FORMAT => YamlRenderer::class,
        HtmlRenderer::FORMAT => HtmlRenderer::class,
    ],
    'paths' => [
        directory('app'),
    ],
    'exclude' => null,
    'pattern' => null,
    'version' => null,
    'cache_key' => SwaggerConfig::DEFAULT_CACHE_KEY,
    'generator_config' => [
        'operationId' => [
            'hash' => true,
        ],
    ],
    'use_cache' => env('APP_ENV') === 'prod',
];
```

Usage
-----

[](#usage)

First, create an entity that represents the resource you want to document. For example, you can create a **User** entity that represents a user resource:

```
namespace App\Entity;

use OpenApi\Attributes as OA;

#[OA\Schema(
    schema: 'User',
    description: 'User record',
    required: ['email', 'first_name', 'last_name'],
    type: 'object',
)]
class User
{
    #[OA\Property(type: 'string')]
    public string $email;

    #[OA\Property(property: 'first_name', type: 'string')]
    public string $firstName;

    #[OA\Property(property: 'last_name',type: 'string')]
    public string $lastName;
}
```

Next, create a Controller that handles the actions for the resource, and add Swagger attributes to the actions to describe the behavior of the endpoint. For example, you can create a **UserController** that handles the **list**action for the User resource:

```
use OpenApi\Attributes as OA;
use Psr\Http\Message\ResponseInterface;

class UserController
{
    #[OA\Get(
        path: '/api/v1/users',
        tags: ['User'],
        parameters: [
            new OA\Parameter(ref: '#/components/parameters/page'),
            new OA\Parameter(ref: '#/components/parameters/limit'),
            new OA\Parameter(
                name: 'sort',
                description: 'The field used to order users',
                in: 'query',
                schema: new OA\Schema(type: 'string'),
                examples: [
                    'user.first_name' => new OA\Examples(
                        example: 'user.first_name',
                        summary: 'Sort by `user.first_name` field',
                        value: 'user.first_name'
                    ),
                    'user.last_name' => new OA\Examples(
                        example: 'user.last_name',
                        summary: 'Sort by `user.last_name` field',
                        value: 'user.last_name'
                    ),
                ]
            ),
            new OA\Parameter(ref: '#/components/parameters/direction')
        ],
        responses: [
            new OA\Response(
                response: 200,
                description: 'Retrieve a collection of users',
                content: new OA\JsonContent(
                    properties: [
                        new OA\Property(
                            property: 'meta',
                            ref: '#/components/schemas/ResponseCollectionMeta'
                        ),
                        new OA\Property(
                            property: 'data',
                            description: 'Collection of users',
                            type: 'array',
                            items: new OA\Items(type: 'array', items: new OA\Items(
                                properties: [
                                    new OA\Property(
                                        property: 'uuid',
                                        type: 'string',
                                        example: '7be33fd4-ff46-11ea-adc1-0242ac120002'
                                    ),
                                    new OA\Property(
                                        property: 'type',
                                        type: 'string'
                                    ),
                                    new OA\Property(
                                        property: 'attributes',
                                        ref: '#/components/schemas/User'
                                    ),
                                ],
                                type: 'object'
                            ))
                        ),
                    ],
                    type: 'object'
                )
            ),
        ]
    )]
    public function list(): ResponseInterface
    {
        // ...
    }
}
```

Some elements like **page**, **limit**, **direction** parameters. The **ResponseCollectionMeta** schema can be used in a variety of places. Therefore, they can be defined in the configuration file:

```
// file app/config/swagger.php
return [
    'documentation' => [
        'info' => [
            'title' => 'My App',
            'description' => 'My App API Documentation',
            'version' => '1.0.0'
        ],
        'components' => [
            'parameters' => [
                'page' => [
                    'name' => 'page',
                    'in' => 'query',
                    'example' => 1,
                    'schema' => [
                        'type' => 'integer'
                    ]
                ],
                'limit' => [
                    'name' => 'limit',
                    'in' => 'query',
                    'example' => 25,
                    'schema' => [
                        'type' => 'integer'
                    ]
                ],
                'direction' => [
                    'name' => 'direction',
                    'in' => 'query',
                    'schema' => [
                        'type' => 'string'
                    ],
                    'examples' => [
                        'asc' => [
                            'value' => 'asc',
                            'summary' => 'Sort Ascending'
                        ],
                        'desc' => [
                            'value' => 'desc',
                            'summary' => 'Sort Descending'
                        ]
                    ]
                ]
            ],
            'schemas' => [
                'ResponseCollectionMeta' => [
                    'type' => 'object',
                    'properties' => [
                        'size' => [
                            'type' => 'integer'
                        ],
                        'page' => [
                            'type' => 'integer'
                        ],
                        'total' => [
                            'type' => 'integer'
                        ]
                    ]
                ]
            ]
        ]
    ],
];
```

The package provides a `Spiral\OpenApi\Controller\DocumentationController` controller that can render the documentation in various formats such as HTML, JSON, and YAML. The HTML format uses the `Swagger UI` for displaying the documentation. To use this controller, it is necessary to add a route in the `App\Application\Bootloader\RoutesBootloader` file:

```
use Spiral\OpenApi\Controller\DocumentationController;

final class RoutesBootloader extends BaseRoutesBootloader
{
    protected function defineRoutes(RoutingConfigurator $routes): void
    {
        // ...

        $routes
            ->add('swagger-api-html', '/api/docs')
            ->action(DocumentationController::class, 'html');
        $routes
            ->add('swagger-api-json', '/api/docs.json')
            ->action(DocumentationController::class, 'json');
        $routes
            ->add('swagger-api-yaml', '/api/docs.yaml')
            ->action(DocumentationController::class, 'yaml');

       // ...
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

```
composer psalm
```

```
composer cs
```

Changelog
---------

[](#changelog)

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

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

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

893d ago

### Community

Maintainers

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

---

Top Contributors

[![msmakouz](https://avatars.githubusercontent.com/u/67324318?v=4)](https://github.com/msmakouz "msmakouz (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

spiral-frameworkswagger-phpswagger-uiapiSwagger-PHPspiral

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zentlix-swagger-php/health.svg)

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3372.3M3](/packages/darkaonline-swagger-lume)[jlapp/swaggervel

A great way to integrate Swagger into Laravel

492931.6k2](/packages/jlapp-swaggervel)[adrenalinkin/swagger-resolver-bundle

Provides possibility for validate data according to Swagger documentation

1013.3k](/packages/adrenalinkin-swagger-resolver-bundle)

PHPackages © 2026

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