operation-switch

Use the operation-switch construct when you want to execute alternative policy assemblies, conditional on the operation that is being called.

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 operation-switch.

About

An operation can be described with a verb/path pair, or with an operationId. The operationIds are strings, or names, that are defined in the OpenAPI document.

The operation-switch policy has the following format:
- operation-switch:
  version: version
  title: title
  description: description
  case:
    - operations:
      - verb: operation_verb_1_1
        path: operation_path_1_1
      - verb: operation_verb_1_2
        path: operation_path_1_2
                     .
                     .
                     .
           further verb/path combinations
                     .
                     .
                     .
      execute: 
        policy_assembly_1 ...
    - operations:
      - verb: operation_verb_2_1
        path: operation_path_2_1
      - verb: operation_verb_2_2
        path: operation_path_2_2
                     .
                     .
                     .
           further verb/path combinations
                     .
                     .
                     .
      execute: 
        policy_assembly_2 ...
                   .
                   .
                   .
    - operations:
      - operationID_3_1
      - operationID_3_2
      - operationID_3_3
        
                     .
                     .
                     .
           further operationIDs
                     .
                     .
                     .
      execute: 
        policy_assembly_3 ...
                   .
                   .
                   .
         further operations sections
                   .
                   .
                   .
 

For each operations: section, if the operation that is being called matches any of the verb/path combinations or operationId strings listed in that operations: section, then the policy assembly that is defined in the execute: section is executed. Therefore, each operations: section defines execution of a policy assembly conditional on the operation that is being called.

You can have as many operations: sections as you want, and each operations: section can have one or more verb/path combinations or operationId strings.

The execute: section can define any policy assembly, including further operation-switch policies.

Properties

Table 2. operation-switch policy properties
Property Required Description Data type Contained in
version Yes The policy version number string N/A
title No A title for the policy. string N/A
description No A policy description. string N/A
case Yes An array containing different cases, each entry contains an operations and execute field. array (object) N/A
operations Yes The operations to which a case applies. object case
verb No An operation verb.
Valid values:
  • GET
  • POST
  • PUT
  • DELETE
  • HEAD
  • PATCH
  • OPTIONS
string operations
path No A relative path to an individual endpoint. For example, /account_status. string operations
operationID No The operation is defined in OpenAPI. The policy operation refers to the OpenAPI operation. string operations
execute Yes The policy assembly that you want to execute if the operation that is being called matches any one of the verb/path combinations. For more information, see execute. string case

Example

Example that defines match operations with verb/path combinations:
# carry out different redaction actions depending on the operation

- operation-switch:
  version: 1.0.0
  title: clear_region_and_set_body
  case:
    - operations:
      - verb: GET
        path: /account_details
      execute:
        - redact:
            title: remove secret field
            actions:
              - action: remove
                from: all
                path: /document/user/secret
    - operations:
      - verb: GET
        path: /account_status
      execute:
        - redact:
            title: redact address
            actions:
              - action: redact
                from: response
                path: //*[@name='secondaryAddress']/*[@name='streetAddress']
Example that defines match operation with operationIDs:
# match on operationIDs

- operation-switch:
  title: customer_actions
  case:
    - operations:
      - getCustomerByName
      - deleteCustomer
      - addACustomer
      execute:
           .
           .
           .