api-contract

Generates OpenAPI definitions, TypeScript types, and mock data for frontend-backend contract synchronization.

Updated Jul 31, 2026
One-click install
npx skills add https://github.com/shengmingzhishu/LeeCommonVideoCut --skill api-contract-shengmingzhishu
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: api-contract
Source: https://github.com/shengmingzhishu/LeeCommonVideoCut/tree/main/.trae/skills/shared/api-contract
Command: npx skills add https://github.com/shengmingzhishu/LeeCommonVideoCut --skill api-contract-shengmingzhishu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires openapi-typescript, faker.js, msw.

What problem does it solve? Frontend and backend teams often drift out of sync on API field names, types, and error codes, causing integration bugs discovered only during joint debugging. This Skill manages the full API contract lifecycle—definition, type synchronization, mock generation, and consistency validation—so both sides always work from the same OpenAPI source of truth. ## Core Features & Use Cases - OpenAPI Definition Generation: Extracts OpenAPI definitions from FastAPI routes and produces a structured openapi.yaml design document with complete parameters, request bodies, responses, and error codes. - Frontend Type Synchronization: Uses openapi-typescript to generate TypeScript types into src/types/api/, which the frontend Service layer references directly without manual edits. - Mock Data & Contract Validation: Generates faker.js-based mock data with MSW handler configurations, and validates contract consistency in CI on both backend (schema validator) and frontend (type freshness checks). - Use Case: After a backend developer modifies a FastAPI endpoint, run this Skill to regenerate the OpenAPI contract, then have the frontend pull updated TS types and MSW mocks so integration testing starts immediately against the new contract. ## Quick Start Generate the OpenAPI contract from the backend FastAPI routes and sync the frontend TypeScript types and MSW mock handlers.

Frequently Asked Questions about api-contract

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate TypeScript types from an OpenAPI schema?▼

Use openapi-typescript to convert an OpenAPI definition into TypeScript types. Run npx openapi-typescript http://localhost:8000/openapi.json -o src/types/api/generated.ts, then reference the generated types in your frontend Service layer without manual edits.

How to keep frontend and backend API contracts in sync?▼

Maintain a single OpenAPI definition as the source of truth, regenerate frontend TS types whenever the backend changes, and run CI checks on both sides. The backend validates its implementation against the schema while the frontend verifies generated types are current.

Can I generate mock data from an OpenAPI specification?▼

Yes, mock data can be generated directly from OpenAPI Schema definitions. Combined with faker.js for realistic values, the output can be exported as MSW handler configurations so frontend development proceeds without a running backend.

Does FastAPI support automatic OpenAPI generation?▼

FastAPI automatically exposes an OpenAPI JSON document at /openapi.json based on route definitions, type hints, and Pydantic models. This endpoint can be consumed by openapi-typescript to produce frontend types.

Why does contract validation fail in CI after backend changes?▼

Validation fails when the backend implementation diverges from the OpenAPI schema, such as renamed fields, changed response shapes, or missing error codes. Regenerate the contract file and update frontend types to restore consistency.