This skill validates OpenAPI, Swagger, and GraphQL specs against implementations, detects breaking changes, and generates TypeScript clients to keep APIs
npx playbooks add skill ananddtyagi/cc-marketplace --skill api-contract-sync
Maintain synchronization between API specifications and their implementations, detect breaking changes, and generate client code to ensure contracts stay reliable across frontend and backend teams.
Use this skill when:
.yaml, .json).graphql, .gql)Validate API specification files for correctness and completeness:
OpenAPI/Swagger Validation:
GraphQL Validation:
Validation Approach:
$ref)Cross-reference API specifications with actual code implementations:
For REST APIs:
app.get(), router.post(), etc.@app.get(), @router.post()path(), urlpatterns@GetMapping, @PostMappingFor GraphQL:
Implementation Matching Steps:
1. Parse spec → extract endpoints/operations
2. Use Grep to find route handlers in codebase
3. Compare and categorize:
- ✓ Matched: spec and implementation align
- ⚠ Drift: partial match with differences
- ✗ Missing: documented but not implemented
- ⚠ Undocumented: implemented but not in spec
4. Generate coverage report
Compare two versions of an API spec to detect breaking vs. non-breaking changes:
Breaking Changes (require version bump):
Non-Breaking Changes (safe to deploy):
Change Detection Process:
Generate type-safe client code from API specifications:
TypeScript Interfaces:
// From OpenAPI schema
interface User {
id: string;
email: string;
name?: string;
createdAt: Date;
}
interface CreateUserRequest {
email: string;
name?: string;
}
interface CreateUserResponse {
user: User;
token: string;
}
API Client Functions:
// HTTP client with proper typing
async function createUser(
data: CreateUserRequest
): Promise<CreateUserResponse> {
const response = await fetch('/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
return response.json();
}
React Query Hooks:
// Auto-generated hooks for data fetching
function useUser(userId: string) {
return useQuery(['user', userId], () =>
fetch(`/api/users/${userId}`).then(r => r.json())
);
}
function useCreateUser() {
return useMutation((data: CreateUserRequest) =>
fetch('/api/users', {
method: 'POST',
body: JSON.stringify(data)
}).then(r => r.json())
);
}
Generation Steps:
Identify gaps between documentation and implementation:
Analysis Report Structure:
API Coverage Report
==================
Documented Endpoints: 45
Implemented Endpoints: 42
Coverage: 93%
Missing Implementations:
- DELETE /api/users/{id} (documented but not found)
- POST /api/users/{id}/suspend (documented but not found)
Undocumented Endpoints:
- GET /api/internal/health (found in code, not in spec)
- POST /api/debug/reset (found in code, not in spec)
Mismatched Signatures:
- POST /api/users
Spec expects: { email, name, role }
Code accepts: { email, name } (missing 'role')
Coverage Analysis Process:
Create upgrade guides when API versions change:
Migration Guide Template:
# API v2.0 Migration Guide
## Breaking Changes
### 1. User Creation Endpoint
**Change**: Required `role` field added to POST /api/users
**Impact**: All user creation calls will fail without this field
**Action Required**:
- Update all POST /api/users calls to include `role`
- Default to 'member' if no specific role needed
Before:
{ "email": "user@example.com", "name": "John" }
After:
{ "email": "user@example.com", "name": "John", "role": "member" }
### 2. Authentication Token Format
**Change**: JWT tokens now use RS256 instead of HS256
**Impact**: Token validation must be updated
**Action Required**:
- Update JWT verification libraries
- Fetch new public key from /.well-known/jwks.json
Guide Generation Steps:
/v1/, /v2/ prefixes or version headers@deprecated directive1. User: "Validate the OpenAPI spec"
2. Read the spec file (usually openapi.yaml or swagger.json)
3. Parse and validate structure
4. Report any issues with suggestions
1. User: "Does our API implementation match the spec?"
2. Read spec file
3. Extract all endpoints
4. Search codebase for route handlers
5. Compare and generate coverage report
1. User: "Compare API v1 and v2 specs"
2. Read both spec files
3. Diff schemas systematically
4. Categorize changes as breaking/non-breaking
5. Generate migration guide
1. User: "Generate TypeScript types from the API spec"
2. Read OpenAPI/GraphQL schema
3. Extract all data models
4. Generate TypeScript interfaces
5. Create client functions or hooks if requested
1. User: "What endpoints are missing in our spec?"
2. Run implementation matching
3. Identify undocumented endpoints
4. Suggest adding them to spec with proper schemas
When validation tools are available, use them:
npx @stoplight/spectral-cli lint openapi.yamlnpx graphql-inspector validate schema.graphqlFor advanced diff analysis:
npx openapi-diff old.yaml new.yamlnpx graphql-inspector diff old.graphql new.graphqlRecommend these tools for automated generation:
When encountering issues:
Invalid Spec File:
Missing Implementation:
Type Mismatches:
For more detailed information on specific topics, see:
This skill works best with:
No additional packages are required for basic validation and comparison. Advanced features may suggest installing validation tools via npm.
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.