Skip to content

Commit

Permalink
Fix #195 - Fix 'End' model when is defined (#212)
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
  • Loading branch information
ricardozanini authored Oct 9, 2024
1 parent 17bb30b commit 3ee6317
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
2 changes: 1 addition & 1 deletion model/action_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func actionStructLevelValidationCtx(ctx ValidatorContext, structLevel validator.
action.SubFlowRef != nil,
}

if validationNotExclusiveParamters(values) {
if validationNotExclusiveParameters(values) {
structLevel.ReportError(action.FunctionRef, "FunctionRef", "FunctionRef", val.TagExclusive, "")
structLevel.ReportError(action.EventRef, "EventRef", "EventRef", val.TagExclusive, "")
structLevel.ReportError(action.SubFlowRef, "SubFlowRef", "SubFlowRef", val.TagExclusive, "")
Expand Down
4 changes: 2 additions & 2 deletions model/workflow_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func transitionStructLevelValidationCtx(ctx ValidatorContext, structLevel valida

func validTransitionAndEnd(structLevel validator.StructLevel, field any, transition *Transition, end *End) {
hasTransition := transition != nil
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
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

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

func validationNotExclusiveParamters(values []bool) bool {
func validationNotExclusiveParameters(values []bool) bool {
hasOne := false
hasTwo := false

Expand Down
72 changes: 72 additions & 0 deletions parser/testdata/workflows/compensation.sw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"id": "compensation",
"version": "1.0",
"name": "Workflow Error example",
"description": "An example of how compensation works",
"start": "printStatus",
"states": [
{
"name": "printStatus",
"type": "inject",
"data": {
"compensated": false
},
"compensatedBy" : "compensating",
"transition": "branch"
},
{
"name": "branch",
"type": "switch",
"dataConditions": [
{
"condition": ".shouldCompensate==true",
"transition": {
"nextState" : "finish_compensate",
"compensate" : true
}
},
{
"condition": ".shouldCompensate==false",
"transition": {
"nextState" : "finish_not_compensate",
"compensate" : false
}
}
],
"defaultCondition": {
"end": true
}
},
{
"name": "compensating",
"usedForCompensation" : true,
"type": "inject",
"data": {
"compensated": true
},
"transition" : "compensating_more"
},
{
"name": "compensating_more",
"usedForCompensation" : true,
"type": "inject",
"data": {
"compensating_more": "Real Betis Balompie"
}
},
{
"name": "finish_compensate",
"type": "operation",
"actions": [],
"end": {
"compensate": true
}
},
{
"name": "finish_not_compensate",
"type": "operation",
"actions": [],
"end": true
}
]
}

0 comments on commit 3ee6317

Please sign in to comment.