Documentation Index
Fetch the complete documentation index at: https://mintlify.com/charlietyn/openapi-generator/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Laravel OpenAPI Generator provides a clean programmatic API for generating OpenAPI specifications, Postman collections, and Insomnia workspaces. You can use either the facade or inject the service directly.Facade
The package registers a facade for convenient access:Facade Accessor
The facade resolves to theRonu\OpenApiGenerator\OpenApiGenerator service class.
Location: src/Facades/OpenApiGenerator.php:10
Service Class: OpenApiGenerator
The main service class provides four public methods for generating specifications. Location:src/OpenApiGenerator.php
generate()
Generate a specification in any supported format. Signature:Enable or disable cache for generation. When
true, results are cached based on the cache configuration.Filter by specific API types. Pass an array of type keys (e.g.,
['api', 'mobile']). When null, all enabled API types are included.Environment name to apply (e.g.,
'artisan', 'local', 'production'). When null, uses the default environment from configuration.Output format:
'openapi', 'postman', or 'insomnia'.array - The generated specification structure.
Example:
generateOpenApi()
Convenience method for generating OpenAPI 3.0.3 specifications. Signature:Enable or disable cache for generation.
Filter by specific API types.
Environment name to apply.
array - OpenAPI 3.0.3 specification.
Implementation:
This method internally calls generate() with format = 'openapi'.
Location: src/OpenApiGenerator.php:22-28
Example:
generatePostman()
Generate a Postman Collection (v2.1 format). Signature:Enable or disable cache for generation.
Filter by specific API types.
Environment name to apply for base URL and variables.
array - Postman Collection JSON structure.
Implementation:
This method internally calls generate() with format = 'postman'.
Location: src/OpenApiGenerator.php:30-36
Example:
generateInsomnia()
Generate an Insomnia Workspace (v4 format). Signature:Enable or disable cache for generation.
Filter by specific API types.
Environment name to apply for base URL and variables.
array - Insomnia Workspace JSON structure.
Implementation:
This method internally calls generate() with format = 'insomnia'.
Location: src/OpenApiGenerator.php:38-44
Example:
Dependency Injection
You can also inject the service directly into your controllers or services:Service Provider
The package is auto-discovered via Laravel’s package discovery. Provider:Ronu\OpenApiGenerator\Providers\OpenApiGeneratorServiceProvider
Responsibilities:
- Registers
OpenApiServicesandOpenApiGeneratoras singletons - Publishes configuration files
- Registers Artisan commands
- Registers HTTP routes (if enabled)
HTTP Controller (Optional)
If HTTP routes are enabled (openapi.routes.enabled = true), the package provides a controller for web access.
Controller: Ronu\OpenApiGenerator\Controllers\OpenApiController
Available HTTP Endpoints:
| Route | Method | Description |
|---|---|---|
/documentation/openapi.{format} | GET | Generate OpenAPI spec (JSON/YAML) |
/documentation/postman | GET | Generate Postman collection |
/documentation/insomnia | GET | Generate Insomnia workspace |
/documentation/environments/{format?} | GET | Get all environments |
api_type- Comma-separated list of API typesenvironment- Environment name
Return Value Structure
OpenAPI Format
Returns an OpenAPI 3.0.3 compliant specification:OpenAPI version (
3.0.3)API metadata (title, version, description, contact, license)
Array of server objects with URLs and descriptions
All API endpoints with operations (GET, POST, etc.)
Resource grouping tags
Reusable schemas and security definitions
Postman Format
Returns a Postman Collection v2.1 structure with:- Collection metadata
- Folders grouped by module
- Pre-request scripts for token management
- Tests for response validation
- Variable references
Insomnia Format
Returns an Insomnia v4 workspace with:- Workspace metadata
- Request groups
- Multiple environments (base + artisan + local + production)
- Request chaining via response variables
- Automated tests
Error Handling
All methods may throw the following exceptions:See the Exceptions page for detailed error handling documentation.
InvalidArgumentException- Invalid API type or environment nameException- General generation errors (invalid configuration, missing templates)
Cache Management
The service respects the cache configuration inconfig/openapi.php:
OpenApiServices class provides a cache clearing method:
Related Documentation
Artisan Commands
CLI command reference
Configuration
Configure API types and environments
Exceptions
Error handling guide
HTTP Routes
Configure web endpoints