Refuse invalid requests in a preview environment
Before you begin
- Plan
- Included in Pro and Team. How plans and limits work
- Role
- Admin or higher.
- You need
- An ephemeral preview environment in mock mode
- An OpenAPI contract with a revision to enforce
Make a preview environment refuse a request that breaks its contract, so a client under test learns at once that it sends something the API does not accept, instead of a mock answering it anyway.
-
Open the environment’s OpenAPI tab.
-
In Request checks, choose Reject under Mode. If it is not offered, the line beneath says why.
-
Choose the revision under Revision, such as Revision 2 (active).
-
If Reject lists operations it cannot decide, add the others under Operations. See Choose which operations are enforced.
-
Select Save request checks.
Result
Section titled “Result”A request that breaks the pinned revision is answered 422 with Request contract invalid and its findings. A request MockHub cannot decide is answered 503 with Request contract unverified. Either way no mock, scenario, data store write, callback or upstream sees the request, the refusal is kept in the request logs with its check, and it counts against the request quota.
What Reject needs
Section titled “What Reject needs”| Condition | When it is not met |
|---|---|
| A plan that refuses requests | Reject is not part of this plan. |
| An ephemeral environment | Reject is only for ephemeral (preview) projects. |
| Answering from mocks only | Reject needs the project to answer from its mocks only, without forwarding. |
| A revision small enough for the gateway to check | Reject cannot use this revision: it is larger than the gateway checks against. |
A permanent project, or one that forwards to an upstream, cannot reject: nothing could send a refused request anywhere else.
Choose which operations are enforced
Section titled “Choose which operations are enforced”Some operations cannot be decided by a check, such as one with an OpenAPI 3.2 querystring parameter that is not form-encoded, an array in a cookie, a form-style object parameter, a parameter described by a media type other than JSON, a form body with an object property that is not a one-level deepObject, a deepObject whose keys are not each a plain value or are described by allOf, anyOf, oneOf or patternProperties, or a body that is none of JSON, a single plain-text value, form-data parts or a form. With Reject chosen, the panel lists them, and Save request checks stays unavailable while any of them is enforced. Add the operations you want enforced under Operations; the others are served without a check.
The list is cautious. A request can still be undecidable for a reason only it shows, and is then answered 503.
It never opens by itself
Section titled “It never opens by itself”An environment set to refuse never serves a request it has not checked. If the plan stops including it, or the pinned revision is removed, it answers 503 with the reason request-enforcement-unavailable until you set the mode to Off or Report. You cannot delete the contract while the mode is Reject: set Off first.
Limits
Section titled “Limits”- A preflight request and a post to the inbox are never refused.
- A refusal says nothing about authentication.
- It does not change a mock’s own matching: a request that passes is served as before.