Validate the API response
Click here to get the flow definition for this tutorial..
Click here to get the schema definition for this tutorial..
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
- Navigate to the Schemas page and click New schema.
- Paste the provided schema definition into the editor.
- 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:
- Navigate to previously created
GET /transformUser
operation. - Select the
transformUserResponse
for the Response schema and save the API.
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.
// Code: 200
{ "fullName": "Joe Test", "requestTime": "2023-07-06T06:20:16.735Z", "name": "Joe", "surname": "Test" }
// Code: 500
{ "statusCode": 500, "message": "Error in flow 'transformUser' : Request Schema validation error" }
// Code: 500
{ "statusCode": 500, "message": "Error in flow 'transformUser' : Request Schema validation error" }