set-variable
Use the set-variable policy to set the value of a runtime variable, or to add or clear a runtime variable.
Gateway support
Gateway | Policy version |
---|---|
DataPower® Gateway (v5 compatible) | 1.0.0 |
DataPower API Gateway | 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 Set Variable.
About
The set-variable policy has the following
format:
- set-variable:
version: version
title: title
description: description
actions:
- action_type: variable_name
value: value
type: data_type
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 |
actions | Yes | Lists the actions to be performed by the set-variable policy. | array |
set | Yes1 | For setting a variable. specifies the name of the variable that you want to
set. 1One of the properties set, add, or clear is required. |
string |
add | Yes2 | For adding a variable. specifies the name of the variable that you want to
add. 2One of the properties set, add, or clear is required. |
string |
clear | Yes3 | For clearing a variable. specifies the name of the variable that you want to
clear. 3One of the properties set, add, or clear is required. |
string |
value | Yes4 | Allocates this value to the specified variable. Can be a literal value, or another
variable. 4value is required only when |
string |
type | Yes | Specifies the data type of the variable. Valid values:
For all values other than If the data type is specified as |
string |
Example 1
# clear a variable
set-variable:
version: 1.0.0
title: clear_region
actions:
- clear: message.headers.region
Example 2
# set a variable to the value of an API Gateway context variable
set-variable:
version: 2.0.0
title: set content type
actions:
- set: message.headers.contenttype
value: $(message.headers.content-type)
type: string
Example 3
# add a variable
assembly:
execute:
- set-variable:
version: 2.0.0
title: set-variable
actions:
- value: testing add
add: message.headers.jja
type: string