Enables conditional branching within workflows, allowing them to dynamically select different paths based on specified conditions or criteria.
Properties
A name/value map of the cases to switch on.
Switch Case
Defines a switch case, encompassing a condition for matching and an associated action to execute upon a match.
A runtime expression used to determine whether or not the case matches.If not set, the case will be matched by default if no other case matches. Note that there can be only one default case; all others must set a condition.
The flow directive to execute when the case matches.
Example
document:
dsl: '1.0.3'
namespace: test
name: switch-example
version: '0.1.0'
do:
- processOrder:
switch:
- case1:
when: .orderType == "electronic"
then: processElectronicOrder
- case2:
when: .orderType == "physical"
then: processPhysicalOrder
- default:
then: handleUnknownOrderType
- processElectronicOrder:
do:
- validatePayment:
call: http
with:
method: post
endpoint: https://fake-payment-service.com/validate
- fulfillOrder:
call: http
with:
method: post
endpoint: https://fake-fulfillment-service.com/fulfill
then: exit
- processPhysicalOrder:
do:
- checkInventory:
call: http
with:
method: get
endpoint: https://fake-inventory-service.com/inventory
- packItems:
call: http
with:
method: post
endpoint: https://fake-packaging-service.com/pack
- scheduleShipping:
call: http
with:
method: post
endpoint: https://fake-shipping-service.com/schedule
then: exit
- handleUnknownOrderType:
do:
- logWarning:
call: http
with:
method: post
endpoint: https://fake-logging-service.com/warn
- notifyAdmin:
call: http
with:
method: post
endpoint: https://fake-notification-service.com/notify