Skip to main content

Export a contract

The Export page takes a contract out of Apiome in one of four ways:

  • A pact from a project — a consumer's declared surface written as a Pact v4 file (apiome pact export-consumer-contract).
  • A Postman collection — a pact replayed as Postman requests with test scripts (apiome pact export-postman).
  • A pact file — any published pact exactly as it was stored, or every pact for a provider as a zip.
  • Provider test scaffolding — a ready provider verification test in TypeScript, Java, Go or Python, with a stub for every provider state the pacts use (apiome pact scaffold-provider-tests). See Provider test scaffolding.

Open it from a pact's page (Export, which opens on that pact's file), from a pacticipant's page (Export, which opens on a Postman collection of its pacts) or from Export studio (Export a contract). Its address is /ade/dashboard/pacts/export. Export studio itself exports an API specification; see Export to an API client for a collection made from a spec.

Pick one of the four cards at the top. Only that kind's form shows, with its own button and its own The same, from anywhere block: the command (and REST request) that does the same from a terminal or a pipeline, updated as you fill in the form. Problems and refusals appear on one line above the cards.

The Export page on A pact from a project: the Billing API project and the Orders UI consumer, the operation checklist with where each example comes from, the pact preview, Download pact and Review and publish, and the export-consumer-contract commandThe Export page on A pact from a project: the Billing API project and the Orders UI consumer, the operation checklist with where each example comes from, the pact preview, Download pact and Review and publish, and the export-consumer-contract command
Route/ade/dashboard/pacts/export

A pact from a project​

A consumer you declared with the picker on a project's Consumers tab has no pact file of its own. This kind writes one: one interaction per operation and response status the consumer reads, carrying only the fields it declared, with the specification's own examples as sample values.

  1. Choose the project and the consumer. A consumer whose contract was imported from a Pact file, or that has no contract revision yet, is greyed out with the reason — publish that Pact file instead.
  2. Optionally give a Revision (the current one otherwise) and the Provider name to write into the pact (otherwise the pacticipant bound to the project).
  3. Click "Derive pact". The operation checklist fills in.

Each row of the checklist is one declared operation and says where its examples came from:

The column readsWhat it means
The spec's exampleEvery value came from the specification's examples.
Generated from the schema — reviewAt least one value had no example and was invented from the schema (a typed placeholder). The number says how many. Review them before you rely on the pact.
Left out — reasonNo interaction could be written, for example no response to assert on. The box cannot be ticked.

Under the checklist, every finding is listed with its reason code (no-example, status-default, media-type-not-json, …): nothing is dropped without saying so.

  • Untick an operation to leave its interactions out of the preview and the download. The command cannot do this — it always writes every declared operation — so The same, from anywhere lists what you left out and why. To leave an operation out of the command too, change the consumer's declared surface.
  • Click "Download pact" to save it as <consumer>-<provider>.json. The preview shows the pact while it is small; a pact over about 200 KB downloads without a preview.
  • Click "Review and publish" to take it to the Publish page. With every operation ticked and the current revision, the page opens on Derive from a project with the project and consumer filled in, so the pact is published as derived. Otherwise the exact file you see is handed over on Paste. Either way nothing is published until you say whose version it is and click Publish pact. The button shows only with Pacts → Create.

Fail if anything needs review only changes the command: --fail-on-findings makes it exit 1 in CI when a value had to be invented or anything was left out.

A revision with nothing to export says This revision has no operations a pact can describe., with the findings that explain why.

A Postman collection​

