PHPackages                             ensi/laravel-openapi-server-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. ensi/laravel-openapi-server-generator

ActiveLibrary[API Development](/categories/api)

ensi/laravel-openapi-server-generator
=====================================

laravel openapi server generator

4.0.4(7mo ago)1572.7k↓37%3[1 issues](https://github.com/ensi-platform/laravel-openapi-server-generator/issues)MITPHPPHP ^8.1CI passing

Since Jun 5Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/ensi-platform/laravel-openapi-server-generator)[ Packagist](https://packagist.org/packages/ensi/laravel-openapi-server-generator)[ RSS](/packages/ensi-laravel-openapi-server-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (51)Used By (0)

Laravel OpenApi Server Generator
================================

[](#laravel-openapi-server-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/faa76d48826e7caff1baf2725c7137c4f1c8bf6dfe7c4caf8928b2ec5f09decd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e73692f6c61726176656c2d6f70656e6170692d7365727665722d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-openapi-server-generator)[![Tests](https://github.com/ensi-platform/laravel-php-rdkafka/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/ensi-platform/laravel-php-rdkafka/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/890bc6422663aea4929b5274ecc846ae3be5b4aed8b1910807ca98c865b77531/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e73692f6c61726176656c2d6f70656e6170692d7365727665722d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-openapi-server-generator)

Generates Laravel application code from Open Api Specification files

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

[](#installation)

You can install the package via composer:

```
composer require ensi/laravel-openapi-server-generator --dev
```

Publish the config file with:

```
php artisan vendor:publish --provider="Ensi\LaravelOpenApiServerGenerator\LaravelOpenApiServerGeneratorServiceProvider"
```

and configure all the options.

### Migrating from version 0.x.x

[](#migrating-from-version-0xx)

Delete `config/openapi-server-generator.php`, republish it using command above and recreate desired configuration.

Version Compatibility
---------------------

[](#version-compatibility)

Laravel OpenApi Server GeneratorLaravelPHP^0.0.2 - ^0.8.2^7.x^7.1.3^0.8.3 - ^0.9.0^7.x || ^8.x^7.1.3 || ^8.0^1.0.0 - ^1.1.2\*^8.0^2.0.0 - ^3.0.3\*^8.1^4.0.0^9.x || ^10.x || ^11.x^8.1#### Basic Usage

[](#basic-usage)

Run `php artisan openapi:generate-server`. It will generate all the configured entities from you OAS3 files.
Override `default_entities_to_generate` configiration with `php artisan openapi:generate-server -e routes,enums`
Make output more versbose: `php artisan openapi:generate-server -v`

Overwriting templates
---------------------

[](#overwriting-templates)

You can also adjust file templates according to your needs.

1. Find the needed template inside `templates` directory in this repo;
2. Copy it to to `resources/openapi-server-generator/templates` directory inside your application or configure package to use another directory via `extra_templates_path` option;
3. Change whatever you need.

Existing entities and generators
--------------------------------

[](#existing-entities-and-generators)

### 'routes' =&gt; RoutesGenerator::class

[](#routes--routesgeneratorclass)

Generates laravel route file (`route.php`) for each endpoint in `oas3->paths`
The following [extension properties](https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#specificationExtensions) are used by this generator:

```
x-lg-handler: '\App\Http\Controllers\CustomersController@create' // Optional. Path is ignored if this field is empty. You can use :: instead of @ if you want
x-lg-route-name: 'createCustomer' // Optional. Translates to `->name('createCustomer')`
x-lg-middleware: '\App\Http\Middleware\Authenticate::class,web'  // Optional. Translates to `->middleware([\App\Http\Middleware\Authenticate::class, 'web'])`
x-lg-without-middleware: '\App\Http\Middleware\Authenticate::class,web'  // Optional. Translates to `->withoutMiddleware([\App\Http\Middleware\Authenticate::class, 'web'])`

```

`route.php` file IS overriden with each generation.
You should include it in your main route file like that:

```
$generatedRoutes = __DIR__ . "/OpenApiGenerated/routes.php";
if (file_exists($generatedRoutes)) { // prevents your app and artisan from breaking if there is no autogenerated route file for some reason.
    require $generatedRoutes;
}
```

### 'controllers' =&gt; ControllersGenerator::class

[](#controllers--controllersgeneratorclass)

Generates Controller class for each non-existing class specified in `x-lg-handler`
Supports invocable Controllers.
If several openapi paths point to several methods in one Controller/Handler then the generated class includes all of them.
If a class already exists it is NOT overriden.
Controller class IS meant to be modified after generation.

### 'requests' =&gt; RequestsGenerator::class

[](#requests--requestsgeneratorclass)

Generates Laravel Form Requests for DELETE, PATCH, POST, PUT paths
Destination must be configured with array as namespace instead of string.
E.g.

```
'requests' => [
    'namespace' => ["Controllers" => "Requests"]
],
```

This means "Get handler (x-lg-handler) namespace and replace Controllers with Requests in it"
Form Request class IS meant to be modified after generation. You can treat it as a template generated with `php artisan make:request FooRequest`
If the file already exists it IS NOT overriden with each generation.

Form Request class name is `ucFirst(operationId)`. You can override it with `x-lg-request-class-name`
You can skip generating form request for a give route with `x-lg-skip-request-generation: true` directive.

When generating a request, the Laravel Validation rules for request fields are automatically generated.
Validation rules generate based on the field type and required field.
For fields whose values should only take the values of some enum, you must specify the `x-lg-enum-class option`. E.g.: `x-lg-enum-class: 'CustomerGenderEnum'`.

### 'enums' =&gt; EnumsGenerator::class

[](#enums--enumsgeneratorclass)

Generates Enum class only for enums listed in `oas3->components->schemas`.
Your need to specify `x-enum-varnames` field in each enum schema. The values are used as enum constants' names.
Destination directory is cleared before generation to make sure all unused enum classes are deleted.
Enums generator does NOT support `allOf`, `anyOf` and `oneOf` at the moment.

### 'pest\_tests' =&gt; PestTestsGenerator::class

[](#pest_tests--pesttestsgeneratorclass)

Generates Pest test file for each `x-lg-handler`
You can exclude oas3 path from test generation using `x-lg-skip-tests-generation: true`.
If a test file already exists it is NOT overriden.
Test file class IS meant to be modified after generation.

### 'resources' =&gt; ResourcesGenerator::class

[](#resources--resourcesgeneratorclass)

Generates Resource file for `x-lg-handler`
Resource properties are generated relative to field in response, which can be set in the config

```
'resources' => [
    'response_key' => 'data'
],
```

You can also specify `response_key` for resource: add `x-lg-resource-response-key: data` in object.
When specifying `response_key`, you can use the "dot" syntax to specify nesting, for example `data.field`
You can exclude resource generation using `x-lg-skip-resource-generation: true` in route.
You can rename resource Class using `x-lg-resource-class-name: FooResource` in resource object or properties object.
If a resource file already exists it is NOT overridden.
Resource file contains a set of fields according to the specification. You also need to specify mixin DocBlock to autocomplete resource.

### 'policies' =&gt; PoliciesGenerator::class

[](#policies--policiesgeneratorclass)

Generates Laravel Policies for routes. Destination must be configured with array as namespace instead of string. E.g:

```
'policies' => [
    'namespace' => ["Controllers" => "Policies"]
],
```

- The path must contain a 403 response or the policy will not be generated.
- You can exclude policy generation using `x-lg-skip-policy-generation: true` in route.
- If a policy file already exists it is NOT overridden.

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

[](#contributing)

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

### Testing

[](#testing)

1. composer install
2. composer test

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.

License
-------

[](#license)

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

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance63

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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

Recently: every ~119 days

Total

50

Last Release

215d ago

Major Versions

0.9.0 → 1.0.02021-10-13

1.1.2 → 2.0.02022-02-16

2.0.18 → 3.0.02023-07-11

3.0.3 → 4.0.02024-06-26

PHP version history (4 changes)0.1.0PHP ^7.1.3

0.8.3PHP ^7.1.3 || ^8.0

1.0.0PHP ^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8089373?v=4)[Наталия](/maintainers/MsNatali)[@MsNatali](https://github.com/MsNatali)

![](https://avatars.githubusercontent.com/u/7352966?v=4)[Andrey](/maintainers/dimionx)[@DimionX](https://github.com/DimionX)

---

Top Contributors

[![MsNatali](https://avatars.githubusercontent.com/u/8089373?v=4)](https://github.com/MsNatali "MsNatali (46 commits)")[![Baristanko](https://avatars.githubusercontent.com/u/9207769?v=4)](https://github.com/Baristanko "Baristanko (27 commits)")[![arrilot](https://avatars.githubusercontent.com/u/2826480?v=4)](https://github.com/arrilot "arrilot (22 commits)")[![DimionX](https://avatars.githubusercontent.com/u/7352966?v=4)](https://github.com/DimionX "DimionX (11 commits)")[![filippovano](https://avatars.githubusercontent.com/u/58265848?v=4)](https://github.com/filippovano "filippovano (10 commits)")[![mtyrtov](https://avatars.githubusercontent.com/u/39631083?v=4)](https://github.com/mtyrtov "mtyrtov (8 commits)")[![Se7en-RU](https://avatars.githubusercontent.com/u/24911713?v=4)](https://github.com/Se7en-RU "Se7en-RU (7 commits)")[![valerialukinykh](https://avatars.githubusercontent.com/u/123940772?v=4)](https://github.com/valerialukinykh "valerialukinykh (7 commits)")[![setopt](https://avatars.githubusercontent.com/u/38655841?v=4)](https://github.com/setopt "setopt (7 commits)")[![rusev-ivan](https://avatars.githubusercontent.com/u/68227103?v=4)](https://github.com/rusev-ivan "rusev-ivan (5 commits)")[![C0rTeZ13](https://avatars.githubusercontent.com/u/120840631?v=4)](https://github.com/C0rTeZ13 "C0rTeZ13 (4 commits)")[![imamberdievf](https://avatars.githubusercontent.com/u/79088728?v=4)](https://github.com/imamberdievf "imamberdievf (2 commits)")[![Alex-Pir](https://avatars.githubusercontent.com/u/69367321?v=4)](https://github.com/Alex-Pir "Alex-Pir (1 commits)")[![Timzan](https://avatars.githubusercontent.com/u/54365038?v=4)](https://github.com/Timzan "Timzan (1 commits)")[![egmanoylin](https://avatars.githubusercontent.com/u/77325193?v=4)](https://github.com/egmanoylin "egmanoylin (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ensi-laravel-openapi-server-generator/health.svg)

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

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

A powerful Laravel package for integrating Large Language Models (LLMs) into your applications.

2.3k388.3k10](/packages/echolabsdev-prism)[sburina/laravel-whmcs-up

WHMCS API client and user provider for Laravel

271.3k](/packages/sburina-laravel-whmcs-up)

PHPackages © 2026

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