The openapi:generate command is the primary CLI interface for generating OpenAPI specifications, Postman collections, and Insomnia workspaces from your Laravel routes.Command Class:Ronu\OpenApiGenerator\Commands\GenerateOpenApiSpec Location:src/Commands/GenerateOpenApiSpec.php
Custom output file path. When not specified, uses the configured output_path from config.Example:/path/to/custom/openapi.json
Default Behavior:When --output is not provided, the command generates files in the directory specified by config('openapi.output_path') (default: storage/app/public/openapi).File Naming Convention:
OpenAPI: openapi-{apiType}.json or openapi-all.json
Postman: postman-{apiType}.json or postman-all.json
Insomnia: insomnia-{apiType}.json or insomnia-all.json
Examples:
# Use default output pathphp artisan openapi:generate# Output: storage/app/public/openapi/openapi-all.json# Custom output pathphp artisan openapi:generate --output=/var/www/docs/api-spec.json# Output: /var/www/docs/api-spec.json# Custom path with API type filterphp artisan openapi:generate --api-type=mobile --output=./mobile-api.json# Output: ./mobile-api.json
When present, bypasses the cache and forces fresh generation. Useful during development or when routes have changed.
Default Behavior:By default, the command uses caching if enabled in config('openapi.cache.enabled'). The cache key includes the API types, environment, and format.Cache Configuration:
# Use cache (default)php artisan openapi:generate# Force fresh generationphp artisan openapi:generate --no-cache# Force fresh generation for specific API typephp artisan openapi:generate --api-type=admin --no-cache
Filter by one or more API types. Can be repeated for multiple types.Common values:api, site, mobile, adminMultiple values: Repeat the option or use array syntax
API Types:API types are configured in config/openapi.php under the api_types key. Each type has:
prefix - Route prefix (e.g., api, mobile)
folder_name - Display name
enabled - Whether the type is active
Examples:
# Generate for all API types (default)php artisan openapi:generate# Generate only for 'api' typephp artisan openapi:generate --api-type=api# Generate for multiple API typesphp artisan openapi:generate --api-type=api --api-type=mobile# Alternative multiple types syntaxphp artisan openapi:generate --api-type=admin --api-type=mobile
Output File Naming:
# Single API typephp artisan openapi:generate --api-type=mobile# Output: storage/app/public/openapi/openapi-mobile.json# Multiple API typesphp artisan openapi:generate --api-type=api --api-type=mobile# Output: storage/app/public/openapi/openapi-api-mobile.json
Validation:The command validates API types against enabled types in configuration:
# Invalid API typephp artisan openapi:generate --api-type=invalid# Error: Unknown or disabled API types: invalid. Available types: api, mobile, admin
When present, generates OpenAPI specification, Postman collection, and Insomnia workspace for ALL enabled API types.Equivalent to:--with-postman --with-insomnia with no --api-type filter
Behavior:When --all is used:
Ignores --api-type filters (generates for all enabled types)
Automatically enables Postman and Insomnia generation
When present, generates an Insomnia Workspace v4 along with the OpenAPI spec.Includes multiple environments (base + artisan + local + production) embedded in the workspace.
Output Files:
Insomnia workspace: insomnia-{apiType}.json
Examples:
# Generate OpenAPI + Insomniaphp artisan openapi:generate --with-insomnia# For specific API typephp artisan openapi:generate --api-type=mobile --with-insomnia# Both Postman and Insomniaphp artisan openapi:generate --with-postman --with-insomnia
Insomnia Workspace Features:
Multiple environments included (no separate files needed)
Request chaining with response variable extraction
Automated test suites
Minimal API Spec tab (OpenAPI viewer)
Request folders organized by module
Import Instructions:
📥 Import instructions: Insomnia Workspace: 1. Import insomnia-mobile.json 2. Environments are already included 3. Check Spec, Collection, and Test tabs
# Use artisan environment (default)php artisan openapi:generate# Use local environmentphp artisan openapi:generate --environment=local# Production environment with API typephp artisan openapi:generate --api-type=api --environment=production# All formats with production environmentphp artisan openapi:generate --all --environment=production
Validation:The command validates environment names and falls back to artisan for unknown values:
# Unknown environmentphp artisan openapi:generate --environment=staging# Warning: Unknown environment 'staging', using 'artisan' as default
🚀 Generating OpenAPI Specification...🔍 Filtering API types: site📋 Inspecting routes...✅ Found 0 unique paths⚠️ No routes found matching the specified filters