Configuration document
A project’s configuration document describes everything the project does, as one JSON document: its settings, mocks, scenarios, chaos profiles and webhooks. Edit a project’s configuration in the browser shows how to export, change and apply it.
Three rules hold for the whole document:
- It is complete. Applying it makes the project match it exactly: a mock, scenario, chaos profile or webhook the document leaves out is deleted, and a setting it leaves out goes back to its default.
- Names are identity. Resources are matched by name, so renaming one deletes it and creates a new one, and the old one’s history goes with it.
- References stay inside it. A mock’s
scenarioand a webhook’striggerMockname a scenario or mock in the same document.
In mockhub.yaml the CLI reads a few keys of its own beside these; see CLI commands.
Unknown fields are refused. Nothing in the document is secret: signing secrets, ids, timestamps and runtime state such as a scenario’s position or whether a chaos profile is active are never part of it.
The document
The top level. Every list is complete: a resource the document leaves out is deleted.
| Field | Type | Meaning |
|---|---|---|
version (required) | 3 | The document format, always 3: a mock lists its named responses and a selection of which one answers. A document of an older version is refused: export the project again to get a version 3 one. |
openapi (required) | null or openapi contract | Required: the project's OpenAPI contract, or null for none. null removes the contract, its revisions and every mock's link to it, and keeps the mocks. |
settings | object | The project settings. Left out, every setting takes its default. |
scenarios | list of scenarios | The scenarios mocks can move through. |
mocks | list of mocks | The project's mocks. |
chaosProfiles | list of chaos profiles | The chaos profiles, without their activation: activating one is not part of the document. |
webhooks | list of webhooks | The project's outgoing webhooks, without their signing secrets. |
Settings
The same settings as the project Settings page. Changing any of them needs Admin or higher.
| Field | Type | Meaning |
|---|---|---|
gatewayMode | "mock", "proxy-fallback", "record-all"Default: "mock" | What the project does with a request no mock matches: answer 404 (mock), forward it (proxy-fallback), or forward every request and keep the exchange as a capture (record-all). See Gateway modes. |
upstreamUrl | string or null Default: null | The API that proxy-fallback and record-all forward to. Required by those modes, and it must be a public address. |
enableResponseTemplating | boolean Default: true | Whether response bodies are rendered as templates. See Dynamic responses with templates. |
storeRequestLogs | boolean Default: true | Whether the project keeps request logs at all. |
logRequestData | boolean Default: true | Whether a request log keeps the request's headers, body and query string. Off, it keeps the method and path. |
logResponseData | boolean Default: true | Whether a request log keeps the response's headers and body. |
logUnmatchedRequests | boolean Default: true | Whether requests no mock matched are logged too. |
redactedHeaders | list of string Default: "Authorization", "Cookie" | Request headers whose values are replaced before a log is stored. Must be empty when logRequestData is false. |
redactedResponseHeaders | list of string Default: "Set-Cookie" | Response headers whose values are replaced before a log is stored. Must be empty when logResponseData is false. |
redactedBodyFields | list of string Default: an empty list | JSON body fields whose values are replaced in captures and inbox requests, on top of the built-in list. See Your data in MockHub. |
corsMode | "off", "any", "origins"Default: "any" | Which web pages may read the project's answers: every page (any), the pages in corsOrigins, which may send cookies (origins), or none, leaving CORS to the mocks (off). See Let web pages call a project. |
corsOrigins | list of string Default: an empty list | The origins corsMode: origins answers, such as http://localhost:5173, stored without a trailing / or default port. Kept when corsMode changes. |
accessMode | "public", "private" | Who the gateway serves: anyone (public), or HTTPS requests meeting the access policy (private). Leaving it out keeps the project's value. The default access policy is left out of exports. Making a project private, or public again, needs the Admin role. Keys are never part of the document. See Make a project private. |
accessPolicy | "all", "any" | How private requests qualify: all (Require both, the default) needs a key and a matching address when the list is nonempty. any (Allow either) accepts a key from anywhere or a matching address without a key. An empty list always needs a key. Leaving it out keeps the current choice. |
ipAllowList | list of string | The source addresses a private project accepts, as IPv4 or IPv6 addresses and CIDR ranges, such as 203.0.113.0/24. Stored in canonical form, so spelling and order are never a change. Empty means any address with a key. Like accessMode, leaving it out keeps the project's list, and an empty list removes the restriction. |
upstreamHeaders | object | Request headers every forwarded request carries in place of the caller's header of the same name, such as Authorization, at most 20. Write-only: an export shows [REDACTED], which keeps the stored value when sent back. Leaving the field out keeps the stored headers and {} clears them. Moving upstreamUrl to another origin needs every value again. Write values as ${env:NAME} so a secret never sits in the file. A pack never carries them. See Record traffic from a real API. |
requestCheckMode | "off", "report", "reject" | What the gateway does with a request that breaks the contract revision requestCheckRevision names: off (not checked), report (checked before any mock answers, the findings recorded beside the log, the request served as if unchecked) or reject (only on an ephemeral environment in mock mode: a request that breaks the contract is answered 422 and one that cannot be decided 503, before any mock is touched). Leaving it out keeps the current policy, and an explicit off clears it with its revision and operations. See Check requests against the contract and Refuse invalid requests in a preview environment. |
requestCheckRevision | integer, from 1 | The retained contract revision requests are checked against. Required with report and reject, refused with off. Leaving it out keeps the current revision. |
requestCheckOperations | list of string | Only these operations are checked, each written METHOD /path, such as GET /orders/{id}. Leaving the key out keeps the current set; a mode named without it checks every operation. |
Scenarios
Each item of scenarios.
| Field | Type | Meaning |
|---|---|---|
name (required) | string, at least 1 characters, at most 255 characters | Unique in the project. Mocks refer to the scenario by it. |
states (required) | list of string, at least 1 item | The states after the first, in order. Every scenario starts in Started, which is implicit: do not list it. |
Mocks
Each item of mocks. A mock lists its responses and says in responseSelection which of them answers.
| Field | Type | Meaning |
|---|---|---|
name (required) | string, at least 1 characters, at most 255 characters | Unique in the project. Renaming a mock deletes it, with its history, and creates a new one. |
status | "Inactive", "Active"Default: "Active" | Whether the project serves the mock. |
request (required) | object | How requests are matched: method and one of url, urlPath, urlPathTemplate (with pathParameters) or urlPathPattern, optionally with headers, queryParameters, cookies, formParameters, bodyPatterns (text, matchesJsonPath and equalToJson) and multipartPatterns. See Request matchers. |
responses (required) | list of responses, at least 1 item | Every response the mock can answer with, from 1 to 50, each under a key that stays the same however it is edited. See Responses. |
responseSelection (required) | default selection or sequence selection or rules selection | Which response answers: the default one, which a request may replace with another when allowRequestOverride is on, the first of an ordered list of rules on the request that holds, or a sequence of response keys answered in turn. A sequence cannot be combined with scenario. See Choose the response that answers. |
scenario | string, at least 1 characters, at most 255 characters | The name of a scenario in this document that the mock takes part in. |
requiredScenarioState | string | The state the scenario must be in for this mock to match. |
newScenarioState | string | The state the scenario moves to after this mock answers. |
store | object | The mock's use of the project's data store. See Data store below. |
responseTemplating | "inherit", "disabled" | disabled serves every response of the mock exactly as written, as Serve as written does. Left out, the mock follows the project. |
openapiOperation | null or operation | The contract operation the mock is linked to. Left out, the mock has no link. |
openapiGeneration | null or import provenance | What an OpenAPI import generated the mock from, which the next import compares with to keep your edits. See Import provenance. |
tags | list of string Default: an empty list | Labels to find the mock by, stored lowercase. Left out means none: an apply replaces the mock's tags with this list, so a tag added in the app is removed unless the document lists it. Tags never change what the mock answers. |
Responses
Each item of a mock’s responses.
| Field | Type | Meaning |
|---|---|---|
key (required) | string | The response’s identity within the mock, such as not-found: lowercase letters, digits, _ and -, up to 64. A selection refers to a response by it. Keys that start with oa- come from an OpenAPI import: keep them as exported. |
name (required) | string, at least 1 characters, at most 255 characters | What the response is called in the app and in request logs. |
response (required) | object | What the response answers: statusCode, headers, body, and optionally a delay, or a stream that sends the body in paced chunks. In place of a body, ai answers as a model provider's API. See Build the response, Stream a response and Mock an LLM API. |
Default selection
A responseSelection with mode default: one response answers every request, unless a request asks for another.
| Field | Type | Meaning |
|---|---|---|
mode (required) | "default" | Always default here. |
defaultResponseKey (required) | string | The key of the response that answers, which the mock must list. |
allowRequestOverride | boolean Default: true | Whether a request may send X-MockHub-Response to be answered by another response of the mock. Off, such a request is refused. See Choose the response that answers. |
Sequence selection
A responseSelection with mode sequence: the responses answer in turn. See Return a sequence of responses.
| Field | Type | Meaning |
|---|---|---|
mode (required) | "sequence" | Always sequence here. |
steps (required) | list of string, at least 2 item | The response keys in the order they answer, from 2 to 10. A key may appear more than once. |
onEnd | "repeat", "stick"Default: "repeat" | What follows the last step: repeat starts over from the first, stick keeps answering with the last. |
Rules selection
A responseSelection with mode rules: the first rule whose conditions hold answers, and the default answers every other request. See Answer by rule.
| Field | Type | Meaning |
|---|---|---|
mode (required) | "rules" | Always rules here. |
rules (required) | list of response rule, at least 1 item | The rules, from 1 to 20, in the order they are tried. |
defaultResponseKey (required) | string | The key of the response that answers a request no rule holds for, which the mock must list. |
allowRequestOverride | boolean Default: true | Whether a request may send X-MockHub-Response to be answered by another response of the mock before any rule is tried. Off, such a request is refused. |
Response rule
Each item of a rules selection’s rules.
| Field | Type | Meaning |
|---|---|---|
when (required) | object | The conditions that must all hold, from 1 to 10: queryParameters, headers, pathParameters, cookies and formParameters map names to matchers, each counting one, and bodyPatterns is one matcher or a list, JSON kinds included, as in the mock’s request. pathParameters needs a urlPathTemplate in the request that declares each name. See Request matchers. |
responseKey (required) | string | The key of the response that answers when the rule holds, which the mock must list. |
Data store
The store of a mock. It has a condition, a write, or both.
| Field | Type | Meaning |
|---|---|---|
condition | object | Match only while a record exists: collection, key (see Data store key), and exists, false to match only while it does not. |
write | object | Change the store once the mock has answered: op (put, delete or clear), collection, key except for clear, and for put the value to save, responseBody or requestBody. |
Data store key
Where a condition or a write reads the record key. A condition cannot read responseBody.
| Field | Type | Meaning |
|---|---|---|
from (required) | "path", "pathParameter", "query", "header", "requestBody", "responseBody" | Where the key comes from. |
segment | integer, from 0, up to 31 | With path: the path segment, counted from 0, so in /users/42 segment 1 is 42. |
name | string, at least 1 characters, at most 128 characters | With query or header: the parameter or header name. |
jsonPath | string, at most 256 characters | With requestBody or responseBody: a JSONPath of .name, [n] and ['name'] steps, such as $.id. |
OpenAPI contract
The openapi of the document. Applying a changed document makes it the next revision, as an import does, without changing any mock. See OpenAPI contracts.
| Field | Type | Meaning |
|---|---|---|
document (required) | string, at least 1 characters | The whole OpenAPI document as one JSON string, exactly as exported. It is checked as an import checks it, against the plan's document size and number of operations. |
dynamicValues | object | The contract's dynamic values, exported only when there are some: one choice per schema field, keyed by its place in the document, and the optional pathEcho rule for generated responses. Keep it as exported. Applying it stores the choices without changing any mock, whose bodies come from mocks; leaving it out removes them. A choice is used only where it still fits its field's schema. See Vary generated response values. |
importOptions | object | How the contract's operations are served: basePath serves every operation under that path instead of its server's. |
Operation
A mock's openapiOperation.
| Field | Type | Meaning |
|---|---|---|
method (required) | string, at least 1 characters, at most 64 characters | The operation's HTTP method, such as GET. |
path (required) | string, at most 2048 characters | The operation's path, such as /orders/{id}. Parameter names do not matter. |
detached | true | true keeps a link to an operation the contract no longer has, as an update that removes an operation leaves it. Without it, the operation must be in the contract. |
Import provenance
A mock's openapiGeneration. It is comparison data rather than settings: keep it as exported, and remove the whole field to make the next import treat the mock as your own.
| Field | Type | Meaning |
|---|---|---|
origin (required) | object | The operation the mock was generated from, with its base path and the compiler version. |
baseline (required) | string | The fields the mock’s responses share that the import generated, as JSON text: its name, request, response templating and default response. |
sourceDigest (required) | string | A fingerprint of the contract revision it came from. |
importerVersion (required) | integer, from 1 | The importer that generated it. |
responses | object | The same comparison data for each imported response, by response key. A response with no entry is your own and an import never changes it. See Response import provenance. |
Response import provenance
An entry of openapiGeneration.responses. Like the mock’s own, it is comparison data: keep it as exported.
| Field | Type | Meaning |
|---|---|---|
origin (required) | object | The contract response, media type and example the response was generated from, and its status code. |
baseline (required) | string | The response the import generated, as JSON text: name, status, headers and body. |
sourceDigest (required) | string | A fingerprint of the contract revision it came from. |
importerVersion (required) | integer, from 1 | The importer that generated it. |
absentFromSource | boolean Default: false | true when a later contract no longer offers this response and the import kept it anyway. |
Chaos profiles
Each item of chaosProfiles. A profile has at least one of latency, errorInjection and fault. See Create a chaos profile for what each does.
| Field | Type | Meaning |
|---|---|---|
name (required) | string, at least 1 characters, at most 255 characters | Unique in the project. |
latency | object | A delay added to every response, in the same form as a mock delay. |
errorInjection | object | Answer with an error instead of the mock, some of the time: rate (0 to 1), statusCode, and optionally body and headers. |
fault | object | Break the connection instead of answering, some of the time: rate (0 to 1) and type. Callers receive 502. |
endpointPattern | string | A regular expression such as ^/orders: only mocks whose URL it matches are affected. Left out, every mock is. |
Webhooks
Each item of webhooks. A webhook fires when its trigger mock answers, on its schedule, or when you send a test. Signing secrets are never part of the document.
| Field | Type | Meaning |
|---|---|---|
name (required) | string, at least 1 characters, at most 255 characters | Unique in the project. |
targetUrl (required) | string | Where the webhook is sent: a public address, or exactly one request placeholder such as {{request.body.callback_url}} to send it to the address the triggering request gives, which needs targetHosts. |
method | "POST", "PUT", "PATCH"Default: "POST" | The HTTP method of the request. |
contentType | string Default: "application/json" | The Content-Type of the request. |
headers | object | Extra request headers. See Headers for the reserved names and how an exported value reads. |
bodyTemplate | string | The request body, with {{placeholder}} substitution, including what the mock answered when triggerMock is set. An unknown placeholder is refused. See Send webhooks from a project. |
enabled | boolean Default: true | Whether the webhook fires. |
triggerMock | string, at least 1 characters, at most 255 characters | The name of a mock in this document; the webhook fires each time it answers. |
triggerDelaySeconds | integer, from 0, up to 900 Default: 0 | How long after the trigger mock answers the webhook is sent. |
scheduleIntervalMinutes | integer, from 1, up to 1440 | Send the webhook on a fixed interval, in minutes. Not together with scheduleCron. |
scheduleCron | string, at most 128 characters | Send the webhook on a five-field cron expression, such as 0 9 * * 1-5, or one of @hourly, @daily, @weekly, @monthly, @yearly. Not together with scheduleIntervalMinutes. |
scheduleTimeZone | string, at most 64 characters | The time zone the cron expression is read in, such as Europe/Warsaw. UTC when absent; needs scheduleCron. |
targetHosts | list of string, at least 1 item | The hosts a request-given address may name, 1 to 20: an exact host, .example.com for its subdomains, or a name MockHub allows. Needs triggerMock, not together with a schedule, and only with a request placeholder as targetUrl. |