Skip to main content
The Laravel OpenAPI Generator service provider publishes two groups of assets: configuration files and template files. This guide explains what gets published, how to customize them, and best practices.

Configuration Files

Publish all configuration files with a single command:

Published Files

This command publishes four configuration files to your config/ directory:
Main configuration file containing:
  • OpenAPI metadata (title, version, contact, license)
  • Server definitions for different environments
  • Security scheme definitions (Bearer, API Key, etc.)
  • Hierarchical environments for Postman/Insomnia
  • API type configurations (admin, site, mobile)
  • Module scanning paths and exclusions
  • Cache settings
  • Output path configuration
  • Model and request class paths
  • Route filtering and exclusions
  • Middleware to security mapping
  • Default response examples
  • HTTP route configuration
File location: config/openapi.php
CRUD and entity documentation configuration containing:
  • CRUD template definitions (summary, description, response templates)
  • Entity metadata (singular/plural names, model classes, descriptions)
  • Custom endpoint documentation
  • Auto-detection settings for fields and relationships
  • Field description overrides
  • Field example overrides
File location: config/openapi-docs.php
Template system configuration containing:
  • Template system enable/disable toggle
  • Template directory paths (generic and custom)
  • Generic template mappings for actions
  • Query builder documentation settings
  • Auto-detection configuration for models
  • Rendering options (debug, validation, caching)
  • Example generation settings
  • Performance limits and caching
File location: config/openapi-templates.php
Test generation configuration containing:
  • Test template definitions for CRUD actions
  • Test script snippets for Postman
  • Test script snippets for Insomnia
  • Custom test overrides for specific endpoints
  • Verbose logging settings
File location: config/openapi-tests.php

Customizing Configuration

After publishing, you can customize any configuration values:
Configuration changes take effect immediately. If caching is enabled, you may need to clear the cache:

Template Files

Publish template files separately:

Published Template Structure

Templates are published to resources/openapi/templates/ with the following structure:

Template Types

Location: resources/openapi/templates/generic/Generic templates define documentation structure for common CRUD operations:
  • index.json: List/paginated collection endpoints
  • show.json: Single resource retrieval
  • store.json: Resource creation
  • update.json: Resource updates
  • destroy.json: Resource deletion
These templates use placeholders that are automatically replaced with model-specific data during generation.Example: generic/show.json
Location: resources/openapi/templates/custom/Custom templates allow you to define documentation for non-CRUD endpoints or override generic templates for specific resources.Example: custom/users_login.json

Template Placeholders

Templates support automatic placeholder replacement:
Placeholders are automatically extracted from your models using reflection and database schema inspection.

Publishing Workflow

Initial Setup

When setting up a new project:

Updating Published Assets

When updating the package to a new version:
Publishing again will overwrite your customized files. Back up your changes first.
Better approach: Use version control and selectively merge new options:

File Locations Reference

Configuration Files

Template Files

Generated Output

Output location can be customized via the openapi.output_path configuration option.

Advanced Customization

Custom Security Schemes

Add OAuth2, OpenID Connect, or custom authentication:
config/openapi.php

Multiple API Versions

Document multiple API versions simultaneously:
config/openapi.php

Custom Response Schemas

Add custom response schemas for your API:
config/openapi.php

Environment-Specific Servers

Define servers for different deployment environments:
config/openapi.php

Best Practices

Commit published files to version control:
This ensures all team members use the same configuration.
Use .env for environment-specific values:
config/openapi.php
Then set different values per environment:
.env.production
Publish only what you need:
You don’t need to publish templates unless you’re customizing them.
Document your customizations:Add comments to your config files explaining custom settings:
config/openapi.php
Use custom templates sparingly:Only create custom templates when generic templates don’t fit. This reduces maintenance burden when the package is updated.Good:
Avoid:

Troubleshooting

Problem: Changes to config files don’t take effect.Solution: Clear configuration cache:
Problem: Generator can’t find custom templates.Solution: Verify template paths in config/openapi-templates.php:
Ensure directories exist:
Problem: Re-publishing overwrites your changes.Solution: Use version control and selective merging: