Overview & Background
The FlowFi Express backend uses OpenAPI 3.1 Swagger specifications to document REST endpoints. However, without automated runtime enforcement, manual route controllers can accept invalid query parameters, accept unexpected body formats, or return payloads that diverge from the documented schema.
Detailed Problem Statement
- Manual validation logic is duplicated across controllers.
- Undocumented query parameters and edge-case type coercions bypass validation.
Technical Specification & Architecture
- Middleware Integration:
- Implement an OpenAPI validation middleware in
backend/src/middleware/schema-validator.middleware.ts.
- Bind request path, query, and body validation directly to Zod schemas matching the OpenAPI specification.
- Strict Error Formatting:
- Standardize all 400 Bad Request responses to RFC 7807 Problem Details:
{
"type": "https://flowfi.org/errors/invalid-parameters",
"title": "Invalid Request Parameters",
"status": 400,
"detail": "Invalid parameter 'duration': must be greater than 0",
"invalidParams": [{ "name": "duration", "reason": "Expected positive integer" }]
}
- Response Validation in Test Environment:
- In test suite, validate all controller responses against the OpenAPI schema to guarantee zero contract drift.
Target Files
backend/src/middleware/schema-validator.middleware.ts
backend/src/app.ts
backend/tests/unit/validation.test.ts
Acceptance Criteria
Overview & Background
The FlowFi Express backend uses OpenAPI 3.1 Swagger specifications to document REST endpoints. However, without automated runtime enforcement, manual route controllers can accept invalid query parameters, accept unexpected body formats, or return payloads that diverge from the documented schema.
Detailed Problem Statement
Technical Specification & Architecture
backend/src/middleware/schema-validator.middleware.ts.{ "type": "https://flowfi.org/errors/invalid-parameters", "title": "Invalid Request Parameters", "status": 400, "detail": "Invalid parameter 'duration': must be greater than 0", "invalidParams": [{ "name": "duration", "reason": "Expected positive integer" }] }Target Files
backend/src/middleware/schema-validator.middleware.tsbackend/src/app.tsbackend/tests/unit/validation.test.tsAcceptance Criteria