This kind writes a pact as a Postman Collection v2.1, so a provider team can run the consumer's requests in Postman — or in CI with Newman — before any Pact tooling is set up.

  1. Choose which pact under Which pact: The latest pact, Latest on a branch, Latest with a tag, A consumer version, A pact version (SHA), or Upload a pact file… for one you have not published (it is sent once to make the collection and is not stored).
  2. For a stored pact, type the Provider and Consumer (names or handles; the workspace's pacticipants are suggested). Tick All consumers — one folder each to export the latest pact of every consumer of the provider — or, with a branch or a tag, each consumer's latest such pact.
  3. Set the Provider base URL, or leave it empty to fill in the {{baseUrl}} variable later (Newman: --env-var baseUrl=http://localhost:8080). Pointing it at a hosted mock is a safe way to try the collection.
  4. Choose the switches:
    • Include provider-state setup as pre-request scripts (on by default) — each request that needs provider states first POSTs {"state", "params", "action": "setup"} per state, in the pact's order, to the {{stateChangeUrl}} variable: the body pact_verifier_cli --state-change-url sends, so the state-change endpoint your verification already uses works unchanged. Fill in State change URL, or set the variable in Postman. If it is not set, or a setup answers an error, the request stops with an error naming the state instead of running against the wrong data.
    • Give each request a test script (on by default) — checks the status, the expected headers and the body by Pact's default rules.
    • Fail if any interaction is left out — only changes the command (--fail-on-left-out).
  5. Click "Export collection", then Download collection.

The Result card names the file (<consumer>-<provider>.postman.json, or every-consumer-<provider>.postman.json) and shows What the collection keeps: a bar of how many of the pact's interactions became requests. Below it, every notice is listed with its reason:

OutcomeFor
left-outMessage interactions, gRPC calls, interactions without a method, request bodies that are not text — and, with All consumers, a consumer with no such pact. Postman sends HTTP requests with text bodies only.
not-assertedResponse values governed by a matching rule, and response bodies that are not text.
not-appliedRequest generators: the request sends the pact's example values.
infoThe provider states the requests need.

A pair without a pact reads Orders UI has not published a pact for Billing Service. Record one from a mock, or upload a file. A pact with no HTTP interaction at all is refused, with the notices that say why.

A pact file​

  1. Type the Consumer and Provider, and choose Which pact (as for Postman, without an upload).
  2. Click "Download pact.json" to save the pact exactly as it was published: the broker's _links and createdAt, which a read through the Pact Broker API adds, are taken off.
  3. Or click "Every pact for this provider (.zip)" for one file per consumer — its latest pact, or its latest on the branch or with the tag — and a README.txt naming every consumer left out and why. A version or a SHA names one consumer's pact, so the zip takes the latest, a branch or a tag only. A zip holds at most 100 pacts; the README lists the rest.

No apiome pact command downloads a pact, so this kind's block shows the REST request: any HTTP client fetches the same document with your API key.

Provider test scaffolding​

A provider team adopting Pact otherwise starts from a blank file and has to find out which provider states its consumers rely on. This kind writes the starting point.

  1. Type the Provider (its name or handle).
  2. Choose the Language: TypeScript · pact-js, Java · pact-jvm, Go · pact-go or Python · pact-python.
  3. Click "Write tests".

Pacts says which pacts the test verifies: the recommended selectors — each consumer's main branch, and whatever is deployed or released — with pending pacts on, so a new consumer expectation does not break the provider's build until it has been verified once.

The file:

  • reads the broker from PACT_BROKER_BASE_URL and PACT_BROKER_TOKEN, and the provider's address from PROVIDER_BASE_URL (default http://localhost:8080). No secret is written into it.
  • publishes results only when CI=true, as GIT_COMMIT on GIT_BRANCH.
  • has one state handler stub per provider state the pacts name, marked TODO, and an EXAMPLE_PARAMETERS table with the parameters each state was sent with (one example value each).
  • marks each state not registered in Apiome with a comment: hosted verification cannot set it up until it is registered under the provider's provider states.

The states table lists each state with its parameters and In Apiome — Registered, or No handler. The line under the file reads, for instance, 11 provider states · 2 have no handler in Apiome. Click "Download" or "Copy"; the card names what to install (for pact-js, npm install --save-dev @pact-foundation/pact). A file over about 200 KB downloads without a preview.

Provider test scaffolding for Billing Service in TypeScript: the recommended selectors, the states table with one state flagged No handler, the generated pact-js test, Download and Copy, and the scaffold-provider-tests commandProvider test scaffolding for Billing Service in TypeScript: the recommended selectors, the states table with one state flagged No handler, the generated pact-js test, Download and Copy, and the scaffold-provider-tests command
Route/ade/dashboard/pacts/export?kind=tests
LanguageLibraryFile
TypeScriptpact-js (Verifier, Jest or Vitest)<provider>.pact.test.ts
Javapact-jvm JUnit 5 (@Provider, @PactBroker, @State)<Provider>PactTest.java
Gopact-go v2 (provider.NewVerifier)<provider>_pact_test.go
Pythonpact-python 2 (Verifier.verify_with_broker)test_<provider>_pact.py

pact-python 2 sets states through a state-change URL, so its file also has handle_state_change: mount it at PROVIDER_BASE_URL + /_pact/provider_states in a test build of the provider.

A provider with no pact yet still gets a file, with no handlers and a note saying so. More than 200 states, or a state name over 500 characters, is left out of the file with the reason listed.

Fail if a state has no handler in Apiome only changes the command: --fail-on-unregistered exits 1 when a state is not registered.

From the command line​

Every flag of the three commands has a control on the page:

apiome pact export-consumer-contract --project billing-api --consumer orders-ui \
--revision 4 --output pact.json --fail-on-findings

apiome pact export-postman --provider "Billing Service" --all-consumers --branch main \
--provider-base-url http://localhost:8080 \
--state-setup --state-change-url http://localhost:8080/_pact/provider_states \
--output collection.json --fail-on-left-out

apiome pact scaffold-provider-tests --provider "Billing Service" --language typescript \
--output billing-service.pact.test.ts --fail-on-unregistered

--all-consumers takes --provider and at most one of --tag or --branch. --state-change-url needs --state-setup. See Export a pact as a Postman collection and the CLI reference.

Who can do what​

ActionNeedsViewerEditorAdminOwner
Derive a pact from a projectconsumer_contracts:view and pacts:view✓✓✓✓
Export a Postman collection, download a pact file or a zippacts:view✓✓✓✓
Write provider testspacts:view✓✓✓✓
Review and publishpacts:create—✓✓✓

Every read is scoped to your workspace: a pact, project or pacticipant of another workspace is not found.