Skip to main content

How It Works

Laravel OpenAPI Generator automatically scans your Laravel routes and generates comprehensive API documentation in multiple formats. The package follows a clear architecture that transforms your application’s routes into structured documentation.

Route Scanning

Automatically discovers API routes by inspecting Laravel’s routing system

Metadata Extraction

Analyzes controllers, FormRequests, and models to build complete specs

Multi-Format Output

Generates OpenAPI, Postman, and Insomnia documentation from a single source

Architecture

The package uses a layered architecture to generate documentation:

Core Components

The main orchestrator that coordinates the entire generation process.Key Responsibilities:
  • Route inspection and filtering
  • API type filtering
  • Cache management
  • Format conversion
Scans Laravel’s route collection and identifies API routes based on configured prefixes.Route Filtering Logic:
What Gets Scanned:
  • All routes starting with configured API prefixes (admin, site, mobile)
  • Routes not matching exclude patterns
  • Routes that pass API type filters
Resolves documentation for each endpoint using multiple sources:Priority System:
  1. JSON Templates - Pre-defined resource documentation
  2. FormRequest Rules - Validation rules from Form Request classes
  3. Model Attributes - Database schema from Eloquent models
  4. Generic Fallback - Default schemas when no metadata is found
Extracts field definitions from FormRequests and Models.From FormRequest:
Generates:

Route Processing Flow

1. Route Discovery

The package scans routes starting with these prefixes:
  • admin/* → Included in admin API type
  • mobile/* → Included in mobile API type
  • site/* → Included in site API type

2. URI Structure Parsing

Routes following the modular pattern: /{prefix}/{module}/{entity}/{action}
Detection Logic:

3. Operation Building

For each route, the generator creates an OpenAPI operation:

Caching Strategy

Generated specifications are cached to improve performance on subsequent requests.
Cache Key Structure:
Clear Cache:

Output Formats

OpenAPI 3.0.3

The canonical specification format. Used as the base for all other formats.

Postman Collection

Converts OpenAPI to Postman Collection v2.1 format with:
  • Test scripts for CRUD operations
  • Environment variable tracking
  • Organized folder structure

Insomnia Workspace

Converts to Insomnia v4 workspace format with:
  • Multiple environment configurations
  • Request chaining support
  • Folder hierarchy
All three formats are generated from the same OpenAPI specification, ensuring consistency across tools.

Next Steps

API Types

Learn how to organize routes into different API types

Environments

Configure multiple deployment environments