api-contract-validator

Validates type contracts between TypeScript interfaces and Pydantic models. Detects field mismatches and type inconsistencies. Related: frontend-backend-mapper for endpoint discovery.

16 stars

Best use case

api-contract-validator is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Validates type contracts between TypeScript interfaces and Pydantic models. Detects field mismatches and type inconsistencies. Related: frontend-backend-mapper for endpoint discovery.

Teams using api-contract-validator should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/api-contract-validator/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/backend/api-contract-validator/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/api-contract-validator/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How api-contract-validator Compares

Feature / Agentapi-contract-validatorStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Validates type contracts between TypeScript interfaces and Pydantic models. Detects field mismatches and type inconsistencies. Related: frontend-backend-mapper for endpoint discovery.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# API Contract Validator Workflow

This skill ensures type safety and consistency between frontend TypeScript interfaces and backend Pydantic models.

## Workflow Steps

1. **Scan TypeScript interfaces:**
   - Read frontend API service files (`frontend/src/api/*.ts`)
   - Extract TypeScript interfaces for requests/responses
   - Parse field types, optional fields, arrays, enums
   - Build TypeScript type inventory

2. **Scan Pydantic models:**
   - Read backend model files (`backend/app/models/*_schemas.py`)
   - Extract Pydantic BaseModel definitions
   - Parse field types, Optional types, Lists, Enums
   - Build Python type inventory

3. **Match and compare contracts:**
   - Match TypeScript interfaces to Pydantic models by name
   - Compare field names (check for camelCase vs snake_case)
   - Compare field types (string vs str, number vs int/float)
   - Check required vs optional field consistency
   - Validate enum values match

4. **Detect mismatches:**
   - **Field name differences**: `userId` vs `user_id`
   - **Type mismatches**: `string` vs `int`
   - **Missing fields**: Field in frontend but not backend (or vice versa)
   - **Optional inconsistencies**: Required in one but optional in another
   - **Enum value differences**: Different allowed values

5. **Generate validation report:**
   - Create `docs/API_CONTRACT_VALIDATION.md` with:
     - Contract health score
     - List of all validated contracts
     - Detailed mismatch reports
     - Recommended fixes (with code examples)
     - Breaking vs non-breaking changes

6. **Provide fix suggestions:**
   - Show exact code changes needed
   - Generate conversion utilities if needed
   - Suggest API versioning for breaking changes

## Validation Report Structure

````markdown
# API Contract Validation Report

Generated: 2025-01-06T12:00:00Z

## Summary

- Total Contracts Validated: 28
- ✅ Matching Contracts: 22 (78.6%)
- ⚠️ Mismatches Found: 6 (21.4%)
- 🔴 Breaking Issues: 2
- 🟡 Non-Breaking Issues: 4

## Contract Health Score: 79/100

### ✅ VALID CONTRACTS (22)

| Contract Name     | Frontend          | Backend             | Status           |
| ----------------- | ----------------- | ------------------- | ---------------- |
| `ATSScoreRequest` | aiServices.ts     | analysis_schemas.py | ✅ Perfect match |
| `UserProfile`     | profileService.ts | schemas.py          | ✅ Perfect match |
| ...               |

### 🔴 BREAKING MISMATCHES (2)

#### 1. NotificationPreferences

**Location:** `notificationService.ts` ↔ `notification_schemas.py`

**Issues:**

- Field type mismatch: `frequency` is `string` in TS but `int` in Python
- Missing required field: `user_id` required in backend but not sent from frontend

**Impact:** 🔴 API calls will fail with 422 validation errors

**Fix (Frontend):**

```typescript
// notificationService.ts
interface NotificationPreferences {
  frequency: number; // Change from string to number
  user_id: string; // Add missing field
  // ... other fields
}
```
````

**Fix (Backend - Alternative):**

```python
# notification_schemas.py
class NotificationPreferencesRequest(BaseModel):
    frequency: str  # Change from int to str
    # Remove user_id from request, get from auth instead
```

### 🟡 NON-BREAKING WARNINGS (4)

#### 1. Casing Inconsistency

**Issue:** Frontend uses camelCase, backend uses snake_case
**Affected:** 15 contracts
**Impact:** 🟡 Works but inconsistent (Pydantic auto-converts)
**Recommendation:** Standardize on one casing style

**Example:**

