Advise me how can I rebuild these tasks for CrewAI to analyze controller and dependencies for generating swagger documentation:
src/your_project/config/tasks.yaml
analyze_controller:
description: >
Analyze the provided Laravel controller in {project_base_path}/{controller_path} file. Extract all relevant information
including routes, methods, parameters, return types, and relationships with other components. Pay special attention
to any existing PHPDoc comments and how different parts of the codebase interact to form the API structure.
expected_output: >
A detailed analysis of the controller and related code structures, including a list of all public
methods, their parameters, return types, relationships with other components, and any existing documentation.
analyze_other_dependencies:
description: >
Perform a thorough analysis of the Laravel project's ecosystem:
- Examine Controllers in {project_base_path}/{controller_path}
- Identify all project dependencies (models, services, requests, etc.) from use statements
- Compile a list of dependency paths based on use statements
- Conduct in-depth analysis of all identified dependencies
expected_output: >
A detailed analysis of all other dependencies in the project, including a list of all public methods,
their parameters, data relationships, and any existing documentation.
generate_swagger_docs:
description: >
Using the detailed analysis provided by the code analyzer, generate comprehensive Swagger documentation.
Ensure all endpoints, parameters, response structures, and data relationships are accurately represented.
expected_output: >
A complete Swagger/OpenAPI specification file (yaml or json) that fully documents the API structure
extracted from the analyzed code.
Assistant
Rebuilding Tasks for CrewAI to Analyze Controller and Dependencies for Generating Swagger Documentation
To rebuild the tasks for CrewAI to analyze controller and dependencies for generating Swagger documentation, you can follow these steps:
Task 1: Analyze Controller
Task Definition
analyze_controller task will analyze the provided Laravel controller in {project_base_path}/{controller_path} file. It will extract all relevant information including routes, methods, parameters, return types, and relationships with other components.
Task Steps
Read Controller File: Read the contents of the controller file located at {project_base_path}/{controller_path}.
Extract Public Methods: Extract all public methods from the controller file.
Analyze Method Parameters: Analyze each public method's parameters and extract their names, types, and default values.
Extract Return Types: Extract the return types of each public method.
Identify Relationships: Identify relationships between the controller and other components (e.g., models, services, requests).
Extract Existing Documentation: Extract any existing PHPDoc comments from the controller file.
Task Output
The task will output a detailed analysis of the controller and related code structures, including:
A list of all public methods
Method parameters (names, types, default values)
Return types
Relationships with other components
Existing documentation (PHPDoc comments)
Task 2: Analyze Other Dependencies
Task Definition
analyze_other_dependencies task will perform a thorough analysis of the Laravel project's ecosystem.
Task Steps
Examine Controllers: Examine all controllers in {project_base_path}/{controller_path}.
Identify Dependencies: Identify all project dependencies (models, services, requests, etc.) from use statements.
Compile Dependency Paths: Compile a list of dependency paths based on use statements.
Analyze Dependencies: Conduct an in-depth analysis of all identified dependencies.
Extract Public Methods: Extract all public methods from each dependency.
Analyze Method Parameters: Analyze each public method's parameters and extract their names, types, and default values.
Extract Return Types: Extract the return types of each public method.
Identify Relationships: Identify relationships between dependencies and other components.
Task Output
The task will output a detailed analysis of all other dependencies in the project, including:
A list of all public methods
Method parameters (names, types, default values)
Return types
Data relationships
Existing documentation
Task 3: Generate Swagger Documentation
Task Definition
generate_swagger_docs task will generate comprehensive Swagger documentation using the detailed analysis provided by the code analyzer.
Task Steps
Use Analysis Results: Use the results from analyze_controller and analyze_other_dependencies tasks.
Create Swagger Specification: Create a Swagger/OpenAPI specification file (yaml or json).
Define Endpoints: Define all endpoints, including paths, methods, and parameters.
Define Response Structures: Define response structures, including data types and relationships.
Define Data Relationships: Define data relationships between endpoints and components.
Add Existing Documentation: Add any existing documentation (PHPDoc comments) to the Swagger specification.
Task Output
The task will output a complete Swagger/OpenAPI specification file (yaml or json) that fully documents the API structure extracted from the analyzed code.
Example Code (Python)
python
import os
import re
from typing import Dict, List
def analyze_controller(controller_path: str) -> Dict:
# Read controller file
with open(controller_path, 'r') as f:
controller_code = f.read()
# Extract public methods
public_methods = re.findall(r'public function (\w+)\(', controller_code)
# Analyze method parameters and return types
method_params = {}
return_types = {}
for method in public_methods:
method_code = re.search(r'public function {}\(.*\)'.format(method), controller_code)
params = re.findall(r'\$([\w]+)', method_code.group(0))
method_params[method] = params
return_type = re.search(r'return (\w+);', method_code.group(0))
if return_type:
return_types[method] = return_type.group(1)
# Identify relationships and extract existing documentation
relationships = []
existing_docs = []
# ...
return {
'public_methods': public_methods,
'method_params': method_params,
'return_types': return_types,
'relationships': relationships,
'existing_docs': existing_docs
}
def analyze_other_dependencies(project_path: str) -> Dict:
# Examine controllers and identify dependencies
dependencies = {}
for file in os.listdir(project_path):
if file.endswith('.php'):
# Analyze file and extract dependencies
dependencies[file] = []
# ...
# Compile dependency paths and analyze dependencies
dependency_paths = {}
for dependency in dependencies:
# Compile dependency path and analyze dependency
dependency_paths[dependency] = []
# ...
return {
'dependencies': dependencies,
'dependency_paths': dependency_paths
}
def generate_swagger_docs(analysis_results: Dict) -> str:
# Create Swagger specification file
swagger_spec = {
'openapi': '3.0.0',
'info': {
'title': 'API Documentation',
'version': '1.0.0'
},
'paths': {}
}
# Define endpoints and response structures
for endpoint in analysis_results['endpoints']:
swagger_spec['paths'][endpoint['path']] = {
'methods': endpoint['methods']
}
# Define data relationships and add existing documentation
swagger_spec['components'] = {
'schemas': {}
}
for relationship in analysis_results['relationships']:
swagger_spec['components']['schemas'][relationship['name']] = {
'type': relationship['type']
}
return yaml.dump(swagger_spec, default_flow_style=False)
Note: This is a simplified example and may require modifications to work with your specific use case.
“Advise me how can I rebuild these tasks for CrewAI to analyze controller and….” Conversation with llama-3.1-70b-instruct, from the LMArena Human Preference 100K dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m8512knkaemjhwf82qnbqj4r