mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
Feat: API Documentation & process general queries
This commit is contained in:
66
lib/dashbot/features/documentation.dart
Normal file
66
lib/dashbot/features/documentation.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'dart:convert';
|
||||
import '../services/dashbot_service.dart';
|
||||
import 'package:apidash/models/request_model.dart';
|
||||
|
||||
class DocumentationFeature {
|
||||
final DashBotService _service;
|
||||
|
||||
DocumentationFeature(this._service);
|
||||
|
||||
Future<String> generateApiDocumentation({
|
||||
required RequestModel? requestModel,
|
||||
required dynamic responseModel,
|
||||
}) async {
|
||||
if (requestModel == null || responseModel == null) {
|
||||
return "No recent API requests found.";
|
||||
}
|
||||
|
||||
final method = requestModel.httpRequestModel?.method
|
||||
.toString()
|
||||
.split('.')
|
||||
.last
|
||||
.toUpperCase() ??
|
||||
"GET";
|
||||
final endpoint = requestModel.httpRequestModel?.url ?? "Unknown Endpoint";
|
||||
final headers = requestModel.httpRequestModel?.enabledHeadersMap ?? {};
|
||||
final parameters = requestModel.httpRequestModel?.enabledParamsMap ?? {};
|
||||
final body = requestModel.httpRequestModel?.body;
|
||||
final rawResponse = responseModel.body;
|
||||
final responseBody =
|
||||
rawResponse is String ? rawResponse : jsonEncode(rawResponse);
|
||||
final statusCode = responseModel.statusCode ?? 0;
|
||||
|
||||
final prompt = """
|
||||
API DOCUMENTATION GENERATION
|
||||
|
||||
**API Details:**
|
||||
- Endpoint: $endpoint
|
||||
- Method: $method
|
||||
- Status Code: $statusCode
|
||||
|
||||
**Request Components:**
|
||||
- Headers: ${headers.isNotEmpty ? jsonEncode(headers) : "None"}
|
||||
- Query Parameters: ${parameters.isNotEmpty ? jsonEncode(parameters) : "None"}
|
||||
- Request Body: ${body != null && body.isNotEmpty ? body : "None"}
|
||||
|
||||
**Response Example:**
|
||||
```
|
||||
$responseBody
|
||||
```
|
||||
|
||||
**Documentation Instructions:**
|
||||
Create comprehensive API documentation that includes:
|
||||
|
||||
1. **Overview**: A clear, concise description of what this API endpoint does
|
||||
2. **Authentication**: Required authentication method based on headers
|
||||
3. **Request Details**: All required and optional parameters with descriptions
|
||||
4. **Response Structure**: Breakdown of response fields and their meanings
|
||||
5. **Error Handling**: Possible error codes and troubleshooting
|
||||
6. **Example Usage**: A complete code example showing how to call this API
|
||||
|
||||
Format in clean markdown with proper sections and code blocks where appropriate.
|
||||
""";
|
||||
|
||||
return _service.generateResponse(prompt);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user