Skip to main content
Version: ACE 4

Request Validation

Overview

Request validation allows verifying if data passed to API is according to the schema that has been defined in API (or default schema if schema is not provided in API definition). This is useful when you want to make sure that the request data (body, headers, query params and path params) is the same as defined in the API definition so to ensure the integrity of data for the end client and elimination of errors that might occur if the request data wouldn't meet the expectations.

Configuration

  • Request schema - schema definition for the doc node.
    • Requires schema to be set up first in ACE's schemas section. Afterwards the needed schema has to be selected under this selector. This is the default schema that will be used if dynamic API request associated with the flow has not a schema defined (and is also useful for testing the flow with debugger or test tool).
  • Add header parameters to doc - add defined header parameters to the doc object.
  • Convert request parameters (in doc) to schema types - converts request parameters (in doc) to the corresponding types defined in the schema.
  • throw as error - if checked(default), failed schema validation will throw an error.
  • target path - doc node on which to store the validation result when throw as error unchecked(empty array if successful, error object if failed).

Examples

Example schema
{
"title": "loginRequestSchema",
"nodeKey": "loginRequestSchema",
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
}
},
"type": "object",
"required": ["username", "password"]
}
Step configuration
{
"stepType": "request-validation",
"color": "rgb(247,225,211)",
"displayName": "Request Validation",
"isSelected": true,
"config": {
"defaultSchema": "loginRequestSchema"
}
}
Example flow with valid input data
{
"id": "31dc4380-96eb-4e92-bfa5-131614c87ab9",
"name": "loginRequest",
"flow": {
"name": "loginRequest",
"description": "",
"steps": [
{
"stepType": "request-validation",
"color": "rgb(247,225,211)",
"displayName": "Request Validation",
"isSelected": false,
"config": {
"defaultSchema": "loginRequestSchema"
},
"textColor": "red"
},
{
"stepType": "jsonata",
"color": "rgb(245,210,211)",
"displayName": "JSONATA Map",
"isSelected": true,
"config": {
"maps": [
{
"mergeArrayItems": {},
"jsonata": "['data']",
"targetPath": "result"
}
]
},
"textColor": "black"
}
]
},
"inputSchema": {
"username": "testUser",
"password": "test Pass"
},
"createDate": "2022-09-27T06:23:40.159Z",
"tags": ["general"],
"inputSchemaLabel": "loginRequestSchema",
"version": 1
}
Flow result
{
"doc": {
"username": "testUser",
"password": "test Pass",
"result": ["data"]
},
"errors": [],
"performance": {
"steps": [
{
"step": "request-validation",
"executionTime": 27
},
{
"step": "jsonata",
"executionTime": 0
}
],
"executionTimeOfFlow": 32,
"timeMetric": "ms"
}
}
Example flow with invalid ( password not passed ) input data
{
"flow": {
"name": "loginRequestInvalid",
"description": "",
"steps": [
{
"stepType": "request-validation",
"color": "rgb(247,225,211)",
"displayName": "Request Validation",
"isSelected": false,
"config": {
"defaultSchema": "loginRequestSchema"
},
"textColor": "red"
},
{
"stepType": "jsonata",
"color": "rgb(245,210,211)",
"displayName": "JSONATA Map",
"isSelected": true,
"config": {
"maps": [
{
"mergeArrayItems": {},
"jsonata": "['data']",
"targetPath": "result"
}
]
},
"textColor": "black"
}
]
},
"tags": ["general"],
"inputSchema": {
"username": "testUser"
},
"inputSchemaLabel": "loginRequestSchema",
"version": 1,
"id": "e4b5047b-1911-4cf5-9a95-a2c564e85383"
}
Flow result
{
"doc": {
"username": "testUser",
"result": ["data"]
},
"errors": [
{
"error": "Error in flow 'loginRequestInvalid' : Request Schema validation error",
"validationErrors": [
{
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params": {
"missingProperty": "password"
},
"message": "should have required property 'password'"
}
]
}
],
"performance": {
"steps": [
{
"step": "request-validation",
"executionTime": 14
},
{
"step": "jsonata",
"executionTime": 1
}
],
"executionTimeOfFlow": 16,
"timeMetric": "ms"
}
}
Example flow with invalid ( password not passed ) input data and throw as error unchecked
{
"flow": {
"name": "loginRequestInvalidThrowUnchecked",
"description": "",
"steps": [
{
"stepType": "request-validation",
"color": "rgb(247,225,211)",
"displayName": "Request Validation",
"isSelected": true,
"config": {
"throwAsError": false,
"defaultSchema": "loginRequestSchema",
"targetPath": "validations"
},
"textColor": "black"
},
{
"stepType": "jsonata",
"color": "rgb(245,210,211)",
"displayName": "JSONATA Map",
"isSelected": false,
"config": {
"maps": [
{
"mergeArrayItems": {},
"jsonata": "['data']",
"targetPath": "result"
}
]
},
"textColor": "black"
}
]
},
"tags": ["general"],
"inputSchema": {
"username": "testUser"
},
"inputSchemaLabel": "loginRequestSchema",
"version": 1,
"id": "417fb38c-22fa-49f7-ae24-b381d5620ae8"
}
Flow result
{
"doc": {
"username": "testUser",
"validations": [
{
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params": {
"missingProperty": "password"
},
"message": "should have required property 'password'"
}
],
"result": ["data"]
},
"errors": [],
"performance": {
"steps": [
{
"step": "request-validation",
"executionTime": 12
},
{
"step": "jsonata",
"executionTime": 0
}
],
"executionTimeOfFlow": 16,
"timeMetric": "ms"
}
}

Testing with API

Example with GET api

The data passed in query params, headers and path params are also considered in request data and used for validation by this step. Below is an example API.

Since Request body schema is not available on the GET apis the step configuration must have default schema selected in the flow. The default schema can be specified as an empty schema (e.g. { "type": "object", "properties": {} }). The query and path parameters will be validated against their definition in the API.

Logical

In this api username is passed in header and the password is passed in query param. Below is an example response:

Logical

Example with POST api

The data passed in request body is used for validation by this step. Apart from data in body the data in query params, headers and path params are also considered for POST.

We have defined the schema on the api under Request body schema this overrides the default schema defined in the step configuration of flow.

This is applicable to other methods as well like PUT, PATCH etc.

Below is an example API

Logical

In this api username and the password is passed in request body. Below is an example response:

Logical