Property tests from the contract
contractdiff props draws values from each payload's schema and checks four properties with no server: the validator agrees with the schema, values survive JSON, normalise is idempotent, and what diff calls compatible really is; replayable by seed, with fast-check arbitraries for your own tests.
contractdiff props <contract> tests the contract itself, with no server running. For every
payload it draws values from the JSON Schema with a generator written apart from the validator,
and checks four properties:
| property | what it checks |
|---|---|
agreement | the generated validator accepts every value drawn, and refuses each value with one constraint broken, at the place broken |
round-trip | every value survives JSON.stringify and JSON.parse unchanged |
normalise | normalising a value is idempotent, and accepts what the schema accepts |
soundness | with --against <old>: every payload diff calls compatible accepts any value the old sender may send |
ok: old.yaml, 100 run(s) per payload, seed 7
agreement 200 checked, 0 discarded, 0 failed
round-trip 200 checked, 0 discarded, 0 failed
normalise 200 checked, 0 discarded, 0 failed
soundness 0 checked, 0 discarded, 0 failed--runs is the number of values drawn per payload and property (1000 by default). The seed is
printed on every run; without --seed, one is taken from the clock, so a failure in CI is replayed
locally with the seed it printed.
Checking diff itself
--against adds the soundness property: for the changes diff would call non-breaking, values the
old side may send are drawn and run through the new side's validator. It tests the classifier on
your contract, not just on the package's own fixtures.
ok: new.yaml, 100 run(s) per payload, seed 7
agreement 300 checked, 0 discarded, 0 failed
round-trip 300 checked, 0 discarded, 0 failed
normalise 300 checked, 0 discarded, 0 failed
soundness 200 checked, 0 discarded, 0 failedA counterexample is shrunk to the smallest value that still fails, and printed with the seed that
found it. --sarif prints the counterexamples as SARIF; --mode and --side take the same values
as in diff. Keywords the generator does not hold to are reported, not ignored.
Arbitraries for your own tests
--emit <file> writes fast-check arbitraries for every payload, for a project's own property tests.
--runs 0 writes them without running the properties:
npx contractdiff props openapi.yaml --emit test/arbitraries.ts --runs 0The emitted file imports fast-check, which the project installs itself; contractdiff does not
depend on it.
Agents
How a coding agent uses contractdiff: explain one operation resolved and size-capped instead of reading the whole spec, lint a contract or an MCP tool list for agent-readiness, and drive every command through --json, --schema and the --mcp server.
Write a plugin
Scaffold a contractdiff generator, extractor, input adapter or lint rule with contractdiff plugin new, prove it with the conformance suite from contractdiff/testing, and load it from contractdiff.config.json.