Overview
Theopenapi: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\GenerateOpenApiSpecLocation:
src/Commands/GenerateOpenApiSpec.php
Command Signature
src/Commands/GenerateOpenApiSpec.php:40-48
Options Reference
—format
Specify the output format for the OpenAPI specification.string
default:"json"
Output format for OpenAPI specification.Allowed values:
json, yaml, ymlDefault: jsonsrc/Commands/GenerateOpenApiSpec.php:91-94
—output
Override the default output file path.string
default:"null"
Custom output file path. When not specified, uses the configured
output_path from config.Example: /path/to/custom/openapi.json--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}.jsonoropenapi-all.json - Postman:
postman-{apiType}.jsonorpostman-all.json - Insomnia:
insomnia-{apiType}.jsonorinsomnia-all.json
—no-cache
Disable caching for this generation run.flag
default:"false"
When present, bypasses the cache and forces fresh generation. Useful during development or when routes have changed.
config('openapi.cache.enabled'). The cache key includes the API types, environment, and format.
Cache Configuration:
src/Commands/GenerateOpenApiSpec.php:82
—api-type
Filter routes by API type. Can be specified multiple times for multiple API types.string[]
default:"[]"
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 syntaxconfig/openapi.php under the api_types key. Each type has:
prefix- Route prefix (e.g.,api,mobile)folder_name- Display nameenabled- Whether the type is active
src/Commands/GenerateOpenApiSpec.php:83, 109-118
—all
Generate all artifact formats (OpenAPI + Postman + Insomnia) for all API types.flag
default:"false"
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--all is used:
- Ignores
--api-typefilters (generates for all enabled types) - Automatically enables Postman and Insomnia generation
- Creates files named with
-allsuffix
openapi-all.json(or.yaml)postman-all.jsoninsomnia-all.jsonpostman-env-artisan.jsonpostman-env-local.jsonpostman-env-production.json
src/Commands/GenerateOpenApiSpec.php:84, 104-106, 176-221
—with-postman
Generate Postman collection in addition to OpenAPI specification.flag
default:"false"
When present, generates a Postman Collection v2.1 along with the OpenAPI spec.Also generates environment files for artisan, local, and production.
- Postman collection:
postman-{apiType}.json - Environment files:
postman-env-artisan.jsonpostman-env-local.jsonpostman-env-production.json
- Pre-request scripts for token extraction
- Request folders organized by module
- Environment variable placeholders (
{{base_url}},{{token}}) - Response validation tests
- Variable tracking (e.g.,
last_user_idfor chaining requests)
src/Commands/GenerateOpenApiSpec.php:85-86, 145-152, 247-278
—with-insomnia
Generate Insomnia workspace in addition to OpenAPI specification.flag
default:"false"
When present, generates an Insomnia Workspace v4 along with the OpenAPI spec.Includes multiple environments (base + artisan + local + production) embedded in the workspace.
- Insomnia workspace:
insomnia-{apiType}.json
- 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
src/Commands/GenerateOpenApiSpec.php:86-87, 149-152, 283-305
—environment
Select the environment configuration for base URLs and variables.string
default:"artisan"
Environment name to use for server URLs and variable values.Common values:
artisan, local, productionDefault: artisanconfig/openapi.php under the environments key:
- The
serversarray in OpenAPI spec - Base URL variables in Postman/Insomnia
- Environment-specific variable values
artisan for unknown values:
src/Commands/GenerateOpenApiSpec.php:87, 96-101
Usage Examples
Basic Usage
Generate for Specific API Type
Generate Multiple API Types with Postman
Generate Everything (All Formats)
Production Export with Custom Path
Development Workflow
Output Files
Default Output Directory
Files are saved to the path specified inconfig/openapi.php:
storage/app/public/openapi/
File Naming Convention
Location:
src/Commands/GenerateOpenApiSpec.php:136-139 and src/Services/OpenApiServices.php:1493-1505
Error Handling
Invalid Format
1 (FAILURE)
Invalid API Type
1 (FAILURE)
No Routes Found
0 (SUCCESS) - Not treated as error
Verbose Error Output
For detailed error information, use the-v flag:
src/Commands/GenerateOpenApiSpec.php:161-170
Exit Codes
Location:
src/Commands/GenerateOpenApiSpec.php:160, 169, 220
Integration with CI/CD
GitHub Actions
GitLab CI
Related Documentation
Public API
Programmatic generation API
Configuration
Configure API types and environments
Postman Export
Working with Postman collections
Insomnia Export
Working with Insomnia workspaces