Vary generated response values
Before you begin
- Plan
- Included in Free, Pro and Team. How plans and limits work
- Role
- Viewer or higher to see the stored choices and Editor or higher to vary, undo or clear values.
- You need
- A project with an OpenAPI contract, and mocks imported from responses generated from the schema
- Response templating on for the project
Turn the fixed sample values of responses generated from a schema into dynamic values, so a client sees a different genre, rating or creation date on each request while the response keeps its structure and stays within the specification.
A dynamic value is a template helper expression, such as {{ randomInt lower=1 upper=6 }}, so the project’s response templating must be on. This action never turns it on: an Admin does that in the project’s Settings, which also changes how every other mock’s response is read.
-
Open the project’s OpenAPI tab and select Vary response values under This project’s contract. After an import that generated responses, the result offers Vary response values too.
-
Under How should values be chosen?, keep Automatically. The dialog reviews what would change: Fields to vary, Stay fixed, Responses to change and Kept as they are. Open Responses that change and Fields that stay fixed, and why to read the lists.
-
Keep Return values from the request path selected to echo eligible fields. Once the contract stores values, the box starts as you last left it. The preview says how many mocks return their path values. A field that only ever returns its path value is not counted in Fields to vary. Clear the box to use each field’s ordinary choice or fixed sample instead, then read the updated review.
-
Select the button that names how many responses change, such as Apply to 14 responses; Responses to change says how many of them are active, and so answer live requests at once. The dialog shows Checking samples against the specification… and then the result.
-
To vary plain text and unbounded numbers too, such as a book’s title or a page count, select Automatically, and AI for the rest, read the scope again, and apply. AI picks what kind of value each of those fields gets, and a new one is still drawn on every request. It spends 5 AI credits when you apply, as one AI generation, if there is something to ask, and none per request; the dialog shows how many are left. With fewer than 5 left, it cannot run until they reset.
Result
Section titled “Result”The dialog says how many responses were updated, such as 4 response(s) updated; 2 field(s) kept fixed to satisfy the specification, and links each one. Open one and use Try it in the mock editor to see a sample; each request draws new values. If the dialog says The responses are saved, but not live yet: the old ones may answer for a moment., the change is made and goes live by itself.
What varies
Section titled “What varies”Outside a path echo, a value is chosen once for each field of the contract: every generated response that shares a schema, such as Book in GET /books and GET /books/{bookId}, varies it the same way.
| The field | Varies with | Decided by |
|---|---|---|
An enum of two or more members |
A member each time | Automatically, no AI usage |
| A boolean | true or false |
Automatically |
An integer or number with a minimum and maximum |
A number within them | Automatically |
A uuid, email or ipv4 (or ip) string |
A new identifier or address | Automatically |
A date, date-time or date-time-rfc-2822 string |
The current date or time, in UTC | Automatically |
An integer with format: unix-time, unixtime or timestamp and no bounds |
The current time, in seconds since the epoch | Automatically |
A string with a pattern and no format |
One of a few samples that match it | Automatically |
| Plain text, or a number without bounds | Realistic alternatives or a fake data value | Automatically, and AI for the rest |
Outside a path echo, a property example or default stays as written; a const always stays fixed, and a mock you imported from an example is never changed.
Every choice, whether MockHub or AI made it, is checked against every keyword at each place the field is used. Before anything is saved, the changed responses are rendered and the rendered JSON is checked against the operation’s schema; a choice that breaks it is dropped and the field stays fixed.
Return a value from the path
Section titled “Return a value from the path”With Return values from the request path selected, GET /orders/42 can return "id": 42. The rule applies to generated responses throughout the contract and spends no AI credits. The property’s ordinary choice still applies in a list response, where there is no matching top-level path field.
A top-level field matches a path parameter by name, ignoring case, underscores and hyphens: user_id matches {user-id}. A field named id matches the whole parameter in the last segment instead, such as {orderId} in /users/{id}/orders/{orderId}, so an order’s id is the order’s and not the user’s. The mock must still use the generated path template. Nested fields, ambiguous names and values tied to other fields stay with their ordinary choices.
The field must be an unconstrained string, a uuid string or an integer with no bounds or multipleOf. A pattern, length bound, enum, other format or an implicit integer range such as int32 prevents an echo. The path value is percent decoded before it is used, and a + stays a plus. An integer accepts at most 18 digits and an optional minus, without leading zeroes; a UUID must have its hexadecimal 8-4-4-4-12 shape. An unsuitable or absent value uses the generated sample: /orders/abc still returns a valid integer sample. Strings are quoted and escaped as JSON.
A field that matches by name but has one of those constraints keeps its ordinary choice or sample. The review lists it under fields named after a path parameter keep their own values; it is not counted among the fields that stay fixed.
An echo overrides that property’s stored choice only in the eligible response. Clearing the checkbox restores the ordinary choices, Use fixed values everywhere removes the rule, and Undo this batch restores it with the rest of the batch.
Fields that stay fixed
Section titled “Fields that stay fixed”Fields that stay fixed, and why lists each field by its place in the document, such as /components/schemas/Book/properties/isbn, with one of these reasons:
| Reason | Why |
|---|---|
unsupported |
No helper can vary it within its schema, such as a multipleOf number, a number bounded on one side only, or a string with another format. |
unique-items |
It is an item of a uniqueItems array: varied apart, two items could become equal. |
one-of |
It sits under a oneOf with more than one branch besides null: a varied value could match two branches. |
discriminator |
It is the property a discriminator reads, so its value names the schema. |
conditional |
It sits under not, if, then, else, dependentSchemas or contains, which relate it to other values. |
incompatible-use |
The field’s choice fits its other uses but not this one, where the document adds a keyword such as a smaller maximum. This use stays fixed and the others keep the choice. |
render-failed |
A response holding the choice did not render, or rendered JSON that broke its schema. |
model-…, or another reason |
The model skipped the field, kept it fixed, answered it twice or in a shape that cannot be used, or its choice broke the schema, such as options-outside-schema. It is not asked again unless you choose again for it. |
Which responses change
Section titled “Which responses change”- Only responses generated from the schema, and only those nobody changed. A mock whose body or response templating was edited since the import is kept, and listed kept your edits; a mock that answers with a response sequence is kept too. Other changes, such as its request rule or delay, are kept on the mocks that change.
- An active response that could not be rendered is left as it is, listed was not rendered. An inactive one is saved unchecked. A run renders up to 20 responses within 10 seconds; select Apply again for the rest.
- At most 200 fields are decided in one run, the most used first. Fields to vary says how many more are left for the next run.
Once some values are stored, the dialog offers Choose again for fields decided before, which replaces those earlier choices with the chosen method. Left unticked, a run decides only fields without a choice and leaves the rest as they are.
If the contract, a mock, the project’s templating or the stored choices change between the review and Apply, nothing is saved and the dialog says Nothing changed. The scope was reviewed again below. Read it and apply again.
Undo the latest batch
Section titled “Undo the latest batch”Select Undo this batch and confirm. It restores the responses and stored choices the latest run changed, and the dialog says, for example, Undone: 4 response(s) and 3 stored choice(s) restored. Only the latest batch can be undone, once. It is refused, with the reason beside the button, after the contract is updated, templating is switched, a value it chose is changed, or a mock it updated is edited or deleted. A batch too large to keep cannot be undone at all.
Return to fixed values
Section titled “Return to fixed values”Select Use fixed values everywhere and confirm. Every generated response returns to its sample, for the whole contract, with response templating off for the mock; responses you edited are kept. It needs neither templating nor a plan with OpenAPI, so it works after a downgrade.
Limits
Section titled “Limits”- Values vary only in JSON responses generated from a schema. A mock imported from an example, or written by hand, is never changed.
- A choice is checked against the schema and samples are rendered once; nothing proves every future answer is valid. When a later import checks the responses it would write, a mock holding dynamic values is reported incomplete, however many rendered samples passed.
- If response templating is turned off later, the mocks send their expressions as text, and the next import writes them again from the stored choices. Return to fixed values first.
- A later import reuses each stored choice where it still fits the field’s schema. A choice that no longer fits stays stored and the field stays fixed until it fits again or you choose again for it.
- The stored choices and path-echo rule travel with the project’s configuration document under
openapi.dynamicValues. - The automatic values come from MockHub’s own rules, not from what a field means; only Automatically, and AI for the rest reads the field’s name and description. The plan sets how many AI credits a workspace can spend per day and per month; see the limits page.