Responses
How the mock answers a request: where the paths are served, which status, body and headers it picks, how a request asks for a particular answer, and how the network is made slow or unreliable on purpose. How the mock picks a response walks through these rules with a document to try them on.
- Routing. Paths are served under the path of the document’s first server (
/v1forhttps://api.example.com/v1) and as they are. Literal paths win over templated ones (/pets/mineover/pets/{id}). An unknown path is answered with 404, an unknown method with 405 and anAllowheader, both as problem details. OpenAPI 3.2’squerymethod and the methods ofadditionalOperations(COPY, …) are routed like the others. - Status. The lowest 2xx response, else
2XX, else the lowest declared, elsedefault. - Body. Content negotiation follows
Accept(406 when nothing fits). Without anAccept, or with*/*, the response takes the media type of the request’s body when it has it: a SOAP 1.2 request (application/soap+xml) to an operation answering both SOAP versions gets a SOAP 1.2 envelope. In the default static mode the media type’sexample, its first named example, or the schema’s example answer; what has none is generated from the schema. Generated values respect types, the formats of the OpenAPI format registry (uuid,date-time,int8,decimal,http-date, …; see Formats), patterns, lengths, ranges,enum,const,allOf,oneOf,readOnlyandwriteOnly. A value forapplication/xml,text/xmlor a+xmltype is written as XML (see XML bodies); a string example is sent as it is. - Headers. Response headers are filled in from their examples or schemas.
X-Apigenie-Mock-OperationandX-Apigenie-Mock-Source(example:cat,generated,scenario:outage,stub:getPet-1) say where a response came from. - Stubs.
--stubs DIR(orstubs:in the configuration) answers with recorded exchanges (see Record and replay) before the document’s examples: a request’sPreferand the rules of scenarios and overrides still come first.
Choosing a response per request
The Prefer header (or query parameters, which are removed before validation) asks for a
particular answer:
Prefer |
Query | Effect |
|---|---|---|
code=404 |
__code=404 |
That status (500 when the operation doesn’t declare it). |
example=cat |
__example=cat |
That named example. |
dynamic=true |
__dynamic=true |
A generated body. |
delay=1500 |
__delay=1500 |
Answer after 1.5 seconds. |
drop=reset |
Reset the connection (close, timeout and truncate too). |
|
scenario=outage |
Apply that scenario to this request. |
Network simulation
Latency (fixed, uniform, normal or log-normal), jitter, dropped connections (reset, closed without an answer, never answered, or truncated bodies) and bandwidth limits apply to every response, an operation’s, a scenario’s or one request’s.