api-contract-tester
Skill3 starsChanged 11 months agoApache-2.0View on GitHub
Test API contracts and ensure compatibility. Use when the user needs to validate API schemas, test backward compatibility, or implement contract testing.
- Installs packages
In this repository100 other files it gives its agents.
- accessibility-checkerSkill
- analytics-trackerSkill
- api-documentation-generatorSkill
- api-rate-limiterSkill
- appstore-screenshot-resizerSkill
- architecture-documenterSkill
- authentication-implementerSkill
- aws-resource-provisionerSkill
- browser-extension-builderSkill
- caching-implementerSkill
- changelog-generatorSkill
- chart-generatorSkill
- ci-pipeline-debuggerSkill
- cli-tool-builderSkill
- code-documenterSkill
- code-explainerSkill
- code-migration-helperSkill
- code-refactorerSkill
- code-reviewerSkill
- color-palette-generatorSkill
- comment-generatorSkill
- contributing-guide-writerSkill
- cron-job-schedulerSkill
- css-animatorSkill
- csv-processorSkill
- data-aggregatorSkill
- database-backup-restoreSkill
- database-migration-generatorSkill
- database-query-optimizerSkill
- data-transformerSkill
- data-validatorSkill
- date-time-helperSkill
- debug-helperSkill
- dependency-updaterSkill
- dependency-vulnerability-checkerSkill
- discord-bot-builderSkill
- docker-compose-builderSkill
- dockerfile-generatorSkill
- e2e-test-builderSkill
- email-template-builderSkill
- env-setupSkill
- error-handlerSkill
- error-message-writerSkill
- error-response-handlerSkill
- etl-pipeline-builderSkill
- file-organizerSkill
- form-builderSkill
- git-commit-messageSkill
- github-actions-builderSkill
- gitignore-generatorSkill
- graphql-schema-builderSkill
- icon-system-builderSkill
- input-validatorSkill
- integration-test-builderSkill
- jsdoc-generatorSkill
- json-schema-generatorSkill
- kubernetes-manifest-generatorSkill
- license-chooserSkill
- linter-fixerSkill
- load-testerSkill
- The first 60 shown.
The file
Files
API Contract Tester
Validate API contracts between services.
Pact (Consumer-Driven Contracts)
Consumer Test
import { Pact } from '@pact-foundation/pact';
import { getUserById } from '../client/userClient';
const provider = new Pact({
consumer: 'frontend',
provider: 'user-service',
port: 1234,
});
describe('User API Contract', () => {
beforeAll(() => provider.setup());
afterAll(() => provider.finalize());
afterEach(() => provider.verify());
it('should get user by id', async () => {
// Define expected interaction
await provider.addInteraction({
state: 'user with id 1 exists',
uponReceiving: 'a request for user 1',
withRequest: {
method: 'GET',
path: '/api/users/1',
headers: { Accept: 'application/json' },
},
willRespondWith: {
status: 200,
headers: { 'Content-Type': 'application/json' },
body: {
id: 1,
name: Matchers.string('John Doe'),
email: Matchers.email(),
},
},
});
// Make the actual call
const user = await getUserById(1);
expect(user.id).toBe(1);
expect(user.name).toBeDefined();
});
});Provider Verification
import { Verifier } from '@pact-foundation/pact';
describe('User Service Contract Verification', () => {
it('validates contract with frontend', async () => {
await new Verifier({
provider: 'user-service',
providerBaseUrl: 'http://localhost:3000',
pactUrls: ['./pacts/frontend-user-service.json'],
stateHandlers: {
'user with id 1 exists': async () => {
await createTestUser({ id: 1, name: 'John Doe' });
},
},
}).verifyProvider();
});
});OpenAPI Schema Validation
import SwaggerParser from '@apidevtools/swagger-parser';
import Ajv from 'ajv';
async function validateResponse(response, operationId) {
const api = await SwaggerParser.dereference('./openapi.yaml');
const schema = findResponseSchema(api, operationId, response.status);
const ajv = new Ajv();
const validate = ajv.compile(schema);
if (!validate(response.data)) {
throw new Error(`Response validation failed: ${JSON.stringify(validate.errors)}`);
}
}
// Usage in tests
it('should return valid user response', async () => {
const response = await api.get('/users/1');
await validateResponse(response, 'getUserById');
});Prism Mock Server
# Install
npm install -g @stoplight/prism-cli
# Start mock server from OpenAPI spec
prism mock openapi.yaml
# Validate requests
prism proxy openapi.yaml http://localhost:3000Contract Test Types
| Type | Description | When to Use |
| Consumer-driven | Consumer defines contract | Microservices |
| Provider-driven | Provider defines contract | Public APIs |
| Schema validation | Validate against spec | Any API |
CI Integration
jobs:
contract-test:
steps:
- name: Run consumer tests
run: npm run test:contract
- name: Publish pacts
run: |
npx pact-broker publish ./pacts \
--consumer-app-version=${{ github.sha }} \
--broker-base-url=${{ secrets.PACT_BROKER_URL }}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

