switch

Use the switch component to execute one of a number of sections of the assembly based on which specified condition is fulfilled.

Gateway support

Table 1. Table showing which gateways support this policy, and the corresponding policy version
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 switch.

About

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

The execute: section can define any policy assembly, including further switch policies. For more information, see execute.

Properties

Table 2. switch 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
case Yes Contains the condition and execute pairs of the switch policy. string
condition Yes (one or more) A script that returns true or false.

DataPower API
GatewayUse the JSONata expression language to define your condition. See Writing switch condition scripts - DataPower API Gateway

DataPower
GatewayUse GatewayScript to define your condition. See Writing switch condition scripts - DataPower Gateway (v5 compatible).

string
execute Yes (one per condition) The policy assembly that you want to execute if the condition returns true. For more information, see execute. string
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: