API Contract & OpenAPI Testing
This page documents the RitoSwap-specific contract test suite in:
app/api/__contract__/contract.test.tsIt is focused on the four public, token-gate–related endpoints actually used in this repo:
GET /api/noncePOST /api/gate-accessGET /api/token-status/{tokenId}POST /api/form-submission-gate
All tests validate against the project’s OpenAPI spec:
public/openapi.json💡
These tests are not generic examples. They encode the exact response shapes, status codes, and error formats that RitoSwap promises at its token-gate surface area.
What these tests cover
What these tests cover
The contract suite models RitoSwap’s public contract at the HTTP layer.
- contract.test.ts
- openapi.json
At a high level, contract.test.ts defines:
- Types dedicated to this file:
HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'ContractTestCasewithname,status, andresponseshapeContractTestgrouping apath,method, andtestCases[]
- A
CONTRACT_TESTSarray with hand-authored examples for each RitoSwap endpoint. - A
coerceMessageEnumIfPresent()helper tuned to the/api/form-submission-gatesuccess schema. - A
describe('API Contract Tests')block that:- Hydrates
OpenAPITestValidatorviagetOpenAPIValidator()from@/e2e/supertest/openapi-validator. - Iterates the RitoSwap endpoints only and calls
validator.validateResponse(...). - Runs two meta-tests to track coverage across all paths and response codes in
openapi.json.
- Hydrates
No route handlers are imported. This file is purely about matching RitoSwap’s documented contract.
Summary
- This suite is tailored specifically to RitoSwap’s token-gate endpoints, not a generic example.
- It encodes the exact success and error shapes for:
/api/nonce/api/gate-access/api/token-status/{tokenId}/api/form-submission-gate
- It uses the same OpenAPI validator as your supertest E2E flow, but runs entirely in Vitest.
- Meta-tests and
generateContractCoverage()give you a quick read on whether docs and contract tests are still aligned with the public surface area of the project.