Skip to content

Commit 5a0a34f

Browse files
authored
feat(*): sync examples to v0.8 spec (#100)
Signed-off-by: lsytj0413 <511121939@qq.com> Signed-off-by: lsytj0413 <511121939@qq.com>
1 parent 7b22226 commit 5a0a34f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1651
-499
lines changed

model/states.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,11 @@ func (j *EventBasedSwitchState) UnmarshalJSON(data []byte) error {
292292
return err
293293
}
294294

295-
if err := json.Unmarshal(eventBasedSwitch["timeouts"], &j.Timeouts); err != nil {
296-
return err
295+
eventBaseTimeoutsRawMessage, ok := eventBasedSwitch["timeouts"]
296+
if ok {
297+
if err := json.Unmarshal(eventBaseTimeoutsRawMessage, &j.Timeouts); err != nil {
298+
return err
299+
}
297300
}
298301

299302
var rawConditions []json.RawMessage

model/workflow.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func (w *Workflow) UnmarshalJSON(data []byte) error {
164164
if nestedData, err = getBytesFromFile(s); err != nil {
165165
return err
166166
}
167+
167168
m := make(map[string][]Event)
168169
if err := json.Unmarshal(nestedData, &m); err != nil {
169170
return err

parser/eventdefs.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2022 The Serverless Workflow Specification Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
events:
16+
- name: PaymentReceivedEvent
17+
type: payment.receive
18+
source: paymentEventSource
19+
correlation:
20+
- contextAttributeName: accountId
21+
- name: ConfirmationCompletedEvent
22+
type: payment.confirmation
23+
kind: produced

parser/functiondefs.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"functions": [
3+
{
4+
"name": "checkFundsAvailability",
5+
"operation": "file://myapis/billingapis.json#checkFunds"
6+
},
7+
{
8+
"name": "sendSuccessEmail",
9+
"operation": "file://myapis/emailapis.json#paymentSuccess"
10+
},
11+
{
12+
"name": "sendInsufficientFundsEmail",
13+
"operation": "file://myapis/emailapis.json#paymentInsufficientFunds"
14+
}
15+
]
16+
}

parser/parser_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestBasicValidation(t *testing.T) {
3131
for _, file := range files {
3232
if !file.IsDir() {
3333
workflow, err := FromFile(filepath.Join(rootPath, file.Name()))
34+
3435
if assert.NoError(t, err, "Test File %s", file.Name()) {
3536
assert.NotEmpty(t, workflow.ID, "Test File %s", file.Name())
3637
assert.NotEmpty(t, workflow.States, "Test File %s", file.Name())
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": "VetAppointmentWorkflow",
3+
"name": "Vet Appointment Workflow",
4+
"description": "Vet service call via events",
5+
"version": "1.0",
6+
"specVersion": "0.8",
7+
"start": "MakeVetAppointmentState",
8+
"events": [
9+
{
10+
"name": "MakeVetAppointment",
11+
"source": "VetServiceSource",
12+
"type": "events.vet.appointments",
13+
"kind": "produced"
14+
},
15+
{
16+
"name": "VetAppointmentInfo",
17+
"source": "VetServiceSource",
18+
"type": "events.vet.appointments",
19+
"kind": "consumed"
20+
}
21+
],
22+
"states": [
23+
{
24+
"name": "MakeVetAppointmentState",
25+
"type": "operation",
26+
"actions": [
27+
{
28+
"name": "MakeAppointmentAction",
29+
"eventRef": {
30+
"triggerEventRef": "MakeVetAppointment",
31+
"data": "${ .patientInfo }",
32+
"resultEventRef": "VetAppointmentInfo"
33+
},
34+
"actionDataFilter": {
35+
"results": "${ .appointmentInfo }"
36+
}
37+
}
38+
],
39+
"timeouts": {
40+
"actionExecTimeout": "PT15M"
41+
},
42+
"end": true
43+
}
44+
]
45+
}

parser/testdata/workflows/applicationrequest-issue16.sw.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ version: '1.0'
1717
name: Applicant Request Decision Workflow
1818
description: Determine if applicant request is valid
1919
start: CheckApplication
20-
specVersion: "0.7"
20+
specVersion: "0.8"
2121
functions:
2222
- name: sendRejectionEmailFunction
2323
operation: http://myapis.org/applicationapi.json#emailRejection

parser/testdata/workflows/applicationrequest-issue69.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Applicant Request Decision Workflow",
55
"description": "Determine if applicant request is valid",
66
"start": "CheckApplication",
7-
"specVersion": "0.7",
7+
"specVersion": "0.8",
88
"auth": "./testdata/workflows/urifiles/auth.json",
99
"functions": [
1010
{
Lines changed: 65 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,75 @@
11
{
2-
"id": "applicantrequest",
3-
"version": "1.0",
4-
"name": "Applicant Request Decision Workflow",
5-
"description": "Determine if applicant request is valid",
6-
"start": "CheckApplication",
7-
"specVersion": "0.7",
8-
"auth": [{
9-
"name": "testAuth",
10-
"scheme": "bearer",
11-
"properties": {
12-
"token": "test_token"
13-
}
14-
}],
15-
"functions": [
16-
{
17-
"name": "sendRejectionEmailFunction",
18-
"operation": "http://myapis.org/applicationapi.json#emailRejection"
19-
}
20-
],
21-
"retries": [
22-
{
23-
"name": "TimeoutRetryStrategy",
24-
"delay": "PT1M",
25-
"maxAttempts": "5"
26-
}
27-
],
28-
"states": [
29-
{
30-
"name": "CheckApplication",
31-
"type": "switch",
32-
"dataConditions": [
2+
"id": "applicantrequest",
3+
"version": "1.0",
4+
"specVersion": "0.8",
5+
"name": "Applicant Request Decision Workflow",
6+
"description": "Determine if applicant request is valid",
7+
"start": "CheckApplication",
8+
"functions": [
339
{
34-
"condition": "${ .applicants | .age >= 18 }",
35-
"transition": {
36-
"nextState": "StartApplication"
37-
}
38-
},
39-
{
40-
"condition": "${ .applicants | .age < 18 }",
41-
"transition": {
42-
"nextState": "RejectApplication"
43-
}
10+
"name": "sendRejectionEmailFunction",
11+
"operation": "http://myapis.org/applicationapi.json#emailRejection"
4412
}
45-
],
46-
"default": {
47-
"transition": {
48-
"nextState": "RejectApplication"
13+
],
14+
"auth": [
15+
{
16+
"name": "testAuth",
17+
"scheme": "bearer",
18+
"properties": {
19+
"token": "test_token"
20+
}
4921
}
50-
}
51-
},
52-
{
53-
"name": "StartApplication",
54-
"type": "operation",
55-
"actions": [
22+
],
23+
"retries": [
5624
{
57-
"subFlowRef": {
58-
"workflowId": "startApplicationWorkflowId"
59-
}
25+
"name": "TimeoutRetryStrategy",
26+
"delay": "PT1M",
27+
"maxAttempts": "5"
6028
}
61-
],
62-
"end": {
63-
"terminate": true
64-
}
65-
},
66-
{
67-
"name": "RejectApplication",
68-
"type": "operation",
69-
"actionMode": "sequential",
70-
"actions": [
29+
],
30+
"states": [
7131
{
72-
"functionRef": {
73-
"refName": "sendRejectionEmailFunction",
74-
"parameters": {
75-
"applicant": "${ .applicant }"
32+
"name": "CheckApplication",
33+
"type": "switch",
34+
"dataConditions": [
35+
{
36+
"condition": "${ .applicants | .age >= 18 }",
37+
"transition": "StartApplication"
38+
},
39+
{
40+
"condition": "${ .applicants | .age < 18 }",
41+
"transition": "RejectApplication"
42+
}
43+
],
44+
"defaultCondition": {
45+
"transition": "RejectApplication"
7646
}
77-
}
47+
},
48+
{
49+
"name": "StartApplication",
50+
"type": "operation",
51+
"actions": [
52+
{
53+
"subFlowRef": "startApplicationWorkflowId"
54+
}
55+
],
56+
"end": true
57+
},
58+
{
59+
"name": "RejectApplication",
60+
"type": "operation",
61+
"actionMode": "sequential",
62+
"actions": [
63+
{
64+
"functionRef": {
65+
"refName": "sendRejectionEmailFunction",
66+
"arguments": {
67+
"applicant": "${ .applicant }"
68+
}
69+
}
70+
}
71+
],
72+
"end": true
7873
}
79-
],
80-
"end": {
81-
"terminate": true
82-
}
83-
}
84-
]
74+
]
8575
}

parser/testdata/workflows/applicationrequest.multiauth.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Applicant Request Decision Workflow",
55
"description": "Determine if applicant request is valid",
66
"start": "CheckApplication",
7-
"specVersion": "0.7",
7+
"specVersion": "0.8",
88
"auth": [
99
{
1010
"name": "testAuth",

0 commit comments

Comments
 (0)