Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default case in switch case list #999

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .ci/validation/test/fixtures/invalid/switch-missing-when.yaml
Original file line number Diff line number Diff line change
@@ -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
matthias-pichler marked this conversation as resolved.
Show resolved Hide resolved
- 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
3 changes: 1 addition & 2 deletions ctk/features/switch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ Feature: Switch Task
- blue:
when: '.color == "blue"'
then: setBlue
- anyOtherColor:
then: setCustomColor
then: setCustomColor
- setRed:
set:
colors: '${ .colors + [ "red" ] }'
Expand Down
8 changes: 3 additions & 5 deletions dsl-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ do:
- lowPriority:
when: .ticket.priority == "low"
then: resolveTicket
- default:
then: raiseUndefinedPriorityError
then: raiseUndefinedPriorityError
- raiseUndefinedPriorityError:
raise:
error:
Expand Down Expand Up @@ -926,8 +925,7 @@ do:
- case2:
when: .orderType == "physical"
then: processPhysicalOrder
- default:
then: handleUnknownOrderType
then: handleUnknownOrderType
- processElectronicOrder:
do:
- validatePayment:
Expand Down Expand Up @@ -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.<br>*If not set, the case will be matched by default if no other case match.*<br>*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.<br>*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
Expand Down
3 changes: 1 addition & 2 deletions examples/switch-then-string.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ do:
- case2:
when: .orderType == "physical"
then: processPhysicalOrder
- default:
then: handleUnknownOrderType
then: handleUnknownOrderType
- processElectronicOrder:
do:
- validatePayment:
Expand Down
2 changes: 1 addition & 1 deletion schema/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions use-cases/managing-ev-charging-stations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ do:
- sessionInProgress:
when: .session != null
then: endSession
- noActiveSession:
then: tryAquireSlot
then: tryAquireSlot

- tryAquireSlot:
try:
Expand Down
9 changes: 3 additions & 6 deletions use-cases/managing-github-issues/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ do:
- requestDetails:
when: $context.issue.action == "requestDetails"
then: awaitDetailsFromQA
- default:
then: raiseUnsupportedActionError
then: raiseUnsupportedActionError

- awaitDetailsFromQA:
do:
Expand Down Expand Up @@ -174,8 +173,7 @@ do:
- reviewerIsNotAssignedDev:
when: $context.issue.reviewer != $context.issue.dev
then: evaluateReview
- reviewerIsAssignedDev:
then: raiseAssignedDevCannotBeReviewer
then: raiseAssignedDevCannotBeReviewer

- evaluateReview:
do:
Expand Down Expand Up @@ -206,8 +204,7 @@ do:
- closeIssue:
when: $context.issue.action == "close"
then: closeIssue
- default:
then: exit
then: exit
- closeIssue:
do:
- initialize:
Expand Down
Loading