mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 10:17:47 +08:00
Update validation_and_logging.md
This commit is contained in:
@@ -1,33 +1,40 @@
|
||||
# API Dash Validation Logging Implementation
|
||||
|
||||
## Overview
|
||||
|
||||
This implementation addresses GitHub issues #906 and #587 by migrating validation warnings and errors from transient UI notifications to the persistent in-app logging console.
|
||||
|
||||
## Changes Made
|
||||
|
||||
### 1. Enhanced `collection_providers.dart`
|
||||
|
||||
**File:** `lib/providers/collection_providers.dart`
|
||||
|
||||
**Added validation logic in the `sendRequest()` method:**
|
||||
|
||||
#### Validation Checks Implemented:
|
||||
|
||||
1. **Empty URL Validation**
|
||||
|
||||
- **Level:** Error
|
||||
- **Message:** "Request URL is empty. Please provide a valid URL."
|
||||
- **Tags:** `['request-validation', 'empty-url']`
|
||||
|
||||
2. **GET Request with Body Warning**
|
||||
|
||||
- **Level:** Warning
|
||||
- **Message:** "GET request contains a body. This may not be supported by all servers."
|
||||
- **Tags:** `['request-validation', 'get-with-body']`
|
||||
- **Trigger:** When HTTP method is GET and request body is not empty
|
||||
|
||||
3. **JSON Validation**
|
||||
|
||||
- **Valid JSON (Debug):**
|
||||
|
||||
- **Level:** Debug
|
||||
- **Message:** "Request body contains valid JSON."
|
||||
- **Tags:** `['request-validation', 'valid-json']`
|
||||
|
||||
|
||||
- **Invalid JSON (Error):**
|
||||
- **Level:** Error
|
||||
- **Message:** "Invalid JSON in request body: [error details]"
|
||||
@@ -40,19 +47,25 @@ This implementation addresses GitHub issues #906 and #587 by migrating validatio
|
||||
- **Tags:** `['request-validation', 'completed']`
|
||||
|
||||
### 2. Added Import
|
||||
|
||||
**Added:** `import 'package:better_networking/better_networking.dart';`
|
||||
|
||||
- Required for accessing `HTTPVerb`, `ContentType`, and `kJsonDecoder` constants
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### Code Location
|
||||
|
||||
The validation logic is inserted in the `sendRequest()` method right after the HTTP request model is prepared but before the actual network request is sent. This ensures:
|
||||
|
||||
- All request parameters are finalized
|
||||
- Validation happens for every request
|
||||
- Logs appear in the terminal before network activity
|
||||
|
||||
### Terminal Integration
|
||||
|
||||
Uses the existing terminal logging system:
|
||||
|
||||
```dart
|
||||
final terminal = ref.read(terminalStateProvider.notifier);
|
||||
terminal.logSystem(
|
||||
@@ -66,34 +79,43 @@ terminal.logSystem(
|
||||
## Testing Scenarios
|
||||
|
||||
### Test Case 1: GET Request with Body
|
||||
|
||||
**Setup:**
|
||||
|
||||
- Method: GET
|
||||
- URL: https://api.example.com/data
|
||||
- Body: `{"key": "value"}`
|
||||
|
||||
**Expected Result:**
|
||||
|
||||
- ⚠️ Warning log appears in terminal console
|
||||
- Message: "GET request contains a body. This may not be supported by all servers."
|
||||
|
||||
### Test Case 2: POST Request with Invalid JSON
|
||||
|
||||
**Setup:**
|
||||
|
||||
- Method: POST
|
||||
- URL: https://api.example.com/data
|
||||
- Content-Type: application/json
|
||||
- Body: `{"key": "value", "invalid": }` (missing value)
|
||||
|
||||
**Expected Result:**
|
||||
|
||||
- ❌ Error log appears in terminal console
|
||||
- Message: "Invalid JSON in request body: [FormatException details]"
|
||||
|
||||
### Test Case 3: Valid POST Request
|
||||
|
||||
**Setup:**
|
||||
|
||||
- Method: POST
|
||||
- URL: https://api.example.com/data
|
||||
- Content-Type: application/json
|
||||
- Body: `{"key": "value", "number": 123}`
|
||||
|
||||
**Expected Result:**
|
||||
|
||||
- ✅ Debug log: "Request body contains valid JSON."
|
||||
- ℹ️ Info log: "Request validation completed for POST https://api.example.com/data"
|
||||
|
||||
@@ -108,12 +130,14 @@ terminal.logSystem(
|
||||
## Migration Status
|
||||
|
||||
✅ **Completed:**
|
||||
|
||||
- GET request with body validation
|
||||
- JSON validation for request bodies
|
||||
- Empty URL validation
|
||||
- Integration with existing terminal logging system
|
||||
|
||||
✅ **Verified:**
|
||||
|
||||
- No compilation errors
|
||||
- Proper import statements
|
||||
- Consistent logging format
|
||||
@@ -122,29 +146,9 @@ terminal.logSystem(
|
||||
## Future Enhancements
|
||||
|
||||
Potential additional validations that could be added:
|
||||
|
||||
- URL format validation
|
||||
- Header validation
|
||||
- Authentication parameter validation
|
||||
- Request size limits
|
||||
- Content-Type mismatch warnings
|
||||
|
||||
## Files Modified
|
||||
|
||||
1. `lib/providers/collection_providers.dart` - Added validation logic
|
||||
2. `test_validation_logging.dart` - Demo/test file (can be removed)
|
||||
3. `VALIDATION_LOGGING_IMPLEMENTATION.md` - This documentation
|
||||
|
||||
## Commit Message
|
||||
```
|
||||
fix(logging): redirect request validation warnings & errors to in-app console (#906, #587)
|
||||
|
||||
- Add GET-with-body validation warning to terminal console
|
||||
- Add JSON validation error logging for invalid request bodies
|
||||
- Add empty URL validation error logging
|
||||
- Add request validation completion info logging
|
||||
- Replace transient UI notifications with persistent terminal logs
|
||||
- Maintain consistent logging format with categories and tags
|
||||
|
||||
Resolves #906: Migrate to in-app logging console
|
||||
Resolves #587: Add a Global status bar in API Dash
|
||||
```
|
||||
Reference in New Issue
Block a user