Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ npm test -- --watch
npm test -- --coverage
```

### API Contract Schema Snapshots (Issue #711)

Committed JSON snapshots under `schema-snapshots/` describe the response shape of critical public endpoints. CI fails when a required field is removed or changes type.

**Guarded endpoints:** `GET /health`, `GET /ready`, `GET /api/v1/vault/summary`, `GET /api/v1/transactions`

```bash
# Verify snapshots are backward-compatible (CI)
npm run snapshots:check

# Regenerate after an intentional breaking API change
npm run snapshots:write
```

When bumping snapshots intentionally:

1. Update the Zod schema in `src/apiContractSnapshots.ts`
2. Run `npm run snapshots:write` and commit `schema-snapshots/*.json`
3. Align OpenAPI annotations and run `npm run generate:openapi`

## Issues Addressed

### Issue #145: Rate Limiting
Expand Down
79 changes: 74 additions & 5 deletions backend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,28 @@
"count": {
"type": "integer"
},
"total": {
"limit": {
"type": "integer"
},
"total": {
"type": "integer",
"nullable": true
},
"nextCursor": {
"type": "string"
"type": "string",
"nullable": true
},
"prevCursor": {
"type": "string"
"type": "string",
"nullable": true
},
"currentPage": {
"type": "integer"
"type": "integer",
"nullable": true
},
"totalPages": {
"type": "integer"
"type": "integer",
"nullable": true
},
"hasNextPage": {
"type": "boolean"
Expand All @@ -58,6 +66,24 @@
}
}
},
"VaultSummary": {
"type": "object",
"properties": {
"totalAssets": {
"type": "number"
},
"totalShares": {
"type": "number"
},
"apy": {
"type": "number"
},
"timestamp": {
"type": "string",
"format": "date-time"
}
}
},
"Error": {
"type": "object",
"properties": {
Expand All @@ -74,6 +100,16 @@
},
"Transaction": {
"type": "object",
"required": [
"id",
"type",
"status",
"amount",
"asset",
"timestamp",
"transactionHash",
"walletAddress"
],
"properties": {
"id": {
"type": "string"
Expand All @@ -85,6 +121,14 @@
"withdrawal"
]
},
"status": {
"type": "string",
"enum": [
"pending",
"completed",
"failed"
]
},
"amount": {
"type": "string"
},
Expand Down Expand Up @@ -341,6 +385,10 @@
},
"pagination": {
"$ref": "#/components/schemas/PaginationMeta"
},
"timestamp": {
"type": "string",
"format": "date-time"
}
}
}
Expand Down Expand Up @@ -489,6 +537,27 @@
}
}
}
},
"/vault/summary": {
"get": {
"summary": "Vault summary",
"description": "Returns high-level vault metrics including total assets, shares, and APY.",
"tags": [
"Vault"
],
"responses": {
"200": {
"description": "Vault summary metrics",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VaultSummary"
}
}
}
}
}
}
}
},
"tags": []
Expand Down
25 changes: 12 additions & 13 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions backend/schema-snapshots/get-_api_v1_transactions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"deposit",
"withdrawal"
]
},
"status": {
"type": "string",
"enum": [
"pending",
"completed",
"failed"
]
},
"amount": {
"type": "string"
},
"asset": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"transactionHash": {
"type": "string"
},
"walletAddress": {
"type": "string"
}
},
"required": [
"id",
"type",
"status",
"amount",
"asset",
"timestamp",
"transactionHash",
"walletAddress"
],
"additionalProperties": false
}
},
"pagination": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"limit": {
"type": "number"
},
"total": {
"type": "number"
},
"nextCursor": {
"type": "string"
},
"prevCursor": {
"type": "string"
},
"currentPage": {
"type": "number"
},
"totalPages": {
"type": "number"
},
"hasNextPage": {
"type": "boolean"
},
"hasPrevPage": {
"type": "boolean"
}
},
"required": [
"count",
"limit",
"total",
"nextCursor",
"prevCursor",
"currentPage",
"totalPages",
"hasNextPage",
"hasPrevPage"
],
"additionalProperties": false
},
"timestamp": {
"type": "string"
}
},
"required": [
"data",
"pagination",
"timestamp"
],
"additionalProperties": false
}
24 changes: 24 additions & 0 deletions backend/schema-snapshots/get-_api_v1_vault_summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "object",
"properties": {
"totalAssets": {
"type": "number"
},
"totalShares": {
"type": "number"
},
"apy": {
"type": "number"
},
"timestamp": {
"type": "string"
}
},
"required": [
"totalAssets",
"totalShares",
"apy",
"timestamp"
],
"additionalProperties": false
}
9 changes: 9 additions & 0 deletions backend/scripts/check-schema-snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
/**
* Verify API contract schema snapshots remain backward-compatible (Issue #711).
*
* Snapshots guard high-traffic public endpoints (health, readiness, vault summary,
* and transaction list) against silent response-shape regressions.
*
* Usage:
* tsx scripts/check-schema-snapshots.ts # fail on breaking changes
* tsx scripts/check-schema-snapshots.ts --write # regenerate snapshot files
*
* Intentional breaking changes:
* 1. Update the Zod schema in src/apiContractSnapshots.ts
* 2. Run: npm run snapshots:write
* 3. Commit the updated files under schema-snapshots/
* 4. Align OpenAPI annotations and run: npm run generate:openapi
*/

import {
Expand Down
Loading
Loading