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

ActiveLibrary[API Development](/categories/api)

danialzash/laravel-openapi-generator
====================================

Automatically generate OpenAPI 3.1 specifications from Laravel routes, requests, and responses

v1.0.2(4mo ago)10MITPHPPHP ^8.1CI failing

Since Jan 6Pushed 4mo agoCompare

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

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

Laravel OpenAPI Generator
=========================

[](#laravel-openapi-generator)

A powerful Laravel package that automatically generates OpenAPI 3.1 specifications from your Laravel application by analyzing routes, form requests, controllers, and JSON resources.

Features
--------

[](#features)

- **Automatic Route Analysis**: Scans all Laravel routes and extracts parameters, middleware, and controller information
- **Request Validation Mapping**: Converts Laravel validation rules to OpenAPI schema definitions
- **Response Schema Detection**: Analyzes JsonResource classes to generate response schemas
- **Security Scheme Detection**: Maps authentication middleware to OpenAPI security schemes
- **Database-Driven Metadata**: Store custom descriptions, examples, and tags in the database
- **Incremental Updates**: Track route changes and update documentation incrementally

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

[](#installation)

### 1. Add the package to your composer.json

[](#1-add-the-package-to-your-composerjson)

```
{
    "repositories": [
        {
            "type": "path",
            "url": "./packages/openapi-generator"
        }
    ],
    "require": {
        "verge/laravel-openapi-generator": "*"
    }
}
```

### 2. Run composer update

[](#2-run-composer-update)

```
composer update
```

### 3. Publish the configuration (optional)

[](#3-publish-the-configuration-optional)

```
php artisan vendor:publish --tag=openapi-generator-config
```

### 4. Run migrations

[](#4-run-migrations)

```
php artisan migrate
```

Usage
-----

[](#usage)

### Scan Routes

[](#scan-routes)

Scan your application routes and populate the metadata database:

```
# Scan routes
php artisan openapi:scan

# Rescan all routes (fresh start)
php artisan openapi:scan --fresh

# Preview changes without saving
php artisan openapi:scan --dry-run
```

### Generate OpenAPI Specification

[](#generate-openapi-specification)

Generate the OpenAPI specification file:

```
# Generate to default location (public/docs/openapi.yaml)
php artisan openapi:generate

# Generate to custom location
php artisan openapi:generate --output=/path/to/openapi.yaml

# Generate as JSON
php artisan openapi:generate --format=json

# Output to stdout
php artisan openapi:generate --stdout
```

### Sync Metadata

[](#sync-metadata)

Synchronize database metadata with current codebase:

```
# Check sync status
php artisan openapi:sync

# Remove orphaned entries
php artisan openapi:sync --clean

# Initialize security schemes from config
php artisan openapi:sync --init-security
```

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

[](#configuration)

The configuration file allows you to customize:

### API Info

[](#api-info)

```
'info' => [
    'title' => env('OPENAPI_TITLE', 'API Documentation'),
    'version' => env('OPENAPI_VERSION', '1.0.0'),
    'description' => '',
],
```

### Route Filters

[](#route-filters)

```
'route_filters' => [
    'include_prefixes' => ['api/', 'v1/'],
    'exclude_prefixes' => ['_ignition', 'sanctum'],
    'exclude_middleware' => ['web'],
],
```

### Security Schemes

[](#security-schemes)

```
'security_schemes' => [
    'bearerAuth' => [
        'type' => 'http',
        'scheme' => 'bearer',
        'bearerFormat' => 'JWT',
        'middleware' => ['auth:sanctum', 'auth:api'],
    ],
],
```

### Response Macros

[](#response-macros)

Map custom response helpers to HTTP status codes:

```
'response_macros' => [
    'show' => ['status' => 200, 'description' => 'Successful response'],
    'created' => ['status' => 201, 'description' => 'Resource created'],
],
```

Adding Custom Metadata
----------------------

[](#adding-custom-metadata)

### Via Database

[](#via-database)

After scanning routes, you can update metadata directly in the database:

```
use Verge\OpenAPIGenerator\Models\RouteMetadata;

$route = RouteMetadata::findByRoute('GET', '/api/users');
$route->update([
    'summary' => 'List all users',
    'description' => 'Retrieve a paginated list of all users in the system.',
    'tags' => ['Users', 'Admin'],
    'request_body_example' => ['name' => 'John Doe'],
]);
```

### Via Custom Schemas

[](#via-custom-schemas)

Add custom schema definitions:

```
use Verge\OpenAPIGenerator\Models\SchemaDefinition;

SchemaDefinition::create([
    'name' => 'UserResponse',
    'schema' => [
        'type' => 'object',
        'properties' => [
            'id' => ['type' => 'string', 'format' => 'uuid'],
            'name' => ['type' => 'string'],
            'email' => ['type' => 'string', 'format' => 'email'],
        ],
    ],
    'description' => 'User response object',
]);
```

Validation Rule Mapping
-----------------------

[](#validation-rule-mapping)

The package automatically maps Laravel validation rules to OpenAPI types:

Laravel RuleOpenAPI Type`string``type: string``integer``type: integer``numeric``type: number``boolean``type: boolean``array``type: array``email``type: string, format: email``url``type: string, format: uri``uuid``type: string, format: uuid``date``type: string, format: date``in:a,b,c``enum: [a, b, c]``min:N``minimum: N` or `minLength: N``max:N``maximum: N` or `maxLength: N``required`Added to `required` array`nullable``nullable: true`Programmatic Usage
------------------

[](#programmatic-usage)

```
use Verge\OpenAPIGenerator\Builders\OpenAPIBuilder;

$builder = app(OpenAPIBuilder::class);

// Build the specification
$spec = $builder->build();

// Get as YAML
$yaml = $builder->toYaml();

// Get as JSON
$json = $builder->toJson();

// Save to file
$builder->save('/path/to/openapi.yaml', 'yaml');

// Get statistics
$stats = $builder->getStatistics();
```

License
-------

[](#license)

MIT License

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance77

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

125d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c074a8523f1d40ffb6037b8d6c6d642307b83d804acfb05b312b7fb65b17bcf?d=identicon)[danialzash](/maintainers/danialzash)

---

Top Contributors

[![danialzash](https://avatars.githubusercontent.com/u/40217623?v=4)](https://github.com/danialzash "danialzash (6 commits)")

---

Tags

apilaraveldocumentationswaggeropenapigenerator

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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