Skip to content

Commit 7344718

Browse files
Add support for custom function type definitions (#460)
* Add support to custom function type definitions Signed-off-by: Ricardo Zanini <[email protected]> * simplified functions schema (dont require secondary) - try Signed-off-by: Tihomir Surdilovic <[email protected]> * playing with default value Signed-off-by: Tihomir Surdilovic <[email protected]> * oneOf->anyOf Signed-off-by: Tihomir Surdilovic <[email protected]> * enum/obj Signed-off-by: Tihomir Surdilovic <[email protected]> * fix Signed-off-by: Tihomir Surdilovic <[email protected]> * fix Signed-off-by: Tihomir Surdilovic <[email protected]> * final changes Signed-off-by: Tihomir Surdilovic <[email protected]> * added a little more text Signed-off-by: Tihomir Surdilovic <[email protected]> * small change to example for custom type Signed-off-by: Tihomir Surdilovic <[email protected]> * change extending to defining custom Signed-off-by: Tihomir Surdilovic <[email protected]> * Adding custom type Signed-off-by: Ricardo Zanini <[email protected]> * Change from operation to function Co-authored-by: Tihomir Surdilovic <[email protected]>
1 parent b5afe5b commit 7344718

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

roadmap/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ _Status description:_
1919
- [v0.1 released April 2020](#v01)
2020

2121
## <a name="v08"></a> Next planned release
22+
2223
| Status | Description | Comments |
2324
| --- | --- | --- |
24-
| | | |
25+
| ✔️| Support custom function `type` definition | [spec doc](https://github.com/serverlessworkflow/specification/blob/main/specification.md) |
2526

2627
## <a name="v07"></a> v0.7
2728

schema/functions.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
},
4242
"type": {
4343
"type": "string",
44-
"description": "Defines the function type. Is either `rest`, `asyncapi, `rpc`, `graphql`, `odata`, or `expression`. Default is `rest`",
44+
"description": "Defines the function type. Is either `rest`, `asyncapi, `rpc`, `graphql`, `odata`, `expression`, or `custom`. Default is `rest`",
4545
"enum": [
4646
"rest",
4747
"asyncapi",
4848
"rpc",
4949
"graphql",
5050
"odata",
51-
"expression"
51+
"expression",
52+
"custom"
5253
],
5354
"default": "rest"
5455
},

specification.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- [Creating an OData Function Definition](#creating-an-odata-function-definition)
3434
- [Invoking an OData Function Definition](#invoking-an-odata-function-definition)
3535
+ [Using Functions for Expression Evaluation](#using-functions-for-expression-evaluation)
36+
+ [Defining custom Function types](#defining-custom-function-types)
3637
* [Workflow Expressions](#workflow-expressions)
3738
* [Workflow Definition Structure](#workflow-definition-structure)
3839
+ [Workflow States](#workflow-states)
@@ -86,7 +87,7 @@
8687
+ [Compensation Execution Details](#compensation-execution-details)
8788
+ [Compensation and Active States](#compensation-and-active-states)
8889
+ [Unrecoverable errors during compensation](#unrecoverable-errors-during-compensation)
89-
* [Continuing as a new Execution](#continuing-as-a-new-execution)
90+
* [Continuing as a new Execution](#continuing-as-a-new-execution)
9091
+ [ContinueAs in sub workflows](#continueas-in-sub-workflows)
9192
* [Workflow Versioning](#workflow-versioning)
9293
* [Workflow Constants](#workflow-constants)
@@ -1033,9 +1034,12 @@ They can be referenced by their domain-specific names inside workflow [states](#
10331034
Reference the following sections to learn more about workflow functions:
10341035

10351036
* [Using functions for RESTful service invocations](#Using-Functions-For-RESTful-Service-Invocations)
1037+
* [Using Functions for Async API Service Invocations](#Using-Functions-for-Async-API-Service-Invocations)
10361038
* [Using functions for gRPC service invocation](#Using-Functions-For-RPC-Service-Invocations)
10371039
* [Using functions for GraphQL service invocation](#Using-Functions-For-GraphQL-Service-Invocations)
1040+
* [Using Functions for OData Service Invocations](#Using-Functions-for-OData-Service-Invocations)
10381041
* [Using functions for expression evaluations](#Using-Functions-For-Expression-Evaluation)
1042+
* [Defining custom function types](#defining-custom-function-types)
10391043

10401044
#### Using Functions for RESTful Service Invocations
10411045

@@ -1565,6 +1569,56 @@ For more information about functions, reference the [Functions definitions](#Fun
15651569

15661570
For more information about workflow expressions, reference the [Workflow Expressions](#Workflow-Expressions) section.
15671571

1572+
#### Defining custom function types
1573+
1574+
[Function definitions](#function-definition) `type` property defines a list of function types that are set by
1575+
the specification.
1576+
1577+
Some runtime implementations might support additional function types that extend the ones
1578+
defined in the specification. In those cases you can define a custom function type with for example:
1579+
1580+
```json
1581+
{
1582+
"functions": [
1583+
{
1584+
"name": "sendOrderConfirmation",
1585+
"operation": "/path/to/my/script/order.ts#myFunction",
1586+
"type": "custom"
1587+
}
1588+
]
1589+
}
1590+
```
1591+
1592+
In this example we define a custom function type that is meant to execute an external [TypeScript](https://www.typescriptlang.org/) script.
1593+
1594+
When a custom function type is specified, the operation property value has a **custom format**, meaning that
1595+
its format is controlled by the runtime which provides the custom function type.
1596+
1597+
Later, the function should be able to be used in an action as any other function supported by the specification:
1598+
1599+
```json
1600+
[{
1601+
"states": [{
1602+
"name": "handleOrder",
1603+
"type": "operation",
1604+
"actions": [
1605+
{
1606+
"name": "sendOrderConfirmation",
1607+
"functionRef": {
1608+
"refName": "sendOrderConfirmation",
1609+
"arguments": {
1610+
"order": "${ .order }"
1611+
}
1612+
}
1613+
}
1614+
],
1615+
"transition": "emailCustomer"
1616+
}]
1617+
}]
1618+
```
1619+
1620+
Note that custom function types are not portable across runtimes.
1621+
15681622
### Workflow Expressions
15691623

15701624
Workflow model parameters can use expressions to select/manipulate workflow and/or state data.
@@ -3136,7 +3190,7 @@ section.
31363190
| --- | --- | --- | --- |
31373191
| name | Unique function name | string | yes |
31383192
| operation | If type is `rest`, <path_to_openapi_definition>#<operation_id>. If type is `asyncapi`, <path_to_asyncapi_definition>#<operation_id>. If type is `rpc`, <path_to_grpc_proto_file>#<service_name>#<service_method>. If type is `graphql`, <url_to_graphql_endpoint>#<literal \"mutation\" or \"query\">#<query_or_mutation_name>. If type is `odata`, <URI_to_odata_service>#<Entity_Set_Name>. If type is `expression`, defines the workflow expression. | string | no |
3139-
| type | Defines the function type. Is either `rest`, `asyncapi`, `rpc`, `graphql`, `odata` or `expression`. Default is `rest` | enum | no |
3193+
| type | Defines the function type. Can be either `rest`, `asyncapi`, `rpc`, `graphql`, `odata`, `expression`, or [`custom`](#defining-custom-function-types). Default is `rest` | enum | no |
31403194
| authRef | References an [auth definition](#Auth-Definition) name to be used to access to resource defined in the operation parameter | string | no |
31413195
| [metadata](#Workflow-Metadata) | Metadata information. Can be used to define custom function information | object | no |
31423196

@@ -3190,6 +3244,8 @@ Depending on the function `type`, the `operation` property can be:
31903244
For example `https://https://services.odata.org/V3/OData/OData.svc#Products`.
31913245
* If `type` is `expression`, defines the expression syntax. Take a look at the [workflow expressions section](#Workflow-Expressions) for more information on this.
31923246

3247+
Defining custom function types is possible, for more information on that refer to the [Defining custom function types](#defining-custom-function-types) section.
3248+
31933249
The `authRef` property references a name of a defined workflow [auth definition](#Auth-Definition).
31943250
It is used to provide authentication info to access the resource defined in the `operation` property.
31953251

0 commit comments

Comments
 (0)