Api contract validation

From CarlosDanielDev/maestro · View interactive version

Api contract validation is an AI agent skill from the GitHub repository CarlosDanielDev/maestro. API contract validation patterns for ensuring client-side models match backend JSON responses. Prevents decoding failures from schema mismatches. Tech-stack agnostic.

How to use this skill

Skill file

API Contract Validation Skill

Purpose

Prevent bugs where client-side models don't match backend API responses — causing silent decoding failures at runtime.

Contract Schema Location

All API contracts live in docs/api-contracts/ as JSON files.

Naming Convention

docs/api-contracts/{feature-area}-{endpoint-name}.json

Contract Schema Format

{
  "$schema": "api-contract-v1",
  "endpoint": "GET /api/items/list",
  "description": "Fetch items for display",
  "issue": "#38",
  "lastVerified": "2026-03-10",
  "request": {
    "query": {
      "count": { "type": "integer", "required": false, "default": 10 }
    }
  },
  "response": {
    "items": {
      "type": "array",
      "items": {
        "id": { "type": "string", "required": true },
        "name": { "type": "string", "required": true },
        "score": { "type": "integer", "required": false }
      }
    },
    "total": { "type": "integer", "required": true }
  }
}

DOR (Definition of Ready)

An issue is NOT ready for implementation unless:

DOD (Definition of Done)

Implementation is NOT done unless:

Common Mismatch Patterns

  1. Ghost fields: Client model has a field that doesn't exist in backend response
  2. Required mismatch: Backend returns field optionally, client declares it as required
  3. Type mismatch: Backend returns number (float) but client declares integer
  4. Naming mismatch: Backend uses snake_case, client uses camelCase without mapping
  5. Nested structure mismatch: Backend nests data differently than client expects

Validation Process

  1. Read contract schema from docs/api-contracts/
  2. Read the corresponding client model file
  3. For each field in schema: verify exists, type matches, optionality matches
  4. For each field in client model: verify exists in schema (catch ghost fields)
  5. Report mismatches

Integration with Orchestrator Workflow

subagent-architect → Architecture Blueprint
    │
    ▼
CONTRACT VALIDATION ← This skill
    │
    ▼
subagent-qa → Test Blueprint (includes decode tests)
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.