ExamplesTestingCI

Examples that check what the response says

Runnable examples can now assert on the response itself — values in the body, headers and how long the call took — and the same examples run from the command line or CI with the `contract-test` tool.

In this release

  • New

    Response assertions

    An example can require a body value, a header or a response time, and a failed check is shown in the test results with what was expected and what came back.

  • New

    Run your examples in CI

    The `contract-test` command runs every example in a document against your API and reports the results in a form CI understands.

  • Improved

    Template variables belong to a project

    A base URL or token saved while working on one project is no longer used for another, and a project without a saved base URL uses the first server its own spec lists.

  • Improved

    Schema errors name the extra field

    A response with a field the schema does not allow now says which field and where, once, instead of repeating that some property was not allowed.

  • Improved

    Variables the spec declares

    A spec can describe the variables its examples need, with defaults; the editor lists them, prefills what is missing and masks secrets, and the CLI reads them from the environment.

  • Improved

    Failures that say what to fix

    Each failed test leads with its cause, points to the failed dependency to fix first, and can be copied as a summary to paste into an AI coding agent.

  • Fixed

    Share links ask before changing your server or secrets

    A link that carries a base URL, a secret, or a different value for a variable you saved shows both values and keeps yours unless you choose the shared one.

  • Improved

    Stored variables and results clean up after themselves

    Old test results and the variables of projects you no longer open are removed from your browser, and the project variables dialog can clear a project's stored data at once.

An example used to prove two things: the API answered with the status you expected, and the body matched the schema you documented. That catches a lot — but not a login that returns a well-formed token for the wrong user, a list that is suddenly empty, or a header your clients rely on quietly disappearing. A response can fit its schema perfectly and still be wrong.

Examples can now say what the response should contain.

Assertions on the response

Add an assert block to an example and it is checked after the status code and the schema:

  • Body values, found by a JSON Pointer such as /data/0/id or a simple JSONPath such as $.data[0].id, can be required to equal a value, exist, have a type, match a regular expression or contain an item. Patterns run on a linear-time engine, so one from a shared spec cannot freeze the page or the CLI; a few constructs such as lookaround are refused rather than run.
  • Headers take the same checks, by name, regardless of case.
  • Response time can be capped, in milliseconds.

When a check fails, the test results show which part of the response it looked at, the check that failed, and the expected value beside the one that actually came back — next to the status and schema errors you already see.

The same examples, outside the browser

The examples you run in the editor can now run from a terminal. The contract-test command reads your OpenAPI document, runs its examples in dependency order against the base URL you give it, and exits with a failure when any of them fails — so the checks you wrote while designing the API can guard every deploy. It can pick examples by operation or tag, take variables from the command line or an environment file, and write a report as readable text, JSON or JUnit XML. It ships as the @explore-openapi/contract-cli package, so npx @explore-openapi/contract-cli run openapi.yaml is all a CI job needs.

Variables that stay with their project

The variables your examples use — the base URL, tokens, API keys — used to be shared by every project you opened, so a base URL saved for one API sent the next project's requests to the wrong server. They are now saved per project, and results kept for reuse by dependent examples are kept per project and base URL too. A project with no saved base URL uses the first server listed in its own spec, and the variables dialog says which one is in effect. Variables saved before this change are not carried over, since there is no telling which project they were meant for — add them again in the project that needs them.

Variables, declared once

A spec can now list the variables its examples need — what each is for, a default for local development, and whether it is a secret. The editor's "Project variables" dialog shows every variable the examples use with its description and whether it has a value; "Set variables" opens it on the missing ones, offers a declared default with "Use default" instead of applying it silently, and masks secrets until you reveal them. Run All checks first and asks for anything missing instead of sending requests bound to fail. From the command line, contract-test takes --var, then an environment variable named after the variable (internal-secret → INTERNAL_SECRET), then the default — and stops before the first request when something is still missing. Secret values never appear in its reports.

Failures that say what to fix

A failed test now opens with one line saying why: a variable that is not set, the status that came back instead of the expected one, or the dependency that failed first. When the status is wrong, that is the only failure reported: the schema and assertions describe the expected response, so they are skipped — and counted as not evaluated, not as errors — and the test shows what the unexpected response said instead. Problems a failed dependency caused are folded away under it, schema errors are grouped by where they occurred, and the count shows distinct problems rather than every validator message. The dashboard also warns when examples use a variable the project has not set. "Copy summary for agent" turns the failures into a short Markdown report — with credentials removed — ready to paste into an AI coding agent, and contract-test run --reporter agent prints the same report in CI.

Share links that ask first

A share link can carry the variables its sender used. Applying them silently meant a link could point your project at another server — with your tokens attached to every request — or swap a secret you had saved. Now a link only fills in ordinary variables you have not set; a base URL, a declared secret or a value different from yours is shown side by side with your own, and nothing changes unless you tick it.

Storage that does not pile up

Variables and test results are kept in your browser, one set per project and server. They used to stay forever, until the browser's storage was full and new values quietly stopped being saved. Results now expire after 30 days and only the 20 most recently run sets are kept; the variables of a project you have not opened for 90 days are removed. "Clear stored data for this project" in the project variables dialog removes them straight away.

Existing examples keep working unchanged: assertions are optional, and an example without them is checked exactly as before.

All releases