```typescript
// Frontend (camelCase)
interface JobListing {
  jobTitle: string;
  companyName: string;
}

// Backend (snake_case)
class JobListingResponse(BaseModel):
    job_title: str
    company_name: str
```

**Recommendation:** Add Pydantic alias config:

```python
class JobListingResponse(BaseModel):
    job_title: str = Field(alias="jobTitle")
    company_name: str = Field(alias="companyName")

    class Config:
        populate_by_name = True
```

## Type Mapping Reference

| TypeScript  | Python (Pydantic) | Compatible             |
| ----------- | ----------------- | ---------------------- |
| `string`    | `str`             | ✅                     |
| `number`    | `int`, `float`    | ✅                     |
| `boolean`   | `bool`            | ✅                     |
| `string[]`  | `List[str]`       | ✅                     |
| `Date`      | `datetime`        | ⚠️ Needs serialization |
| `any`       | `Any`             | ⚠️ Avoid if possible   |
| `T \| null` | `Optional[T]`     | ✅                     |

```

## Usage Tips

- Run validator before major releases
- Integrate into CI/CD pipeline
- Fix breaking issues immediately
- Schedule non-breaking fixes for next sprint
- Use validator output for API documentation
```

Related Skills

doc-ctr-validator

16
from diegosouzapw/awesome-omni-skill

Validate Data Contracts (CTR) documents against Layer 8 schema standards

contract-review-pro

16
from diegosouzapw/awesome-omni-skill

专业合同审核 Skill,基于《合同审核方法论体系》提供合同类型指引和详细审核服务

conductor-validator

16
from diegosouzapw/awesome-omni-skill

Validates Conductor project artifacts for completeness, consistency, and correctness. Use after setup, when diagnosing issues, or before implementation to verify project context.

add-bc-contract

16
from diegosouzapw/awesome-omni-skill

Add Contract for inter-BC communication using Provider pattern. Use when one Bounded Context needs to access data from another BC (e.g., Inventory needs Articles from Admin). Creates Contract interface, Provider implementation, and configuration.

u01874-handoff-contracting-for-marketing-and-storytelling

16
from diegosouzapw/awesome-omni-skill

Operate the "Handoff Contracting for marketing and storytelling" capability in production for marketing and storytelling workflows. Use when mission execution explicitly requires this capability and outcomes must be reproducible, policy-gated, and handoff-ready.

Smart Contracts

16
from diegosouzapw/awesome-omni-skill

Smart contracts are self-executing programs on blockchain. This guide covers Solidity basics, contract deployment, interaction, and frontend integration for building decentralized applications with au

Data Contracts

16
from diegosouzapw/awesome-omni-skill

A Data Contract is a formal agreement between a data producer (e.g., a microservice) and a data consumer (e.g., a data platform) that defines the structure, semantics, and quality of data being shared

Contract Testing Pact

16
from diegosouzapw/awesome-omni-skill

Contract testing validates that service consumers and providers agree on request/response expectations. Pact implements consumer-driven contracts (CDC) with shareable pact files and provider verificat

api-validator

16
from diegosouzapw/awesome-omni-skill

Validate REST API standards compliance (versioning, naming, HTTP methods, status codes, pagination, Swagger). Use when checking endpoints before deployment, reviewing API design, or ensuring documentation completeness (e.g., "Validate User API", "Check Product endpoints").

API Contracts Generator

16
from diegosouzapw/awesome-omni-skill

Génère des contrats API cohérents entre Frontend (Next.js) et Backend (NestJS) avec types synchronisés, validation standardisée et error handling uniforme. À utiliser lors de la création d'APIs, DTOs, types frontend/backend, ou quand l'utilisateur mentionne "API", "DTO", "types", "contract", "validation", "frontend-backend", "synchronisation".

api-contracts-and-zod-validation

16
from diegosouzapw/awesome-omni-skill

Generate Zod schemas and TypeScript types for forms, API routes, and Server Actions with runtime validation. Use this skill when creating API contracts, validating request/response payloads, generating form schemas, adding input validation to Server Actions or route handlers, or ensuring type safety across client-server boundaries. Trigger terms include zod, schema, validation, API contract, form validation, type inference, runtime validation, parse, safeParse, input validation, request validation, Server Action validation.

api-contracts-and-validation

16
from diegosouzapw/awesome-omni-skill

Define and validate API contracts using Zod