✨ feat: implement input validation for API v2
- Added go-playground/validator dependency - Created pkg/validation/ package with custom validator wrapper - Implemented request validation for v2 greet endpoint - Added structured validation error responses - Extended BDD tests to cover validation scenarios - Updated AGENTS.md with v2 API documentation - Created ADR 0011-validation-library-selection.md - Simplified server handler creation code - Updated CHANGELOG with implementation details
This commit is contained in:
44
AGENTS.md
44
AGENTS.md
@@ -388,6 +388,50 @@ curl http://localhost:8080/api/v1/greet/Alice
|
||||
# Response: {"message":"Hello Alice!"}
|
||||
```
|
||||
|
||||
### Greet Service v2 (Feature Flag Enabled)
|
||||
```http
|
||||
POST /api/v2/greet
|
||||
```
|
||||
|
||||
**Request Body:**
|
||||
```json
|
||||
{
|
||||
"name": "John"
|
||||
}
|
||||
```
|
||||
|
||||
**Examples:**
|
||||
```bash
|
||||
# Valid request
|
||||
curl -X POST http://localhost:8080/api/v2/greet \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name":"John"}'
|
||||
# Response: {"message":"Hello my friend John!"}
|
||||
|
||||
# Empty name (valid, returns default)
|
||||
curl -X POST http://localhost:8080/api/v2/greet \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name":""}'
|
||||
# Response: {"message":"Hello my friend!"}
|
||||
|
||||
# Missing name field (valid, returns default)
|
||||
curl -X POST http://localhost:8080/api/v2/greet \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}'
|
||||
# Response: {"message":"Hello my friend!"}
|
||||
|
||||
# Name too long (validation error)
|
||||
curl -X POST http://localhost:8080/api/v2/greet \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name":"ThisNameIsWayTooLongAndShouldFailValidationBecauseItExceedsTheMaximumAllowedLengthOf100Characters!!!!"}'
|
||||
# Response: {"error":"validation_failed","message":"Invalid request data","details":[{"message":"Name failed validation for 'max' (parameter: 100)"}]}'
|
||||
```
|
||||
|
||||
**Validation Rules:**
|
||||
- `name`: Maximum length 100 characters (optional field)
|
||||
|
||||
**Feature Flag:** Enable with `DLC_API_V2_ENABLED=true` or in config file with `api.v2_enabled: true`
|
||||
|
||||
## 🔗 OpenTelemetry & Jaeger Integration
|
||||
|
||||
The application supports OpenTelemetry for distributed tracing with Jaeger compatibility.
|
||||
|
||||
Reference in New Issue
Block a user