argument('controller'); if (! File::exists($path)) { // Try to find it in app/Http/Controllers $fullPath = app_path('Http/Controllers/'.ltrim($path, '/')); if (! File::exists($fullPath)) { $this->error("Controller not found at: {$path}"); return 1; } $path = $fullPath; } $content = File::get($path); $this->info('Analyzing controller: '.basename($path)); $prompt = "Generate PHP Swagger (L5-Swagger) annotations for the following Laravel controller. Focus on @OA\Get, @OA\Post, etc. with proper @OA\Response and @OA\Parameter. Guidelines: - Use modern OpenAPI 3.0 standards. - Include common responses like 200, 401, 403, and 500. - Identify request parameters from the code. - OUTPUT ONLY THE PHP CODE FOR THE ANNOTATIONS, no extra explanation. CONTROLLER CODE: {$content}"; $result = $this->aiService->provider()->generate($prompt); if (isset($result['success']) && $result['success']) { $annotations = $result['response']; $this->warn('AI Generated Annotations:'); $this->line($annotations); if ($this->confirm('Do you want to prepend these annotations to the file?')) { // Find where to insert (usually before the class declaration) $pattern = '/class\s+'.basename($path, '.php').'/'; if (preg_match($pattern, $content)) { $newContent = preg_replace($pattern, $annotations."\n".'$0', $content); File::put($path, $newContent); $this->success('Annotations added to '.basename($path)); } else { $this->error('Could not find class declaration to insert annotations.'); } } } else { $this->error('AI Error: '.($result['error'] ?? 'Unknown error')); } return 0; } }