Response generation with API mocks
API mocks respond as realistically as possible to any calls they receive. When generating a response body, a mock will give priority to user-provided data by looking for an example field, then a default value, then an enum field. If one is found, it will be used as an example, otherwise a JSON example will be generated based on the data type returned by the operation being called.
As an example, consider the Company data type definition shown below. It does not contain any user-provided examples.
When mocking is activated, a GET call made to the /company/{companyId} resource will return an automatically generated JSON response based on the structure of the data type, as shown below using Talend Cloud API Tester.
The mock has done a number of interesting things, including generating values for custom response headers (e.g. x-my-custom-header), identifying arrays and creating appropriate examples (e.g. tags property), and also identifying nested structures and generating values for those too (e.g. address property).
Talend Cloud API Designer mocks support content negotiation, so you can use the Accept request header to select which body should be returned among several options (each potentially has its own example), therefore changing the examples returned by the mock.