validate - DataPower API Gateway
Use the validate policy to validate the payload in an assembly flow against a schema.
Gateway support
Note: This page describes the validate policy implementation
in the DataPower® API
Gateway. If you
are using the DataPower Gateway (v5
compatible),
see validate - DataPower Gateway (v5 compatible).
For information on the different types of gateway, see API Connect gateway types.
| Gateway | Policy version |
|---|---|
| DataPower API Gateway, policy available from V2018.4.1.0 | 2.0.0 |
This topic describes how to configure the policy in your OpenAPI source; for details on how to configure the policy in the assembly user interface, see Validate - DataPower API Gateway.
About
The validate policy has
the following
format:
- validate:
version: version
title: title
description: description
validate-against: validation_mechanism
.
.
.
properties_specific_to_the specified_validation_mechanism
.
.
.Apply this policy by adding an assembly extension with an execute field to your OpenAPI definition file.
Note: With the DataPower API
Gateway, the input to the validate policy must be parsed data. One way to produce parsed data is to use a
parse policy before a validate policy in your
assembly flow, which provides explicit control of the parse action.Properties
The following table describes the policy properties:
| Property | Required | Description | Data type |
|---|---|---|---|
| version | Yes | The policy version number | string |
| title | No | A title for the policy. | string |
| description | No | A policy description. | string |
| input | No | Identifies a variable in the API context. The content of the body field of
the variable, which is represented by variable_name.body, is the
input data to validate. By default, the variable name is message. |
string |
| output | No | Specifies the name of a variable in the API context.
|
string |
| validate-against | Yes | Specifies the schema to be used for validating the payload. Valid values:
|
string |
You can also apply a validate policy by using the API Manager assembly editor to add a built-in policy to the API. For more information, see Validate - DataPower API Gateway in the built-in policies section.
Example 1
- validate:
version: 2.0.0
title: 'validate, response parameter schema'
validate-against: response-param
Example 2
- validate:
version: 2.0.0
title: 'validate, predefined schema'
validate-against: definition
definition: '#/definitions/RouteOutput'
Example 3
- validate:
version: 2.0.0
title: 'validate, JSON and XML schema URLs'
validate-against: url
json-schema: 'https://my.json.schema'
xml-validation-mode: xsd
xml-schema: 'https://my.xml.schema'