Phase 22 focused on Contract Testing with Pact and API Diff Tool for version comparison.
Concepto: Consumer-driven contract testing para validar que los mocks cumplen con contratos establecidos y detectar breaking changes automáticamente.
Files Created:
backend/src/contract-testing/contract-testing.module.tsbackend/src/contract-testing/contract-testing.service.tsbackend/src/contract-testing/contract-testing.controller.tsbackend/src/contract-testing/dto/upload-contract.dto.tsbackend/src/contract-testing/dto/validate-contract.dto.tsbackend/src/contract-testing/dto/verify-provider.dto.tsbackend/src/contract-testing/dto/generate-contract.dto.tsbackend/src/contract-testing/dto/index.ts
Key Features:
- Pact Contract Upload: Upload
.jsonPact contract files - Contract Validation: Validate API endpoints against contracts
- Provider Verification: Run Pact Verifier to validate provider compliance
- Contract Generation: Auto-generate Pact contracts from API endpoints
- Deep Object Comparison: Detect mismatches in request/response schemas
- Missing Endpoint Detection: Identify endpoints defined in contract but missing in API
- Response Validation: Compare expected vs actual response bodies
Validation Checks:
- Endpoint existence (method + path)
- Response status codes
- Response body structure
- Deep object comparison with difference reporting
API Endpoints:
POST /admin/contract-testing/upload- Upload Pact contract filePOST /admin/contract-testing/validate- Validate API against contractPOST /admin/contract-testing/verify-provider- Run Pact provider verificationPOST /admin/contract-testing/generate- Generate contract from APIGET /admin/contract-testing/contracts- List all contractsGET /admin/contract-testing/contracts/:contractId- Get contract details
Pact Support:
- Pact Specification v2.0.0+
- Consumer-Provider interactions
- Request/Response matching
- Provider states
- File-based contract storage in
pacts/directory
Concepto: Herramienta para comparar dos versiones de un API visualmente, destacando cambios (added, removed, modified) y detectando breaking changes automáticamente.
Files Created:
backend/src/api-diff/api-diff.module.tsbackend/src/api-diff/api-diff.service.tsbackend/src/api-diff/api-diff.controller.tsbackend/src/api-diff/dto/compare-versions.dto.ts
Key Features:
-
Version Comparison: Side-by-side comparison of two API versions
-
Change Detection:
- Added Endpoints: New endpoints in target version
- Removed Endpoints: Endpoints deleted from source version
- Modified Endpoints: Endpoints with changes in fields or responses
- Unchanged Endpoints: Count of endpoints without changes
-
Breaking Change Detection:
ENDPOINT_REMOVED- Endpoint was removed (critical)METHOD_CHANGED- HTTP method changed (critical)PATH_CHANGED- Endpoint path changed (critical)REQUIRED_PARAM_ADDED- New required parameter (critical)RESPONSE_STATUS_CHANGED- Response status code removed (major)RESPONSE_SCHEMA_BREAKING- Response schema incompatible (major)
-
Detailed Change Tracking:
- Field-level changes with old/new values
- Summary statistics
- Severity levels: critical, major, minor
API Endpoints:
GET /admin/api-diff/:apiId/versions- List available versionsPOST /admin/api-diff/:apiId/compare- Compare two versionsGET /admin/api-diff/:apiId/compare-with-latest- Quick compare with latest
Diff Result Structure:
{
fromVersion: string,
toVersion: string,
addedEndpoints: EndpointDiff[],
removedEndpoints: EndpointDiff[],
modifiedEndpoints: EndpointDiff[],
unchangedCount: number,
breakingChangesCount: number,
summary: {
totalChanges: number,
additions: number,
deletions: number,
modifications: number,
breakingChanges: number
}
}File Created: frontend/src/pages/ApiDiffPage.tsx
UI Features:
-
Version Selector: Dropdown menus for "from" and "to" versions
-
Auto-select Latest: Automatically selects latest version as target
-
Summary Dashboard: 5 metric cards showing:
- Total changes
- Additions (green)
- Deletions (red)
- Modifications (orange)
- Breaking changes (red/green)
-
Change Visualization:
- Added Endpoints: Green-themed cards with method + path
- Removed Endpoints: Red-themed cards with breaking change badges
- Modified Endpoints: Orange-themed cards with:
- Breaking changes section (if any)
- Field changes list
- Severity badges (CRITICAL, MAJOR, MINOR)
-
Severity Color Coding:
- Critical: Red (#d32f2f)
- Major: Orange (#f57c00)
- Minor: Yellow (#fbc02d)
-
Responsive Design: Grid layout adapting to screen size
Integration: Added route /apis/:apiId/diff to frontend/src/App.tsx
- Backend Files Created: 11
- Frontend Files Created: 1
- Total Files: 12
- Total Lines of Code: ~2,800
- New Modules: 2 (ContractTestingModule, ApiDiffModule)
- New Services: 2 (ContractTestingService, ApiDiffService)
- New Controllers: 2 (ContractTestingController, ApiDiffController)
- API Endpoints: 9 (6 contract testing + 3 API diff)
- Contract Testing: Ensures mocks comply with consumer expectations
- Automated Validation: Catch breaking changes before deployment
- Version Control: Track API evolution with detailed change history
- Visual Diff: Clear visualization of API changes
- Breaking Change Alerts: Immediate feedback on risky changes
- Contract Generation: Auto-generate contracts from existing endpoints
- Automated Contract Validation: Run in CI pipeline
- Version Comparison: Compare feature branches against main
- Breaking Change Gating: Block deployments with breaking changes
1. Generate Contract from API:
POST /admin/contract-testing/generate
{
"apiId": "api-123",
"consumerName": "frontend-app"
}2. Upload External Contract:
POST /admin/contract-testing/upload
Content-Type: multipart/form-data
- file: contract.json
- apiId: api-1233. Validate API Against Contract:
POST /admin/contract-testing/validate
{
"apiId": "api-123",
"contractId": "frontend-app-backend-api-1234567890"
}Response:
{
"valid": false,
"errors": [
"Missing endpoint: GET /api/users",
"POST /api/products: No response with status 201"
],
"warnings": [
"GET /api/orders: Response body mismatch"
],
"missingEndpoints": ["GET /api/users"],
"mismatchedResponses": [...]
}1. List Versions:
GET /admin/api-diff/:apiId/versionsResponse:
{
"apiId": "api-123",
"versions": [
{
"version": "v2.0.0",
"isLatest": true,
"createdAt": "2024-12-14T10:00:00Z",
"endpointCount": 25
},
{
"version": "v1.0.0",
"isLatest": false,
"createdAt": "2024-11-01T10:00:00Z",
"endpointCount": 20
}
]
}2. Compare Versions:
POST /admin/api-diff/:apiId/compare
{
"fromVersion": "v1.0.0",
"toVersion": "v2.0.0"
}Response:
{
"apiId": "api-123",
"diff": {
"fromVersion": "v1.0.0",
"toVersion": "v2.0.0",
"addedEndpoints": [...],
"removedEndpoints": [...],
"modifiedEndpoints": [...],
"summary": {
"totalChanges": 8,
"additions": 5,
"deletions": 1,
"modifications": 2,
"breakingChanges": 3
}
},
"hasBreakingChanges": true,
"message": "Found 3 breaking change(s)"
}# .github/workflows/contract-testing.yml
name: Contract Testing
on: [pull_request]
jobs:
validate-contracts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate API Contracts
run: |
# Upload contracts
CONTRACT_ID=$(curl -X POST \
${{ secrets.MOCK_API_URL }}/admin/contract-testing/upload \
-H "Authorization: Bearer ${{ secrets.API_TOKEN }}" \
-F "file=@contracts/consumer-contract.json" \
-F "apiId=${{ secrets.API_ID }}" \
| jq -r '.contractId')
# Run validation
curl -X POST \
${{ secrets.MOCK_API_URL }}/admin/contract-testing/validate \
-H "Authorization: Bearer ${{ secrets.API_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"apiId\":\"${{ secrets.API_ID }}\",\"contractId\":\"$CONTRACT_ID\"}" \
| jq -e '.valid'
check-breaking-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for Breaking Changes
run: |
# Compare with latest version
RESULT=$(curl -X POST \
${{ secrets.MOCK_API_URL }}/admin/api-diff/${{ secrets.API_ID }}/compare \
-H "Authorization: Bearer ${{ secrets.API_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"fromVersion\":\"${{ github.base_ref }}\",\"toVersion\":\"${{ github.head_ref }}\"}")
# Fail if breaking changes detected
echo "$RESULT" | jq -e '.hasBreakingChanges == false'- Consumer-First: Create contracts from consumer perspective
- Versioned Contracts: Maintain contracts per API version
- Automated Validation: Run in CI on every PR
- Provider States: Use provider states for complex scenarios
- Contract Evolution: Update contracts alongside API changes
- Pre-Release Checks: Compare before deploying new versions
- Documentation: Document breaking changes in release notes
- Deprecation Strategy: Mark endpoints as deprecated before removal
- Version Tagging: Use semantic versioning (MAJOR.MINOR.PATCH)
- Change Log: Auto-generate changelogs from diff results
- Pact Broker integration for centralized contract storage
- Consumer webhooks on contract validation failures
- Bi-directional contracts (consumer & provider)
- Contract testing for GraphQL and WebSocket
- Schema diff for request/response bodies (JSON Schema)
- Export diff as Markdown/PDF report
- Compare across different APIs (not just versions)
- Timeline view showing API evolution
- Rollback suggestions for breaking changes
- Contract Testing backend (service + controller + DTOs)
- Pact integration con
@pact-foundation/pact - Contract upload y storage
- Contract validation lógica
- Provider verification
- Contract generation desde endpoints
- API Diff backend (service + controller + DTO)
- Version comparison lógica
- Breaking change detection (6 tipos)
- Severity levels (critical, major, minor)
- API Diff frontend (página completa)
- Visual diff con color coding
- Summary dashboard
- Breaking change badges
- Integración en app.module.ts
- Ruta frontend para API Diff
- Documentación completa (este archivo)
Phase 22 Core Deliverables: 100% COMPLETE
Mock API Studio ahora incluye:
- ✅ 22 Phases implementadas (0-22)
- ✅ Contract Testing con Pact (consumer-driven)
- ✅ API Diff Tool con breaking change detection
- ✅ Quality assurance automation
- ✅ CI/CD integration ready
- ✅ Visual diff UI
Total Features: 110+ (counting all endpoints, UI pages, services, validations)
¡Mock API Studio - Phase 22 COMPLETE! 🚀