Skip to main content

Generate a pact from a mock: record, review, publish

You can now create a consumer's pact without a Pact library and without rewriting a test. Open Contracts → Start something → Generate a pact from a mock, point your consumer at a hosted mock, and let Apiome write the pact from what it calls. See Pact from a mock.

  • Record a session. Choose the mock and the consumer, click “Start recording”, and copy two lines into your consumer: the mock's address and the X-Mock-Capture header. A counter shows the calls as they arrive. A consumer that cannot add a header gets a private capture URL instead.
  • Captured calls, with a reason on every row. Calls are grouped as the pact will hold them: one row per operation, status and provider state. Calls injected by chaos mode and calls the spec does not have are listed and left out. Untick any interaction to leave it out too.
  • Choose how strict. Balanced matches values by type. Strict also applies the spec's formats and patterns. Override single fields, and see which sensitive values the mock's redaction removed.
  • See what the consumer really uses. The side panel says how many of the spec's operations and response fields the pact covers, and checks the pact against the mocked spec, the provider's main branch, what is deployed and the latest draft.
  • Review, then publish. The review shows what changed since the last pact first — new interactions, dropped ones, and a note when the pact got looser — and the JSON second. Publish pact publishes it like any other pact; See it in the matrix takes you to the verdict.

The page says plainly when it cannot go on: the mock is off (with the switch beside the message), it is still waiting for the first call, nothing matched the spec, or the captured calls have expired.

Set up contracts now offers Record it from the mock as the first way to a first pact, and Publish a pact has a fifth tab, Record from a mock, that leads here.

For the REST API: POST …/pact-broker/pacts/generate takes leave_out and reports spec_usage and left_out_interactions. apiome pact record for CI comes next.