Known Issues
This document lists known issues and workarounds for Laravel Spectrum. These issues are planned to be fixed in future versions.
π¨ Critical Issuesβ
1. Anonymous FormRequest Class Analysisβ
Issue: Validation rules in FormRequests defined as anonymous classes may not be detected correctly.
// Pattern that may not be detected
Route::post('/users', function (Request $request) {
$validated = $request->validate(
(new class extends FormRequest {
public function rules() {
return ['name' => 'required'];
}
})->rules()
);
});
Workaround: Define FormRequest as a regular class.
// Recommended approach
class StoreUserRequest extends FormRequest
{
public function rules()
{
return ['name' => 'required'];
}
}
Route::post('/users', [UserController::class, 'store']);
Status: Planned fix in v2.0
2. Deeply Nested Array Validationβ
Issue: Nested array validation deeper than 3 levels is not fully parsed.
// Levels beyond the 3rd may only be partially detected
public function rules()
{
return [
'data' => 'required|array',
'data.*.items' => 'required|array',
'data.*.items.*.details' => 'required|array',
'data.*.items.*.details.*.value' => 'required|string', // May not be detected
];
}
Workaround: Increase the parsing depth in the configuration or flatten the structure.
// config/spectrum.php
'analysis' => [
'max_depth' => 5, // Default is 3
],
Status: Under investigation
β οΈ Limitationsβ
1. Dynamic Route Registrationβ
Issue: Routes dynamically registered at runtime are not detected.
// Patterns not detected
if (config('features.new_api')) {
Route::post('/new-endpoint', [NewController::class, 'store']);
}
// Dynamically generating routes from database
foreach (Module::active() as $module) {
Route::prefix($module->slug)->group($module->routes);
}
Workaround: Use static route definitions or create a custom analyzer.
// Custom analyzer example
class DynamicRouteAnalyzer implements Analyzer
{
public function analyze($target): array
{
// Logic to analyze dynamic routes
}
}
Status: Specification limitation
2. Custom Middleware Authentication Detectionβ
Issue: Authentication requirements for non-standard custom middleware are not automatically detected.
// Pattern not detected
Route::middleware('custom.auth:special')->group(function () {
Route::get('/protected', [Controller::class, 'index']);
});
Workaround: Configure middleware mapping.
// config/spectrum.php
'authentication' => [
'middleware_map' => [
'custom.auth' => 'bearer',
'custom.auth:special' => 'apiKey',
],
],
Status: Documented
π Bugsβ
1. Enum Type Array Validationβ
Issue: Enum constraints for individual values in array validation are not detected.
use App\Enums\StatusEnum;
public function rules()
{
return [
// Array validation is detected
'statuses' => ['required', 'array'],
// Enum constraint for individual elements is not detected
'statuses.*' => ['required', Rule::enum(StatusEnum::class)],
];
}
Workaround:
Use the in
rule together.
'statuses.*' => [
'required',
Rule::enum(StatusEnum::class),
Rule::in(StatusEnum::cases()), // Add this as well
],
Status: Planned fix in v1.3
2. Fractal Include Detectionβ
Issue:
Fractal's availableIncludes
are not correctly detected when conditional.
class UserTransformer extends TransformerAbstract
{
public function __construct(private bool $isAdmin)
{
$this->availableIncludes = $isAdmin
? ['posts', 'comments', 'privateData']
: ['posts', 'comments'];
}
}
Workaround: Define as a static property.
protected array $availableIncludes = ['posts', 'comments', 'privateData'];
public function includePrivateData(User $user)
{
if (!$this->isAdmin) {
return null;
}
return $this->item($user->privateData, new PrivateDataTransformer);
}
Status: Being fixed
π» Environment-Specific Issuesβ
1. File Watching on Windowsβ
Issue:
The spectrum:watch
command doesn't detect file changes on Windows.
Workaround: Use polling mode.
php artisan spectrum:watch --poll
Or enable in configuration:
// config/spectrum.php
'watch' => [
'polling' => [
'enabled' => true,
'interval' => 1000,
],
],
Status: Platform limitation
2. Performance in Docker Containersβ
Issue: Generation is slow when using volume mounts with Docker for Mac/Windows.
Workaround:
- Use caching aggressively
- Run generation inside the container
- Copy only results to host
# Dockerfile
RUN php artisan spectrum:generate && \
cp -r storage/app/spectrum /tmp/spectrum
# docker-compose.yml
volumes:
- ./storage/app/spectrum:/tmp/spectrum
Status: Docker limitation
π§ Performance Issuesβ
1. Memory Usage in Large Projectsβ
Issue: Memory exhaustion may occur in projects with over 1000 routes.
Workaround: Use the optimized command:
php artisan spectrum:generate:optimized --chunk-size=50
Status: Continuously improving
2. Circular Reference Detectionβ
Issue: Circular references between resources may cause stack overflow.
// Circular reference example
class UserResource extends JsonResource
{
public function toArray($request)
{
return [
'posts' => PostResource::collection($this->posts),
];
}
}
class PostResource extends JsonResource
{
public function toArray($request)
{
return [
'author' => new UserResource($this->author), // Circular reference
];
}
}
Workaround: Set maximum depth or use conditional loading:
'author' => $this->when(!$request->has('no_author'), function () {
return new UserResource($this->author);
}),
Status: Improvement planned for v1.4
π Minor Issuesβ
1. Custom Date Formatsβ
Issue:
Custom date formats are not recognized as date-time
format.
'created_at' => $this->created_at->format('YεΉ΄mζdζ₯'),
Workaround: Use ISO 8601 format or treat custom formats as strings.
2. Japanese Field Namesβ
Issue: Japanese field names may not be properly escaped in OpenAPI.
Workaround:
Use English field names and include Japanese in description
:
public function attributes()
{
return [
'name' => 'εε',
'email' => 'γ‘γΌγ«γ’γγ¬γΉ',
];
}
π Update Informationβ
Recently Fixed Issuesβ
- v1.2.0: Improved pagination metadata detection
- v1.1.5: Fixed service provider registration issue in Lumen
- v1.1.4: Fixed deprecation warnings in PHP 8.2
Planned Fixesβ
- v1.3.0: Full support for enum array validation
- v1.4.0: Automatic circular reference detection and handling
- v2.0.0: Full support for anonymous classes
π Reporting Issuesβ
When reporting a new issue, please include the following information:
-
Environment Information
php -v
php artisan --version
composer show wadakatu/laravel-spectrum -
Reproduction Steps
- Minimal reproduction code
- Expected behavior
- Actual behavior
-
Error Logs
tail -n 100 storage/logs/laravel.log
Report to: GitHub Issues
π Related Documentationβ
- Troubleshooting - Solving common problems
- FAQ - Frequently asked questions