Config Caching with Runtime env() Usage
Symptom
Changing.env values (e.g., APP_NAME, APP_URL) does not affect generated documentation output.
Cause
Laravel’sconfig: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()- ReadsAPP_NAMEviaenv()EnvironmentGenerator::buildBaseEnvironmentData()- ReadsAPP_URLviaenv()
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
Concurrent Generation Writes to Same Output File
Symptom
Partially written or inconsistent JSON/YAML files instorage/app/public/openapi. Files may contain truncated JSON or mixed content from multiple generations.
Cause
Multiple workers, developers, or CI jobs runningopenapi:generate simultaneously write to the same output filenames, causing race conditions.
Mitigation
- Unique Output Paths
- File Locking
- Single Queue Worker
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 whenopenapi.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
Mitigation
- Generate via CLI
- Increase Timeout
- Filter Routes
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: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
Theopenapi.routes.middleware stack includes authentication, authorization, or rate limiting middleware.
Mitigation
- Remove Middleware
- Custom Middleware Stack
- Static File Serving
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 inopenapi.api_types.
Mitigation
1
Verify available 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 inresources/openapi/templates or missing required fields.
Mitigation
1
Validate template JSON
2
Enable output validation
In This adds extra validation but slows generation. Use only for debugging.
config/openapi-templates.php: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
No routes found matching filters
No routes found matching filters
Cause: Routes don’t match API type prefixes or are excluded.Solution:
Placeholders not replaced in output
Placeholders not replaced in output
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”
FormRequest validation rules not appearing
FormRequest validation rules not appearing
Cause: Route doesn’t type-hint FormRequest in controller method.Solution:
Permission denied writing output files
Permission denied writing output files
Cause: Output directory not writable.Solution:
Next Steps
API Reference
Explore the programmatic API for custom integrations.
Configuration Reference
Detailed configuration options and defaults.