Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MockServer can turn a service’s OpenAPI 3.0 or 3.1 specification into request-matching expectations, then help you verify received requests and inspect recorded traffic. Use the service’s contract to define the mock; use MockServer’s separate record-and-replay workflow when you need to capture actual upstream exchanges.

What you need: the service’s OpenAPI contract

For generated mocks, the OpenAPI document must describe the service you want MockServer to simulate—not MockServer itself. Current MockServer documentation supports OpenAPI 3.0 and 3.1 in JSON or YAML. The document can be supplied as a URL, file URL, classpath location, inline JSON object, or inline YAML string. See the OpenAPI expectation documentation for supported inputs and options.

MockServer also publishes an OpenAPI description of its own REST API at /mockserver/openapi.yaml on a running instance. That describes the API used to control MockServer; it is not the service contract to import when generating a mock of your application.

Generate expectations from the OpenAPI document

Importing the service contract creates expectations that match requests according to the OpenAPI operations. You can select operations and response status codes with operationsAndResponses. If you do not specify a selection, MockServer includes all operations and, when an operation has multiple responses, uses the first response body.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The import is documented as incremental: re-importing updates existing generated expectations, adds new ones, and prunes generated expectations that no longer belong. This supports repeat imports in tests or CI without accumulating duplicate generated sets. Check the behavior against the MockServer release deployed in your environment, since documentation and behavior can vary by version.

Track and verify requests

OpenAPI is useful beyond setting up the mock. MockServer can use the specification to verify received requests and request sequences, and to filter retrieval or clearing of logs and recorded requests. This lets a test check whether expected operations occurred, rather than only whether a client received a response.

The retrieval interfaces distinguish several kinds of server state. Choose the one that matches what you are investigating:

  • Recorded requests: requests received by the server.
  • Recorded request-response pairs: traffic together with the corresponding responses.
  • Active expectations: expectations currently configured on the server.
  • Recorded expectations: expectations recorded by MockServer.
  • Logs: server log entries, which can help diagnose matching and request behavior.

MockServer clients and the REST API can retrieve these records. The client and REST API documentation describes the available control and retrieval interfaces.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose contract generation or proxy record-and-replay

Approach Where examples come from Best fit What it tracks
Generate expectations from OpenAPI The declared service contract Repeatable mocks and checks aligned to documented operations Whether requests conform to the contract, including request sequences
Proxy record-and-replay Observed HTTP(S) requests and upstream responses Inspecting or replaying concrete exchanges captured through a proxy Actual request-response traffic; recorded data can be exported as HAR 1.2

These workflows answer different questions. A contract describes intended operations and responses; a proxy recording captures exchanges that actually occurred. Use the OpenAPI route when your goal is contract-based expectations or verification. Use record and replay when you need upstream responses captured and available for replay as expectations.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Pick a control surface for your workflow

REST API or client libraries

Use the REST API or a client library when setup and tracking belong in automated tests, scripts, or CI. MockServer documentation lists Java, JavaScript, Python, Ruby, Go, .NET, Rust, and PHP interfaces, in addition to REST. Choose the language that fits the test harness and use the relevant MockServer client documentation for its current syntax.

VS Code extension

If you work directly with specification files in VS Code, the IDE extension documents generating expectations from an OpenAPI file and viewing a running server’s request log in an output panel. This is a convenient route for file-centered editing and interactive inspection; automation can still use the REST API or a client. See the MockServer IDE extensions page.

A practical workflow

  1. Confirm the input. Use the service’s OpenAPI 3.0 or 3.1 document in JSON or YAML, and identify the MockServer release you run.
  2. Choose the operations and responses. Set operationsAndResponses if you want to limit what is generated or select response status codes; otherwise all operations are included and the first response body is used when alternatives exist.
  3. Import the specification. Provide it using a supported source such as a URL, file URL, classpath location, or inline content.
  4. Send requests to the mock. Exercise the operations your client or test needs to call.
  5. Verify and inspect. Use OpenAPI-based request or sequence verification, then retrieve the relevant recorded requests, request-response pairs, expectations, or logs.
  6. Re-import when the contract changes. The documented incremental import updates, adds, and prunes generated expectations, allowing the generated set to follow the specification.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.