# API Contract Engineer

> Hands-on implementation of contract testing: Pact consumer tests, provider verification, and schema validation wired into CI. Use when working with pact implementation, schema validation or when the user mentions pact implementation, schema validation.

- Skill: `opknock/api-contract-engineer` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-contract-engineer`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-contract-engineer/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-contract-engineer

---


Hands-on implementation of contract testing: Pact consumer tests, provider verification, and schema validation wired into CI.

## Agentic Workflow: Read -> Reason -> Act (api-contract-engineer)

You are **api-contract-engineer** (testing) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — testing context for `api-contract-engineer`
- Domain: Hands-on implementation of contract testing: Pact consumer tests, provider verification, and schema validation wired into CI.
- **pact-implementation**: Write and run Pact consumer and provider tests in Node and Python — `npm install @pact-foundation/pact`
- **schema-validation**: Validate live API responses against OpenAPI-derived JSON Schemas in tests — `npm install ajv`
- Check `knowledge` and `prerequisites: pact, openapi, node.js, python`

### 2. Reason — think for `api-contract-engineer`
- For `pact-implementation`: Write and run Pact consumer and provider tests in Node and Python — decide which checks to run
- For `schema-validation`: Validate live API responses against OpenAPI-derived JSON Schemas in tests — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-contract-engineer` tools
- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Npx` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-contract-engineer:ba3e429f`

# API Contract Engineer

Implements contract tests that catch breaking API changes before they reach production.

## When to Use
- Consumer and provider teams move fast
- Breaking changes keep slipping through
- Third-party APIs need guards

## Real Commands

```bash
# Install
npm install @pact-foundation/pact

# Run consumer tests
npx jest --testMatch '**/pact/*.test.js'

# Publish contracts
npx pact-broker publish ./pacts --consumer-version 1.0.0 --broker-base-url http://localhost:9292

# Provider verification
npm run test:provider

# Validate spec parses
node -e "const P=require('@apidevtools/swagger-parser');P.validate('openapi.yaml').then(()=>console.log('valid'))"
```

## Provider State
Set up provider states so verification runs against known fixtures.

## Testing
Run consumer tests on every PR; verification in the provider pipeline.

## Best Practices
- Publish contracts with unique versions
- Gate deploys with can-i-deploy
- Keep pacts small and readable

## Capabilities

### pact-implementation
Write and run Pact consumer and provider tests in Node and Python

**Parameters:**
- `consumer` (string): Consumer app name
- `provider` (string): Provider app name
- `version` (string): Consumer version

**Commands:**
- `npm install @pact-foundation/pact`
- `npx jest --testMatch '**/pact/*.test.js'`
- `npm run test:provider`
- `npx pact-mock-service start --port 1234`
- `npx pact-broker publish ./pacts --consumer-version 1.0.0 --broker-base-url http://localhost:9292`

**Examples:**
- npx jest --testMatch '**/pact/*.test.js' --runInBand
- npm run test:provider && npx pact-broker publish ./pacts --consumer-version 1.0.0
- npx pact-mock-service start --port 1234 --pact-dir ./pacts

### schema-validation
Validate live API responses against OpenAPI-derived JSON Schemas in tests

**Parameters:**
- `spec` (string): OpenAPI spec path
- `response` (string): Response JSON to validate

**Commands:**
- `npm install ajv`
- `npm install @apidevtools/swagger-parser`
- `node -e "const P=require('@apidevtools/swagger-parser');P.validate('openapi.yaml').then(()=>console.log('valid')).catch(e=>console.log(e.message))"`
- `node -e "const Ajv=require('ajv');const a=new Ajv();console.log(a.validate({type:'object',additionalProperties:false,required:['id']},{id:1,x:2})===false?'rejected':'passed')"`
- `pip install openapi-schema-validator && python -c "from openapi_schema_validator import validate;print('ok')"`

**Examples:**
- node -e "const P=require('@apidevtools/swagger-parser');P.validate('openapi.yaml').then(()=>console.log('valid'))"
- node -e "const Ajv=require('ajv');const a=new Ajv();console.log(a.validate({type:'object',required:['id']},{id:1}))"
- python -c "from openapi_schema_validator import validate;validate({'id':1},{'type':'object','required':['id']});print('ok')"

## References
- [Pact JS](https://docs.pact.io/implementation_guides/javascript/)
- [Pact Broker](https://docs.pact.io/pact_broker/)
- [swagger-parser](https://apitools.dev/swagger-parser/)

