PHPackages                             alireza-h/php-openapi - 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. alireza-h/php-openapi

ActiveLibrary[API Development](/categories/api)

alireza-h/php-openapi
=====================

PHP Open Api Generator

0.3.0(3y ago)223MITPHPPHP ^7.4|^8.0

Since Jan 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/alireza-h/php-openapi)[ Packagist](https://packagist.org/packages/alireza-h/php-openapi)[ Docs](https://github.com/alireza-h/php-openapi)[ RSS](/packages/alireza-h-php-openapi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

PHP OpenAPI
===========

[](#php-openapi)

[![Open API JSON Preview](./resources/images/screenshots/openapi-json.png)](./resources/images/screenshots/openapi-json.png)

[![Open API Swagger UI Preview](./resources/images/screenshots/openapi-swagger-ui.png)](./resources/images/screenshots/openapi-swagger-ui.png)

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

[](#installation)

### Standalone

[](#standalone)

- Clone project
- Run `composer update`
- Check `src/Document` directory as sample and create your own `OpenApiOperationGenerator` and `OpenApiDocumentGenerator`

    `OpenApiOperationGenerator` is responsible to generate Open API Operations and `OpenApiDocumentGenerator` is responsible to generate Open API json document. Each public method of `OpenApiOperationGenerator` generates one Open API Operation (Using reflection).
- Run `php -S localhost:8001` in project root directory

    - Open `http://loclahost:8001` in your browser for Open API json document
    - Open `http://loclahost:8001?swagger` in your browser for Open API Swagger UI

### Dependency of existing project

[](#dependency-of-existing-project)

- Install package

    ```
    composer require alireza-h/php-openapi
    ```
- Check `src/Document` directory as sample and create your own `OpenApiOperationGenerator`and `OpenApiDocumentGenerator`

    Instead of using `OpenApiDocumentGenerator`, you can create your own `OpenApiBuilder` object and add `OpenApiOperation` to builder object.

    ```
    OpenApiBuilder::openapi()
        ->info(
            [
                'title' => 'API',
                'description' => 'API Description',
                'version' => '1.0.0'
            ]
        )
        ->server(
            [
                'url' => '{scheme}://{host}/{base_path}',
                'variables' => [
                    'scheme' => [
                        'enum' => [
                            'http',
                            'https'
                        ],
                        'default' => 'http'
                    ],
                    'host' => [
                        'default' => 'localhost:8000'
                    ],
                    'base_path' => [
                        'default' => 'api'
                    ],
                ]
            ]
        )
        ->component(
            'securitySchemes',
            'bearerAuth',
            [
                'type' => 'http',
                'scheme' => 'bearer',
                'bearerFormat' => 'JWT',
            ]
        )
        ->security(
            [
                'bearerAuth' => []
            ]
        )
        ->operation(
            OpenApiOperation::post('/auth/signup')
                ->tags(['Auth'])
                ->summary('Signup')
                ->description('Signup description')
                ->requestBody(
                    OpenApiRequestBody::create()
                        ->properties(
                            [
                                [
                                    'name' => 'email',
                                    'type' => 'string',
                                    'format' => 'email',
                                    'example' => 'email@example.com',
                                    'description' => 'Email',
                                ],
                                ...
                            ]
                        )
                        ->mediaTypeMultipartFormData()
                )
                ->response(
                    OpenApiResponse::create()
                        ->example(
                            [
                                'data' => [],
                                'message' => null
                            ]
                        )
                )
        )
        ->operation(
            OpenApiOperation::put('/auth/confirm')
                ->tags(['Auth'])
                ->summary('ConfirmSignup')
                ->description('Confirm signup description')
                ->requestBody(
                    OpenApiRequestBody::create()
                        ->properties(
                            [
                                [
                                    'name' => 'email',
                                    'type' => 'string',
                                    'format' => 'email',
                                    'example' => 'email@example.com',
                                    'description' => 'Email',
                                ],
                                [
                                    'name' => 'code',
                                    'example' => 12345,
                                ]
                            ]
                        )
                        ->mediaTypeXWwwFormUrlencoded()
                )
                ->response(
                    OpenApiResponse::create()
                        ->example(
                            [
                                'data' => [],
                                'message' => null
                            ]
                        )
                )
        )
        ->docs();
    ```
- Create your own custom route to serve Open API json document and swagger UI

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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

Every ~9 days

Total

3

Last Release

1212d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5dee77bd635b2fdb405f515647c431807615947d166559a001d30827218f1b4?d=identicon)[alireza-h](/maintainers/alireza-h)

---

Top Contributors

[![alireza-h](https://avatars.githubusercontent.com/u/11046660?v=4)](https://github.com/alireza-h "alireza-h (48 commits)")

### Embed Badge

![Health badge](/badges/alireza-h-php-openapi/health.svg)

```
[![Health](https://phpackages.com/badges/alireza-h-php-openapi/health.svg)](https://phpackages.com/packages/alireza-h-php-openapi)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[ovac/idoc

Generate beautiful API documentation from your Laravel application

184477.6k2](/packages/ovac-idoc)[canvural/php-openapi-faker

Library to generate fake data for OpenAPI request/response/schemas.

92395.8k2](/packages/canvural-php-openapi-faker)

PHPackages © 2026

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