How mockResponseForOperation() resolves data
mainThe mockResponseForOperation(operationId) method resolves data based on your OpenAPI specification in the following priority:
- OpenAPI
exampleobjects: If the response content contains anexamplefield, that object is returned. - JSON Schema: If no example is present, it uses the
schemadefinition to generate a mock object.
Example OpenAPI structure supported:
paths:
'/pets':
get:
operationId: getPets
responses:
200:
content:
'application/json':
example:
- id: 1
name: Garfield
'/pets/{id}':
get:
operationId: getPetById
responses:
200:
content:
'application/json':
schema:
type: object
properties:
id: { type: integer }
name: { type: string, example: Garfield }