Use the switch component to execute one of a number of sections of the assembly based on which specified condition is fulfilled.
|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 switch.
The switch policy has the following format:
- switch: version: version title: switch description: 'Description' case: - condition: Script_1 execute: Assembly_Section_1 - condition: Script_2 execute: Assembly_Section_2 - otherwise: Assembly_Section_3
execute: section can define any policy assembly, including further switch
policies. For more information, see execute.
|version||Yes||The policy version number||string|
|title||No||A title for the policy.||string|
|description||No||A policy description.||string|
|case||Yes||Contains the condition and execute pairs of the switch policy.||string|
|condition||Yes (one or more)||A script that returns
Use the JSONata expression language to define your condition. See Writing switch condition scripts - DataPower API Gateway
Use GatewayScript to define your condition. See Writing switch condition scripts - DataPower Gateway (v5 compatible).
|execute||Yes (one per condition)||The policy assembly that you want to execute if the condition returns
|otherwise||No||The case you want to execute if no other cases are fulfilled. It functions in the same manner as an execute property. For more information, see execute.||string|
For examples, see one or other of the following topics, depending on which gateway type you are using: