Skip to main content
This guide covers edge cases, extreme scenarios, and troubleshooting strategies for production environments.

Config Caching with Runtime env() Usage

Symptom

Changing .env values (e.g., APP_NAME, APP_URL) does not affect generated documentation output.

Cause

Laravel’s config:cache freezes configuration values. Some package code reads env() directly at runtime instead of relying solely on cached config values. When config is cached, these env() calls return null.

Affected Areas

  • PlaceholderHelper::getProjectName() - Reads APP_NAME via env()
  • EnvironmentGenerator::buildBaseEnvironmentData() - Reads APP_URL via env()

Mitigation

1

Prefer config overrides

Instead of relying on .env values, set config values explicitly in config/openapi.php:
2

Clear config cache after changes

When changing .env values:
3

Avoid config cache in development

Only use config:cache in production. In local/staging, keep config uncached to allow dynamic .env changes.

How to Reproduce

How to Test

Production ImpactIf you deploy with cached config and rely on env() values, your documentation will show stale or incorrect information. Always set critical values in config files, not .env.

Concurrent Generation Writes to Same Output File

Symptom

Partially written or inconsistent JSON/YAML files in storage/app/public/openapi. Files may contain truncated JSON or mixed content from multiple generations.

Cause

Multiple workers, developers, or CI jobs running openapi:generate simultaneously write to the same output filenames, causing race conditions.

Mitigation

Use --output to write to unique file names per job:

How to Reproduce

How to Test

Add file locking and run the same concurrent test. Verify that one generation waits for the other to complete.

Long-Running Queue Workers and Stale Caches

Symptom

Old or stale documentation when running generation from a long-lived queue worker. New routes or validation rules don’t appear in output.

Cause

The generator caches output when openapi.cache.enabled is true. Long-lived workers reuse cached data even after code changes.

Mitigation

1

Disable cache for queue jobs

2

Reduce cache TTL

For frequently changing APIs, reduce cache time-to-live:
3

Clear cache on deployment

Add cache clearing to deployment scripts:

How to Reproduce

How to Test


Large Route Sets Causing Timeouts

Symptom

HTTP requests to /documentation/openapi.json time out or return 500 errors. Large applications with hundreds of routes cause generation to exceed PHP execution limits.

Cause

On-demand HTTP generation performs heavy introspection:
  • Route extraction
  • FormRequest validation analysis
  • Model schema reflection
  • Template processing
For large apps, this exceeds the default 30-60 second timeout.

Mitigation

Recommended: Generate docs via CLI and serve static files:
Serve from:

How to Reproduce

Create a large number of routes:

How to Test

Compare response times:
Performance Benchmarks
  • 50 routes: Less than 1 second
  • 200 routes: 2-5 seconds
  • 500+ routes: 10-30 seconds (consider CLI generation)

Multi-Tenant Deployments

Symptom

OpenAPI info title, server URLs, and environments do not reflect tenant-specific settings. All tenants get the same generic documentation.

Cause

Configuration is global. The generator reads app-level config values, not tenant-specific overrides.

Mitigation

1

Generate docs per tenant

2

Store per-tenant output

Use tenant-specific output paths:
Serve from tenant-specific URLs:
3

Dynamic HTTP routes

Serve tenant-specific docs via HTTP:

How to Reproduce

How to Test


Rate Limiting or Auth Middleware Blocking HTTP Docs

Symptom

401/403/429 responses when accessing /documentation/openapi.json.

Cause

The openapi.routes.middleware stack includes authentication, authorization, or rate limiting middleware.

Mitigation

For public documentation:

How to Reproduce

How to Test

Remove middleware and verify access:

Invalid API Type Filters

Symptom

422 validation error when requesting HTTP documentation with invalid API type.

Cause

Requested API type is missing, disabled, or misspelled in openapi.api_types.

Mitigation

1

Verify available types

Check enabled API types:
2

Enable the API type

In config/openapi.php:
3

Add missing API type

If the type doesn’t exist:

How to Reproduce

How to Test

Add the API type to config and retry:

Template JSON Parsing Failures

Symptom

Generation fails with JSON template errors:

Cause

Invalid JSON syntax in resources/openapi/templates or missing required fields.

Mitigation

1

Validate template JSON

Use a JSON validator:
Or online: jsonlint.com
2

Enable output validation

In config/openapi-templates.php:
This adds extra validation but slows generation. Use only for debugging.
3

Check for common issues

  • Trailing commas: Not allowed in JSON
  • Unescaped quotes: Must escape " inside strings
  • Missing braces: Ensure all { have matching }

How to Reproduce

Create invalid JSON in a template:

How to Test

Fix JSON and regenerate:

General Troubleshooting

Cause: Routes don’t match API type prefixes or are excluded.Solution:
Cause: Template placeholders don’t match available variables.Solution:Available placeholders:
  • {{entity_singular}} - e.g., “user”
  • {{entity_plural}} - e.g., “users”
  • {{api_type}} - e.g., “admin”
Ensure template uses correct placeholder syntax.
Cause: Route doesn’t type-hint FormRequest in controller method.Solution:
Cause: Output directory not writable.Solution:

Next Steps

API Reference

Explore the programmatic API for custom integrations.

Configuration Reference

Detailed configuration options and defaults.