diff --git a/.ci/validation/test/fixtures/invalid/switch-missing-when.yaml b/.ci/validation/test/fixtures/invalid/switch-missing-when.yaml new file mode 100644 index 00000000..71d145fe --- /dev/null +++ b/.ci/validation/test/fixtures/invalid/switch-missing-when.yaml @@ -0,0 +1,45 @@ +document: + dsl: 1.0.0-alpha2 + namespace: test + name: switch-missing-when + 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: + set: + validate: true + - fulfillOrder: + set: + status: fulfilled + then: exit + - processPhysicalOrder: + do: + - checkInventory: + set: + inventory: clear + - packItems: + set: + items: 1 + - scheduleShipping: + set: + address: Elmer St + then: exit + - handleUnknownOrderType: + do: + - logWarning: + set: + log: warn + - notifyAdmin: + set: + message: something's wrong diff --git a/ctk/features/switch.feature b/ctk/features/switch.feature index bba64c00..9879396c 100644 --- a/ctk/features/switch.feature +++ b/ctk/features/switch.feature @@ -108,8 +108,7 @@ Feature: Switch Task - blue: when: '.color == "blue"' then: setBlue - - anyOtherColor: - then: setCustomColor + then: setCustomColor - setRed: set: colors: '${ .colors + [ "red" ] }' diff --git a/dsl-reference.md b/dsl-reference.md index 68b3346b..6a5a7681 100644 --- a/dsl-reference.md +++ b/dsl-reference.md @@ -673,8 +673,7 @@ do: - lowPriority: when: .ticket.priority == "low" then: resolveTicket - - default: - then: raiseUndefinedPriorityError + then: raiseUndefinedPriorityError - raiseUndefinedPriorityError: raise: error: @@ -926,8 +925,7 @@ do: - case2: when: .orderType == "physical" then: processPhysicalOrder - - default: - then: handleUnknownOrderType + then: handleUnknownOrderType - processElectronicOrder: do: - validatePayment: @@ -979,7 +977,7 @@ Defines a switch case, encompassing a condition for matching and an associated a | Name | Type | Required | Description | |:--|:---:|:---:|:---| -| when | `string` | `no` | 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 match.*
*Note that there can be only one default case, all others **MUST** set a condition.* +| when | `string` | `yes` | A runtime expression used to determine whether or not the case matches.
*To define a default case, use the task level `then` property, which will be used when no task matches.* | | then | [`flowDirective`](#flow-directive) | `yes` | The flow directive to execute when the case matches. | #### Try diff --git a/examples/switch-then-string.yaml b/examples/switch-then-string.yaml index 881bab50..813a908b 100644 --- a/examples/switch-then-string.yaml +++ b/examples/switch-then-string.yaml @@ -12,8 +12,7 @@ do: - case2: when: .orderType == "physical" then: processPhysicalOrder - - default: - then: handleUnknownOrderType + then: handleUnknownOrderType - processElectronicOrder: do: - validatePayment: diff --git a/schema/workflow.yaml b/schema/workflow.yaml index 1b47ec76..8c4a73fb 100644 --- a/schema/workflow.yaml +++ b/schema/workflow.yaml @@ -702,7 +702,7 @@ $defs: title: SwitchCase description: The definition of a case within a switch task, defining a condition and corresponding tasks to execute if the condition is met. unevaluatedProperties: false - required: [ then ] + required: [ when, then ] properties: when: type: string diff --git a/use-cases/managing-ev-charging-stations/README.md b/use-cases/managing-ev-charging-stations/README.md index 35e41091..e0fe200a 100644 --- a/use-cases/managing-ev-charging-stations/README.md +++ b/use-cases/managing-ev-charging-stations/README.md @@ -119,8 +119,7 @@ do: - sessionInProgress: when: .session != null then: endSession - - noActiveSession: - then: tryAquireSlot + then: tryAquireSlot - tryAquireSlot: try: diff --git a/use-cases/managing-github-issues/README.md b/use-cases/managing-github-issues/README.md index d320c4e5..f66820d3 100644 --- a/use-cases/managing-github-issues/README.md +++ b/use-cases/managing-github-issues/README.md @@ -114,8 +114,7 @@ do: - requestDetails: when: $context.issue.action == "requestDetails" then: awaitDetailsFromQA - - default: - then: raiseUnsupportedActionError + then: raiseUnsupportedActionError - awaitDetailsFromQA: do: @@ -174,8 +173,7 @@ do: - reviewerIsNotAssignedDev: when: $context.issue.reviewer != $context.issue.dev then: evaluateReview - - reviewerIsAssignedDev: - then: raiseAssignedDevCannotBeReviewer + then: raiseAssignedDevCannotBeReviewer - evaluateReview: do: @@ -206,8 +204,7 @@ do: - closeIssue: when: $context.issue.action == "close" then: closeIssue - - default: - then: exit + then: exit - closeIssue: do: - initialize: