Api contract testing

From vladkesler/initrunner · View interactive version

Api contract testing is an AI agent skill from the GitHub repository vladkesler/initrunner. Curl-based HTTP endpoint probing and response validation. Tests status codes, response bodies, headers, and schema conformance against expected contracts.

How to use this skill

Skill file

API contract testing skill using curl and inline validation scripts.

When to activate

Use this skill when the project has API endpoints: an OpenAPI/Swagger spec,

a routes directory, an Express/FastAPI/Flask/Rails app entrypoint, or

existing API test files. Also activate when integration tests reference HTTP

endpoints or when a new endpoint has been added.

Probing commands

Status code extraction

curl -s -w '\n%{http_code}' http://host:port/path

The last line of output is the HTTP status code. Capture it separately from

the response body.

Response body

curl -s http://host:port/path

Use -s (silent) to suppress progress bars.

Timing

curl -s -o /dev/null -w '%{time_total}' http://host:port/path

Record total request time for baseline comparison.

Sending payloads

curl -s -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' http://host:port/path

Always set the Content-Type header explicitly when sending a body.

Status validation

verify that the status matches the specific error condition (400 for

malformed input, 401 for missing auth, 403 for forbidden, 404 for

unknown resource, 422 for validation failure)

flag these as failures unless explicitly expected

Response body checks

Use inline scripts to validate JSON structure:

curl -s http://host:port/path | python -c "
import sys, json
data = json.load(sys.stdin)
assert 'id' in data, 'missing id field'
assert isinstance(data['id'], int), 'id must be integer'
"

Or with Node.js if Python is unavailable:

curl -s http://host:port/path | node -e "
const data = JSON.parse(require('fs').readFileSync(0,'utf8'));
if (!data.id) { console.error('missing id'); process.exit(1); }
"

Check:

Schema validation

When an OpenAPI spec is available:

  1. Identify the spec file (openapi.yaml, openapi.json, swagger.yaml).
  2. Locate the schema for the endpoint's response.
  3. Compare the actual response fields against the spec -- check field

presence, types, and required/optional status.

  1. Flag any extra fields not in the spec (potential data leak) and any

missing required fields (contract violation).

Headers

Verify these headers on every response:

API endpoints)

Method coverage

Test each endpoint with all relevant HTTP methods:

payload, verify 4xx error

For each method, test both the success path and at least one error path.

MUST

structure for all 4xx/5xx responses)

MUST NOT

requests against production

confirmation from the user

or config files instead

test case

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.