Skip to content

Commit eb32b3b

Browse files
authored
v08 spec alignment - Support custom function type definition (#80)
Signed-off-by: spolti <filippespolti@gmail.com> Signed-off-by: spolti <filippespolti@gmail.com>
1 parent 828391a commit eb32b3b

File tree

5 files changed

+78
-11
lines changed

5 files changed

+78
-11
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/serverlessworkflow/sdk-go/v2
33
go 1.19
44

55
require (
6-
github.com/go-playground/validator/v10 v10.11.0
6+
github.com/go-playground/validator/v10 v10.11.1
77
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46
88
github.com/stretchr/testify v1.7.0
99
k8s.io/apimachinery v0.25.1

go.sum

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb
1111
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
1212
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
1313
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
14-
github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw=
15-
github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
14+
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
15+
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
1616
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
1717
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
1818
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
@@ -37,6 +37,8 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA
3737
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
3838
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46 h1:Dz0HrI1AtNSGCE8LXLLqoZU4iuOJXPWndenCsZfstA8=
3939
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46/go.mod h1:is8FVkzSi7PYLWEXT5MgWhglFsyyiW8ffxAoJqfuFZo=
40+
github.com/serverlessworkflow/sdk-go v1.0.0 h1:XsRtESODZhyvwHYgARH2VuubiZytME3jiJ61zwGj2YQ=
41+
github.com/serverlessworkflow/sdk-go v1.0.0/go.mod h1:y8Va8RTSHEGShsyISobSCKiniKiBKTUne73pY5sux0E=
4042
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4143
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4244
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
@@ -87,6 +89,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
8789
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
8890
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
8991
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
92+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
93+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
9094
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
9195
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
9296
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@@ -99,5 +103,6 @@ k8s.io/klog/v2 v2.70.1 h1:7aaoSdahviPmR+XkS7FyxlkkXs6tHISSG03RxleQAVQ=
99103
k8s.io/klog/v2 v2.70.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
100104
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
101105
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
106+
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
102107
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
103108
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

model/function.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ package model
1717
import "encoding/json"
1818

1919
const (
20-
// FunctionTypeREST ...
20+
// FunctionTypeREST a combination of the function/service OpenAPI definition document URI and the particular service
21+
// operation that needs to be invoked, separated by a '#'.
2122
FunctionTypeREST FunctionType = "rest"
22-
// FunctionTypeRPC ...
23+
// FunctionTypeRPC a combination of the gRPC proto document URI and the particular service name and service method
24+
// name that needs to be invoked, separated by a '#'.
2325
FunctionTypeRPC FunctionType = "rpc"
24-
// FunctionTypeExpression ...
26+
// FunctionTypeExpression defines the expression syntax.
2527
FunctionTypeExpression FunctionType = "expression"
26-
// FunctionTypeGraphQL ...
28+
// FunctionTypeGraphQL a combination of the GraphQL schema definition URI and the particular service name and
29+
// service method name that needs to be invoked, separated by a '#'
2730
FunctionTypeGraphQL FunctionType = "graphql"
28-
// FunctionTypeAsyncAPI ...
31+
// FunctionTypeAsyncAPI a combination of the AsyncApi definition document URI and the particular service operation
32+
// that needs to be invoked, separated by a '#'
2933
FunctionTypeAsyncAPI FunctionType = "asyncapi"
30-
// FunctionTypeOData ...
34+
// FunctionTypeOData a combination of the GraphQL schema definition URI and the particular service name and service
35+
// method name that needs to be invoked, separated by a '#'
3136
FunctionTypeOData FunctionType = "odata"
37+
// FunctionTypeCustom property defines a list of function types that are set by the specification. Some runtime
38+
// implementations might support additional function types that extend the ones defined in the specification
39+
FunctionTypeCustom FunctionType = "custom"
3240
)
3341

3442
// FunctionType ...
@@ -39,9 +47,10 @@ type Function struct {
3947
Common
4048
// Unique function name
4149
Name string `json:"name" validate:"required"`
42-
// If type is `rest`, <path_to_openapi_definition>#<operation_id>. If type is `rpc`, <path_to_grpc_proto_file>#<service_name>#<service_method>. If type is `expression`, defines the workflow expression.
50+
// If type is `rest`, <path_to_openapi_definition>#<operation_id>. If type is `rpc`, <path_to_grpc_proto_file>#<service_name>#<service_method>.
51+
// If type is `expression`, defines the workflow expression. If the type is `custom`, <path_to_custom_script>#<custom_service_method>.
4352
Operation string `json:"operation" validate:"required"`
44-
// Defines the function type. Is either `rest`, `rpc`, `expression` or `graphql`. Default is `rest`
53+
// Defines the function type. Is either `rest`, `rpc`, `expression`, `graphql`, `asyncapi`, `odata` or `custom`. Default is `rest`
4554
Type FunctionType `json:"type,omitempty"`
4655
// References an auth definition name to be used to access to resource defined in the operation parameter
4756
AuthRef string `json:"authRef,omitempty" validate:"omitempty,min=1"`

parser/parser_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ func TestFromFile(t *testing.T) {
6565
assert.NotNil(t, w.States[0].(*model.OperationState).Actions[0].FunctionRef)
6666
assert.Equal(t, "greetingFunction", w.States[0].(*model.OperationState).Actions[0].FunctionRef.RefName)
6767
},
68+
"./testdata/workflows/greetings-custom-function.sw.yaml": func(t *testing.T, w *model.Workflow) {
69+
assert.IsType(t, &model.OperationState{}, w.States[0])
70+
assert.Equal(t, "custom.greeting", w.ID)
71+
assert.NotEmpty(t, w.States[0].(*model.OperationState).Actions)
72+
assert.NotEmpty(t, w.Functions[0])
73+
assert.Equal(t, "greetingCustomFunction", w.Functions[0].Name)
74+
assert.Equal(t, model.FunctionTypeCustom, w.Functions[0].Type)
75+
assert.NotNil(t, w.States[0].(*model.OperationState).Actions[0].FunctionRef)
76+
assert.Equal(t, "greetingCustomFunction", w.States[0].(*model.OperationState).Actions[0].FunctionRef.RefName)
77+
assert.Equal(t, "greetingCustomFunction", w.States[0].(*model.OperationState).Actions[0].Name)
78+
},
6879
"./testdata/workflows/eventbaseddataandswitch.sw.json": func(t *testing.T, w *model.Workflow) {
6980
assert.Equal(t, "Start", w.States[0].GetName())
7081
assert.Equal(t, "CheckVisaStatus", w.States[1].GetName())
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2020 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+
id: custom.greeting
16+
version: '1.0'
17+
name: Greeting Workflow
18+
description: Greet Someone
19+
specVersion: "0.8"
20+
start:
21+
stateName: Greet
22+
functions:
23+
- name: greetingCustomFunction
24+
operation: /path/to/my/script/greeting.ts#CustomGreeting
25+
type: custom
26+
27+
states:
28+
- name: Greet
29+
type: operation
30+
actionMode: sequential
31+
actions:
32+
- name: greetingCustomFunction
33+
functionRef:
34+
refName: greetingCustomFunction
35+
parameters:
36+
name: "${ .greet | .name }"
37+
actionDataFilter:
38+
dataResultsPath: "${ .payload | .greeting }"
39+
stateDataFilter:
40+
dataOutputPath: "${ .greeting }"
41+
end:
42+
terminate: true

0 commit comments

Comments
 (0)