| name | api_contract_validation |
| description | Validates API implementations against OpenAPI/Swagger specs and ensures contract compliance. Invoke when implementing APIs, reviewing API changes, or validating integrations. |
SKILL: API Contract Validation
🎯 Objective
Ensure API implementations match their specifications exactly. Detect deviations in request/response formats, status codes, and error handling before deployment.
🧠 Core Principle: Specification Fidelity
The implementation must match the contract. Any undocumented behavior, missing fields, or incorrect status codes constitutes a contract violation.
📊 Severity Legend
FAIL — Implementation contradicts the spec (wrong status, missing field, type mismatch). Block.
WARN — Spec gap or ambiguity (undocumented-but-harmless behavior, missing example). Reconcile spec and code.
PASS — Endpoint verified against the spec.
N/A — Feature not used by this API (state why).
✅ Verification Discipline
Compare against the spec file as the source of truth, not against intuition about "normal" REST behavior. When implementation and spec disagree, do not silently pick one — report the conflict so the owner decides which to change. Validate the spec itself is well-formed before validating code against it.
🛠️ Execution Pipeline
1. SPECIFICATION_PARSING
Goal: Establish the contract as the source of truth.
How to verify: Lint the spec first (swagger-cli validate, spectral lint, or redocly lint). A malformed spec invalidates the whole comparison.
2. REQUEST_VALIDATION
Goal: Inputs are accepted/rejected exactly as documented.
3. RESPONSE_VALIDATION
Goal: Outputs match the schema with no leaks.
Example:
Spec: GET /users/{id} → 200 { id: integer, name: string }
❌ Implementation returns { id, name, passwordHash } → undocumented field leaks a secret.
✅ Implementation returns exactly { id, name }, types matching schema.
4. ERROR_RESPONSE_CHECK
Goal: Failures are documented and consistent.
Example:
❌ Returns 200 with { "error": "not found" } in the body — status lies about the outcome.
✅ Returns 404 with the documented error schema { code, message }.
5. AUTHENTICATION_FLOW
Goal: Security matches the declared schemes.
6. CONTENT_TYPE_VERIFICATION
Goal: Media types and negotiation behave as documented.
7. RATE_LIMITING_VERIFICATION
Goal: Throttling is enforced and observable.
8. PAGINATION_CONSISTENCY
Goal: Paging is correct at the edges.
9. VERSIONING_VERIFICATION
Goal: Version transitions stay compatible.
📤 Output Directives
Report format: [PASS/FAIL/WARN] METHOD /path: Contract violation with expected vs actual.
Example output:
[FAIL] GET /users/{id}: Response includes undocumented `passwordHash`. Remove from serializer.
[FAIL] POST /orders: Returns 200 on validation error; spec requires 400 with error schema.
[WARN] GET /products: Implements `?sort=` not present in spec. Add to spec or remove.
[PASS] DELETE /sessions/{id}: 204 on success, 401 unauthenticated — matches spec.