Agent skill
api-contract-validator
Validate API contracts and ensure compatibility. Use when checking OpenAPI specs, running contract tests, detecting breaking changes, or generating types from API specifications.
Install this agent skill to your Project
npx add-skill https://github.com/j0KZ/mcp-agents/tree/main/starter-kit/template/.claude/skills/api-contract-validator
SKILL.md
API Contract Validator
Ensure API compatibility and prevent breaking changes through contract testing
Quick Commands
# Validate OpenAPI spec
npx @apidevtools/swagger-cli validate api-spec.yml
# Run contract tests
npm run test:contracts
# Check breaking changes
npx oasdiff breaking api-v1.yml api-v2.yml
# Generate types from spec
npx openapi-typescript api-spec.yml --output types.ts
Core Functionality
Key Features
- Schema Validation: OpenAPI/Swagger spec validation
- Contract Testing: Consumer-driven contracts
- Breaking Change Detection: API compatibility checking
- Mock Generation: Generate mocks from contracts
- Type Safety: TypeScript types from API specs
Detailed Information
For comprehensive details, see:
cat .claude/skills/api-contract-validator/references/contract-testing-guide.md
cat .claude/skills/api-contract-validator/references/openapi-best-practices.md
cat .claude/skills/api-contract-validator/references/versioning-strategy.md
Usage Examples
Example 1: Validate API Response
import { APIContractValidator } from '@j0kz/api-contract-validator';
const validator = new APIContractValidator('./api-spec.yml');
// Validate response against contract
const response = await fetch('/api/users/123');
const validation = await validator.validateResponse(
'GET',
'/users/{id}',
response
);
if (!validation.valid) {
console.error('Contract violation:', validation.errors);
}
Example 2: Consumer-Driven Contracts
// Consumer defines expectations
const contract = {
consumer: 'mobile-app',
provider: 'user-service',
interactions: [{
description: 'get user by id',
request: {
method: 'GET',
path: '/users/123'
},
response: {
status: 200,
body: {
id: '123',
name: 'John Doe',
email: 'john@example.com'
}
}
}]
};
await validator.verifyContract(contract);
Contract Testing Patterns
Pact Testing
const { Pact } = require('@pact-foundation/pact');
const provider = new Pact({
consumer: 'MyConsumer',
provider: 'MyProvider'
});
// Define interactions
await provider.addInteraction({
state: 'user exists',
uponReceiving: 'a request for user',
withRequest: {
method: 'GET',
path: '/users/1'
},
willRespondWith: {
status: 200,
body: expectedUser
}
});
Configuration
{
"api-contract-validator": {
"specFile": "./api/openapi.yml",
"strict": true,
"allowAdditionalProperties": false,
"contracts": {
"directory": "./contracts",
"publish": true,
"broker": "https://pact-broker.example.com"
},
"breaking": {
"allowRemoval": false,
"allowTypeChange": false,
"allowRequired": false
}
}
}
CI/CD Integration
# GitHub Actions
- name: Validate API Contract
run: |
npx @j0kz/api-contract-validator validate
npx @j0kz/api-contract-validator check-breaking
- name: Publish Contracts
run: npx @j0kz/api-contract-validator publish
Notes
- Supports OpenAPI 3.0, Swagger 2.0, and AsyncAPI
- Integrates with Pact for consumer-driven contracts
- Can generate API documentation automatically
- Supports GraphQL schema validation
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
debug-detective
Systematic debugging approach for ANY codebase, ANY language, ANY bug type
tool-discovery
Guide for discovering and using @j0kz MCP tools efficiently through search, filtering, and progressive exploration. Use when exploring available capabilities, finding the right tool for a task, or ...
project-standardization
Guides correct usage of @j0kz/mcp-agents standardization and automation scripts including version.json single source of truth, test count automation, URL casing rules, and critical workflow pattern...
api-integration
Master third-party API integration in ANY language with best practices and patterns
documentation-generation
Documentation generation and maintenance patterns including README structure, CHANGELOG management, API documentation, wiki synchronization, and badge updates. Use when creating package docs, updat...
competitive-ads-extractor
Extracts and analyzes competitor ads from ad libraries (Facebook, LinkedIn, TikTok, Google). Use when researching competitor messaging, creative patterns, campaign strategies, or ad inspiration. Ch...
Didn't find tool you were looking for?