Skip to main content

Overview

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

Command Signature

Full Signature:
Location: 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: json
Examples:
Validation: The command validates the format and returns an error for invalid values:
Location: src/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
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:

—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.
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:
Examples:
Location: 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 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:
Output File Naming:
Validation: The command validates API types against enabled types in configuration:
Location: 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
Behavior: When --all is used:
  1. Ignores --api-type filters (generates for all enabled types)
  2. Automatically enables Postman and Insomnia generation
  3. Creates files named with -all suffix
Output Files:
  • openapi-all.json (or .yaml)
  • postman-all.json
  • insomnia-all.json
  • postman-env-artisan.json
  • postman-env-local.json
  • postman-env-production.json
Examples:
Console Output:
Location: 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.
Output Files:
  • Postman collection: postman-{apiType}.json
  • Environment files:
    • postman-env-artisan.json
    • postman-env-local.json
    • postman-env-production.json
Examples:
Postman Collection Features:
  • 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_id for chaining requests)
Import Instructions:
Location: 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.
Output Files:
  • Insomnia workspace: insomnia-{apiType}.json
Examples:
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:
Location: 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: artisan
Environment Configuration: Environments are defined in config/openapi.php under the environments key:
Effect on Generation: The environment determines:
  1. The servers array in OpenAPI spec
  2. Base URL variables in Postman/Insomnia
  3. Environment-specific variable values
Examples:
Validation: The command validates environment names and falls back to artisan for unknown values:
Location: src/Commands/GenerateOpenApiSpec.php:87, 96-101

Usage Examples

Basic Usage

Output:

Generate for Specific API Type

Output:

Generate Multiple API Types with Postman

Output:

Generate Everything (All Formats)

Output: Generates OpenAPI + Postman + Insomnia for all enabled API types.

Production Export with Custom Path


Development Workflow


Output Files

Default Output Directory

Files are saved to the path specified in config/openapi.php:
Default location: 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

Output:
Exit Code: 1 (FAILURE)

Invalid API Type

Output:
Exit Code: 1 (FAILURE)

No Routes Found

Output:
Exit Code: 0 (SUCCESS) - Not treated as error

Verbose Error Output

For detailed error information, use the -v flag:
Location: src/Commands/GenerateOpenApiSpec.php:161-170

Exit Codes

Location: src/Commands/GenerateOpenApiSpec.php:160, 169, 220

Integration with CI/CD

GitHub Actions


GitLab CI


Public API

Programmatic generation API

Configuration

Configure API types and environments

Postman Export

Working with Postman collections

Insomnia Export

Working with Insomnia workspaces