Request validation
A spec-based mock server checks every request against the document before answering, so integration mistakes surface while you develop, not when the real API arrives. There are three checks, and all three start on.
| Check | What it verifies | On failure |
|---|---|---|
parameters | Required path, query, header and cookie parameters, and their schemas | 422 invalid-request |
body | The request body against the schema of its media type | 422 invalid-request |
credentials | The credentials the operation’s security requires are present | 401 missing-credentials |
A failed 422 lists each problem:
{
"type": "https://apigit.com/mock/problems/invalid-request",
"title": "The request does not match the API description",
"status": 422,
"detail": "The request does not match getPetById: path petId: must be integer",
"errors": [{ "in": "path", "name": "petId", "message": "must be integer" }]
}Credentials are checked for presence only
The credentials check looks for the kind of credential the document declares: an API key in its header, query parameter or cookie, HTTP bearer or basic authorization, or an OAuth2 or OpenID Connect bearer token. Any value is accepted, so you can use placeholders.
This is separate from the mock server’s own access token. The access token is enforced first and decides who may reach the mock at all. The credentials check simulates your API’s security.
Turn checks off for a document
Open the mock server, choose Setting, and use the Validate switches of each document under Documents & Base Paths. Each of the three checks has its own switch, and a change applies after Save documents, without a republish.
Turn checks off for one request
Use the Prefer header:
# skip every check
curl https://petstore-sandbox.mockserver.apigit.com/api/v3/pet/abc \
-H 'Prefer: validate=false'
# run only the body check
curl -X POST https://petstore-sandbox.mockserver.apigit.com/api/v3/pet \
-H 'Content-Type: application/json' -H 'Prefer: validate=body' -d '{"name":"doggie","photoUrls":[]}'
# run only the named checks
curl https://petstore-sandbox.mockserver.apigit.com/api/v3/pet/1 \
-H 'api_key: anything' -H 'Prefer: validate=parameters,credentials'A check that is switched off is skipped, not reported: the request gets the normal response.