Skip to main content
Version: ACE 5

Validate the API response

Flow definition

Click here to get the flow definition for this tutorial..

Schema definition

For data integrity the response has to be validated.

Validation allows verifying that the response matches the API definition. It also helps to catch any unintended changes in the flow that could cause an incorrect response to be returned.

What is a schema?

Schemas in the context of APIs are JSON objects that conform to either the OpenAPI or JSON Schema specification. In ACE you will find schemas being used for defining data structures.

Importing the schema

  1. Navigate to the Schemas page and click New schema.
  2. Paste the provided schema definition into the editor.
  3. Name the schema transformUserResponse and save it.

Reading the schema

It is recommended to familiarize yourself with the JSON Schema format. The given schema validates the following:

  • Fields - fullName, name, surname, requestTime - exist in the response.
  • There are no additional fields.
  • All fields are strings.
  • The fullName field has a length restriction between 5 and 100 characters and has a pattern that only permits characters and spaces.

Attaching response schema

To attach the schema:

  1. Navigate to previously created GET /transformUser operation.
  2. Select the transformUserResponse for the Response schema and save the API.
Attached schema

Response schema

Enabling response validation

To enable response validation:

  • Navigate to the /transformUser flow and attach a Response Validation step at the very end of the flow and save it.
  • Alternatively you can import the flow attached to this tutorial.

Testing response validation

Now it is certain that the data being generated by the flow matches a certain structure. Any bad data generated by the flow is caught and returned as an error response.

GET /transformUser?name=Joe&surname=Test
// Code: 200
{ "fullName": "Joe Test", "requestTime": "2023-07-06T06:20:16.735Z", "name": "Joe", "surname": "Test" }
GET /transformUser?name=Jo&surname=S (fullName too short)
// Code: 500
{ "statusCode": 500, "message": "Error in flow 'transformUser' : Request Schema validation error" }
GET /transformUser?name=Jo3&surname=T3st (fullName contains numbers)
// Code: 500
{ "statusCode": 500, "message": "Error in flow 'transformUser' : Request Schema validation error" }