PHPackages                             wapmorgan/openapi-generator - 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. wapmorgan/openapi-generator

ActiveLibrary[API Development](/categories/api)

wapmorgan/openapi-generator
===========================

OpenApi configuration generator directly from PHP code (PhpDoc, functions signature and type hints) and projects (for yii2, slim, laravel). Can be used with a large monolithic backend to maintain big API documentation

0.4.11(1y ago)202.8k4[1 issues](https://github.com/wapmorgan/OpenApiGenerator/issues)MITPHPPHP &gt;=7.4

Since Feb 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/wapmorgan/OpenApiGenerator)[ Packagist](https://packagist.org/packages/wapmorgan/openapi-generator)[ RSS](/packages/wapmorgan-openapi-generator/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (4)Versions (31)Used By (0)

What is it?
===========

[](#what-is-it)

It is OpenApi configuration generator that works with origin source code + phpdoc.

[![Latest Stable Version](https://camo.githubusercontent.com/8144986ee37c2eec504467bcb3d9f52fc4d47672ea24fd52bb63b73a67b07366/68747470733a2f2f706f7365722e707567782e6f72672f7761706d6f7267616e2f6f70656e6170692d67656e657261746f722f762f737461626c65)](https://packagist.org/packages/wapmorgan/openapi-generator)[![Latest Unstable Version](https://camo.githubusercontent.com/4cfc585678c87812936c916fe7cf6c59d2db7332d0aef9c16f93165eb94a370f/68747470733a2f2f706f7365722e707567782e6f72672f7761706d6f7267616e2f6f70656e6170692d67656e657261746f722f762f756e737461626c65)](https://packagist.org/packages/wapmorgan/openapi-generator)[![License](https://camo.githubusercontent.com/8fc670f65805bb1aa9e6ef0b44722f69f00a7073c95d0e3648c8f986167e1cb3/68747470733a2f2f706f7365722e707567782e6f72672f7761706d6f7267616e2f6f70656e6170692d67656e657261746f722f6c6963656e7365)](https://packagist.org/packages/wapmorgan/openapi-generator)

Main purpose of this library is to automatize generation of OpenApi-specification for existing **JSON-API** with a lot of methods. Idea by [@maxonrock](https://github.com/maxonrock).

1. [Open Api generator](#openapigenerator)
    - [Laravel Example](#laravel-example)
    - [How it works](#how-it-works)
    - [How to use](#how-to-use)
    - [Integrations](#integrations)
2. [Extending](#extending)
    - [New scraper](#new-scraper)
    - [Settings](#settings)
    - [Limitations](#limitations)
    - [ToDo](#todo)

OpenApiGenerator
================

[](#openapigenerator)

**What it does?**

It generates [OpenApi 3.0 specification files](https://swagger.io/docs/specification/about/) for your REST JSON-based API written in PHP from source code directly. You **do not need** to write OpenApi-specification manually.

Laravel Example
---------------

[](#laravel-example)

1. Routes:

    ```
    Route::get('/selector/lists', [\App\Http\Controllers\SelectorController::class, 'lists']);
    Route::post('/selector/select', [\App\Http\Controllers\SelectorController::class, 'select']);
    Route::get('/selector/goTo', [\App\Http\Controllers\SelectorController::class, 'goTo']);
    Route::get('/geo/detect', [\App\Http\Controllers\GeoController::class, 'detect']);
    Route::get('/geo/select', [\App\Http\Controllers\GeoController::class, 'select']);
    ```
2. One controller:

    ```
    /**
    * Returns lists of filters
    * @param Request $request
    * @return ListsResponse
    */
    public function lists(Request $request) {
      return new ListsResponse([
          //            'persons' => range(1, 15),
          'persons' => array_keys(Menu::$personsList),
          'tastes' => Menu::$tastes,
          'meat' => Menu::$meat,
          'pizzas' => Menu::$pizzas,
      ]);
    }

    /**
    * Makes a selection of pizzas according to criteria
    * @param \App\Http\Requests\SelectPizzas $request
    * @return PizzaListItem[]
    */
    public function select(\App\Http\Requests\SelectPizzas $request) {
      $validated = $request->validated();

      return (new Selector())->select(
          $validated['city'], $validated['persons'],
          $validated['tastes'] ?? null, $validated['meat'] ?? null,
          $validated['vegetarian'] ?? false, $validated['maxPrice'] ?? null);
    }
    ```
3. One request and two responses:

    ```
    class SelectPizzas extends FormRequest {
         public function rules()
         {
             // ...
             return array_merge([
                'city' => ['required', 'string'],
                'persons' => ['required', Rule::in(array_keys(Menu::$personsList))],
                'vegetarian' => ['boolean'],
                'maxPrice' => ['numeric'],
                'pizzas' => ['array', Rule::in(array_keys(Menu::$pizzas))],
             ], $tastes, $meat);
         }
    }

    class ListsResponse extends BaseResponse {
         /** @var string[] */
         public $persons;
         /** @var string[] */
         public $tastes;
         /** @var string[] */
         public $meat;
         /** @var string[] */
         public $pizzas;
    }

    class PizzaListItem extends BaseResponse {
         public string $pizzeria;
         public string $id;
         public int $sizeId;
         public string $name;
         public float $size;
         public array $tastes;
         public array $meat;
         public float $price;
         public float $pizzaArea;
         public float $pizzaCmPrice;
         public string $thumbnail;
         public array $ingredients;
         public int $dough;
    }
    ```
4. **Result of generation from code**: two endpoints with description and arguments for `select`.

    ```
    ┌─────────┬─────────────────┬──────────────────────────┐
    │ get     │ /selector/lists │ Returns lists of filters │
    ├─────────┼─────────────────┼──────────────────────────┤
    │ Result (4)                                           │
    │ persons │ array of string │                          │
    │ tastes  │ array of string │                          │
    │ meat    │ array of string │                          │
    │ pizzas  │ array of string │                          │
    └─────────┴─────────────────┴──────────────────────────┘
    ┌──────────────────┬──────────────────┬───────────────────────────────────────────────────┐
    │ post             │ /selector/select │ Makes a selection of pizzas according to criteria │
    ├──────────────────┼──────────────────┼───────────────────────────────────────────────────┤
    │ Parameters (15)                                                                         │
    │ string           │ city             │                                                   │
    │ string           │ persons          │                                                   │
    │ boolean          │ vegetarian       │                                                   │
    │ number           │ maxPrice         │                                                   │
    │ array            │ pizzas           │                                                   │
    │ boolean          │ tastes.cheese    │                                                   │
    │ boolean          │ tastes.sausage   │                                                   │
    │ boolean          │ tastes.spicy     │                                                   │
    │ boolean          │ tastes.mushroom  │                                                   │
    │ boolean          │ tastes.exotic    │                                                   │
    │ boolean          │ meat.chicken     │                                                   │
    │ boolean          │ meat.pork        │                                                   │
    │ boolean          │ meat.beef        │                                                   │
    │ boolean          │ meat.fish        │                                                   │
    │ boolean          │ meat.sauce_meat  │                                                   │
    ├──────────────────┼──────────────────┼───────────────────────────────────────────────────┤
    │ Result (14)                                                                             │
    │                  │ array of         │                                                   │
    │ [*].pizzeria     │ string           │                                                   │
    │ [*].id           │ string           │                                                   │
    │ [*].sizeId       │ integer          │                                                   │
    │ [*].name         │ string           │                                                   │
    │ [*].size         │ integer          │                                                   │
    │ [*].tastes       │ array of         │                                                   │
    │ [*].meat         │ array of         │                                                   │
    │ [*].price        │ integer          │                                                   │
    │ [*].pizzaArea    │ integer          │                                                   │
    │ [*].pizzaCmPrice │ integer          │                                                   │
    │ [*].thumbnail    │ string           │                                                   │
    │ [*].ingredients  │ array of         │                                                   │
    │ [*].dough        │ integer          │                                                   │
    └──────────────────┴──────────────────┴───────────────────────────────────────────────────┘

    ```

How it works
------------

[](#how-it-works)

1. **Scraper** collects info about API (tags, security schemes and servers, all endpoints) and contains settings for Generator. Scraper is framework-dependent.
2. **Generator** fulfills openapi-specification with endpoints information by analyzing source code:
    - summary and description of actions
    - parameters and result of actions Generator is common. It just receives information from Scraper and analyzes code by Scraper rules.

More detailed process description is in [How it works document](docs/how_it_works.md).

How to use
----------

[](#how-to-use)

Invoke console script to generate openapi for your project (with help of integrations):

For example, for yii2-project:

1. Run parser on project to analyze files and retrieve info about endpoints ```
    ./vendor/bin/openapi-generator scrape --scraper yii2 ./
    # And more deeper scan
    ./vendor/bin/openapi-generator generate --scraper yii2 --inspect ./
    ```
2. Generate specification(s) into yaml-files in `api_docs` folder by **specification\_name.yml**```
    ./vendor/bin/openapi-generator generate --scraper yii2 ./ ./api_docs/
    # Or with your own scraper (child of one of basic scrapers)
    ./vendor/bin/openapi-generator generate --scraper components/api/OpenApiScraper.php ./ ./api_docs/
    ```
3. Deploy swagger with specification (e.g. *api\_docs/main.yml* on port 8091) ```
     docker run -p 8091:8080 --rm -e URL=./apis/main.yaml -v $(pwd):/usr/share/nginx/html/apis/ swaggerapi/swagger-ui:v4.15.2
    ```

More detailed description is in [How to use document](docs/how_to_use.md).

Integrations
------------

[](#integrations)

There's few integrations: Yii2, Laravel, Slim. Details is in [Integrations document](docs/integrations.md). You can write your own integration for framework or your project.

Extending
=========

[](#extending)

New scraper
-----------

[](#new-scraper)

You use (or extend) a predefined *scraper* (see Integrations) or create your own *scraper* from scratch (extend `DefaultScraper`), which should return a result with list of your API endpoints. Also, your scraper should provide tags, security schemes and so on.

Scraper should return list of **specifications** (for example, list of api versions) with:

- *meta* - version/description/externalDocs - of specification.
- *servers* - list of servers (base urls).
- *tags* - list of tags with description and other properties (categories for endpoints).
- *securitySchemes* - list of security schemes (authorization types).
- *endpoints* - list of API endpoints (separate callbacks).

Detailed information about Scraper result: [in another document](docs/scraper_result.md).

Settings
--------

[](#settings)

DefaultGenerator provides list of settings to tune generator.

ParametertypedefaultdescriptionCHANGE\_GET\_TO\_POST\_FOR\_COMPLEX\_PARAMETERSboolfalseif callback has arguments with `object` , `array` , `stdclass` , `mixed` type or class-typed, method of argument will be changed to `POST` and these arguments will be placed as `body` data in json-formatTREAT\_COMPLEX\_ARGUMENTS\_AS\_BODYboolfalsemove complex arguments to request bodyPARSE\_PARAMETERS\_FROM\_ENDPOINTboolfalseif callback `id` has macroses (`users/{id}`), these arguments will be parsed as normal callback argumentsPARSE\_PARAMETERS\_FORMAT\_FORMAT\_DESCRIPTIONboolfalseif php-doc for callback argument in first word after argument variable has one of predefined sub-types (`@param string $arg SUBTYPE Full parameter description `), this will change sub-type in resulting specification. For example, for `string` format there are subtypes: `date`, `date-time`, `password`, `byte`, `binary`, for `integer` there are: `float`, `double`, `int32`, `int64`. Also, you can defined custom format with `DefaultGenerator::setCustomFormat($format, $formatConfig)`Usage:

```
$generator->changeSetting(DefaultGenerator::CHANGE_GET_TO_POST_FOR_COMPLEX_PARAMETERS, true);
```

By default, they all are disabled.

Limitations
-----------

[](#limitations)

- Only query parameters supported (`url?param1=...&param2=...`) or body json parameters (`{data: 123`).
- Only one response type supported - HTTP 200 response.
- No support for parameters' / fields' / properties' `format`, `example` and other validators.

ToDo
----

[](#todo)

- Support for few operations on one endpoint (GET/POST/PUT/DELETE/...).
- Support for body parameters (when parameters are complex objects) - partially.
- Support for few responses (with different HTTP codes).
- Extracting class types into separate components (into openapi components).
- Support for other request/response types besides JSON
- Add `@paramFormat` for specifying parameter format - partially.
- Support for dynamic action arguments in dynamic model
- Switch 3.0/3.1 ()

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance43

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

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

Recently: every ~161 days

Total

30

Last Release

439d ago

PHP version history (2 changes)0.0.1PHP &gt;=7.1.0

0.4.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6000618?v=4)[Sergey](/maintainers/wapmorgan)[@wapmorgan](https://github.com/wapmorgan)

---

Top Contributors

[![wapmorgan](https://avatars.githubusercontent.com/u/6000618?v=4)](https://github.com/wapmorgan "wapmorgan (134 commits)")

---

Tags

apiapi-docs-generatorapi-documentationopenapiscraperswaggerapidocumentationswaggeropenapiopenapi-generatorswagger-generator

### Embed Badge

![Health badge](/badges/wapmorgan-openapi-generator/health.svg)

```
[![Health](https://phpackages.com/badges/wapmorgan-openapi-generator/health.svg)](https://phpackages.com/packages/wapmorgan-openapi-generator)
```

###  Alternatives

[swagger-api/swagger-ui

 Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

28.7k45.4M99](/packages/swagger-api-swagger-ui)[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)

PHPackages © 2026

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