Skip to content

Commit 3ee6317

Browse files
Fix #195 - Fix 'End' model when is defined (#212)
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 17bb30b commit 3ee6317

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

model/action_validator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func actionStructLevelValidationCtx(ctx ValidatorContext, structLevel validator.
3939
action.SubFlowRef != nil,
4040
}
4141

42-
if validationNotExclusiveParamters(values) {
42+
if validationNotExclusiveParameters(values) {
4343
structLevel.ReportError(action.FunctionRef, "FunctionRef", "FunctionRef", val.TagExclusive, "")
4444
structLevel.ReportError(action.EventRef, "EventRef", "EventRef", val.TagExclusive, "")
4545
structLevel.ReportError(action.SubFlowRef, "SubFlowRef", "SubFlowRef", val.TagExclusive, "")

model/workflow_validator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func transitionStructLevelValidationCtx(ctx ValidatorContext, structLevel valida
217217

218218
func validTransitionAndEnd(structLevel validator.StructLevel, field any, transition *Transition, end *End) {
219219
hasTransition := transition != nil
220-
isEnd := end != nil && (end.Terminate || end.ContinueAs != nil || len(end.ProduceEvents) > 0) // TODO: check the spec continueAs/produceEvents to see how it influences the end
220+
isEnd := end != nil && (end.Terminate || end.Compensate || end.ContinueAs != nil || len(end.ProduceEvents) > 0) // TODO: check the spec continueAs/produceEvents to see how it influences the end
221221

222222
if !hasTransition && !isEnd {
223223
structLevel.ReportError(field, "Transition", "transition", val.TagRequired, "")
@@ -226,7 +226,7 @@ func validTransitionAndEnd(structLevel validator.StructLevel, field any, transit
226226
}
227227
}
228228

229-
func validationNotExclusiveParamters(values []bool) bool {
229+
func validationNotExclusiveParameters(values []bool) bool {
230230
hasOne := false
231231
hasTwo := false
232232

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"id": "compensation",
3+
"version": "1.0",
4+
"name": "Workflow Error example",
5+
"description": "An example of how compensation works",
6+
"start": "printStatus",
7+
"states": [
8+
{
9+
"name": "printStatus",
10+
"type": "inject",
11+
"data": {
12+
"compensated": false
13+
},
14+
"compensatedBy" : "compensating",
15+
"transition": "branch"
16+
},
17+
{
18+
"name": "branch",
19+
"type": "switch",
20+
"dataConditions": [
21+
{
22+
"condition": ".shouldCompensate==true",
23+
"transition": {
24+
"nextState" : "finish_compensate",
25+
"compensate" : true
26+
}
27+
},
28+
{
29+
"condition": ".shouldCompensate==false",
30+
"transition": {
31+
"nextState" : "finish_not_compensate",
32+
"compensate" : false
33+
}
34+
}
35+
],
36+
"defaultCondition": {
37+
"end": true
38+
}
39+
},
40+
{
41+
"name": "compensating",
42+
"usedForCompensation" : true,
43+
"type": "inject",
44+
"data": {
45+
"compensated": true
46+
},
47+
"transition" : "compensating_more"
48+
},
49+
{
50+
"name": "compensating_more",
51+
"usedForCompensation" : true,
52+
"type": "inject",
53+
"data": {
54+
"compensating_more": "Real Betis Balompie"
55+
}
56+
},
57+
{
58+
"name": "finish_compensate",
59+
"type": "operation",
60+
"actions": [],
61+
"end": {
62+
"compensate": true
63+
}
64+
},
65+
{
66+
"name": "finish_not_compensate",
67+
"type": "operation",
68+
"actions": [],
69+
"end": true
70+
}
71+
]
72+
}

0 commit comments

Comments
 (0)