Skip to content

Check a mock against its contract

Before you begin

Plan
Included in Free, Pro and Team. How plans and limits work
Role
Viewer or higher to check a response and Editor or higher to link a mock to an operation.
You need
  • A project with an OpenAPI contract

Render a mock and check the response it would send against the operation it stands in for, so a mock that drifted from your API’s contract is caught before a caller relies on it.

  1. On the project’s Mocks tab, select the mock’s name.

  2. Under Contract operation, check Operation. A mock made by an import is linked already. For another mock, choose its operation, such as GET /orders/{id} · getOrder, and select Save mock.

  3. Select Try it. The dialog names the operation and revision it checks against.

  4. Change the request if you need to, such as the path /orders/43.

  5. Select Preview and validate.

Under Preview, the dialog shows the response as Preview this response would, and a Contract check section with one of four results:

Result Means
Valid The status, content type, headers and body all meet the operation.
Invalid At least one does not. Each finding names where it is and the rule it breaks.
Incomplete Part of the response could not be checked, so it is not a pass. The notes say why.
Not checked The request or the response does not belong to the operation, such as a request the mock does not match.

Each check is listed as Status, Content type, Headers and Body, with whether it passed. A body that sends "total": "4299" where the schema asks for an integer is Invalid, with the finding:

/total The data (string) must match the type: integer
Rule at /paths/~1orders~1{id}/get/responses/200/content/application~1json/schema/properties/total

The first part is where in the body the problem is; Rule at is where in the document the rule is.

A format is checked as JSON Schema and the OpenAPI Format Registry define it, from email and uuid to iri, idn-hostname, http-date, media-range, language, ipv4-cidr, unixtime and the sf-* structured fields. An int64 written as a string, such as "9007199254740993", must hold digits within its range. A language tag must be well formed, so en_US fails, but its subtags are not looked up. A vendor’s own, such as unix-time, describes the value and is not checked.

Some formats are also read the way many APIs write them: a relative link such as /orders?page=2 where the schema says format: uri, a date-time with no UTC offset or with a space for the T, such as 2024-05-01 10:00:00, a date-time-local with the space, and a duration written as ISO 8601 allows, such as PT0.5S. Such a value passes, and a note names where it is. Nothing else is read loosely: a missing required property, a null the schema does not allow, or a number sent as a string is Invalid.

Changing the mock, the request, or the operation clears the result, so a result on screen always belongs to what you see.

A link says which operation a mock answers for. It does not change which requests the mock matches, and a mock can be linked to one operation while several mocks share it. Clearing Operation and saving unlinks the mock.

When the active revision no longer has the linked operation, the editor says the operation is not in the contract’s active revision. The link stays until you change it, and Preview and validate answers Not checked.

  • A check covers one response, to one request, at one revision. It says nothing about the mock’s other responses, which response a request would get, other requests, the steps of a response sequence, or what a template renders next time.
  • Preview and validate does not count towards the workspace’s requests, like Preview this response.
  • If the contract gets a new revision while the dialog is open, the check still reads the revision the dialog names, and the result says which. Once that revision is no longer kept, the check is refused and the editor loads the active one; select Preview and validate again.
  • JSON and text bodies are checked. XML, schemas for other media types, and headers without a single type make the check Incomplete.
  • Live traffic is checked as it arrives only where Report mode or background checks are on. To check a response a mock or your upstream already sent, check its request log.

Report a problem with this page