Skip to content

Commit 355ff0f

Browse files
committed
fix(Sdk): Added support for extensions
fix(Sdk): Made most workflow components extensible
1 parent c722620 commit 355ff0f

File tree

61 files changed

+1503
-1268
lines changed

Some content is hidden

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

61 files changed

+1503
-1268
lines changed

src/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,23 @@ public async Task Validate_Workflow_WithExternalInputDataSchema_ShouldWork()
338338
deserializedWorkflow.DataInputSchemaUri.Should().NotBeNull();
339339
}
340340

341+
[Fact]
342+
public async Task Validate_Workflow_WithExtensions_ShouldWork()
343+
{
344+
//arrange
345+
var json = File.ReadAllText(Path.Combine("resources", "workflows", "extended.json"));
346+
var workflow = JsonConvert.DeserializeObject<WorkflowDefinition>(json);
347+
348+
//act
349+
var result = await this.WorkflowValidator.ValidateAsync(workflow);
350+
var loadedWorflowJson = JsonConvert.SerializeObject(workflow);
351+
var deserializedWorkflow = JsonConvert.DeserializeObject<WorkflowDefinition>(loadedWorflowJson);
352+
353+
//assert
354+
result.IsValid.Should().BeTrue();
355+
deserializedWorkflow.Extensions.Should().NotBeNull();
356+
}
357+
341358
}
342359

343360
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"schema": "file://resources/schemas/input-data.json"
2+
"schema": "file://resources/schemas/input-data.json",
3+
"failOnValidationErrors": false
34
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"states": {
5+
"items": {
6+
"anyOf": [
7+
{
8+
"$ref": "#/definitions/x-aws-step-function-state"
9+
}
10+
]
11+
}
12+
}
13+
},
14+
"definitions": {
15+
"x-aws-step-function-state": {
16+
"type": "object",
17+
"properties": {
18+
"name": {
19+
"type": "string",
20+
"description": "State name"
21+
},
22+
"type": {
23+
"type": "string",
24+
"const": "x-aws-step-function",
25+
"description": "State type"
26+
},
27+
"functions": {
28+
"type": "array",
29+
"minLength": 1,
30+
"items": {
31+
"$ref": "#/definitions/x-aws-step-function"
32+
}
33+
},
34+
"end": {
35+
"$ref": "#/definitions/end",
36+
"description": "State end definition"
37+
},
38+
"transition": {
39+
"description": "Next transition of the workflow after the state",
40+
"$ref": "#/definitions/transition"
41+
},
42+
"metadata": {
43+
"$ref": "common.json#/definitions/metadata"
44+
}
45+
},
46+
"required": [ "name", "type", "functions" ],
47+
"additionalProperties": false
48+
},
49+
"x-aws-step-function": {
50+
"type": "object",
51+
"properties": {
52+
"name": {
53+
"type": "string",
54+
"minLength": 1
55+
},
56+
"payload": {
57+
"type": "object"
58+
}
59+
},
60+
"required": [ "name" ]
61+
}
62+
}
63+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"id": "extended-workflow",
3+
"name": "Extended workflow",
4+
"version": "1.0.0",
5+
"specVersion": "0.8",
6+
"extensions": [
7+
{
8+
"extensionId": "customState",
9+
"resource": "resources\\extensions\\state-type-extension.json"
10+
}
11+
],
12+
"states": [
13+
{
14+
"name": "AWS Step Function State",
15+
"type": "x-aws-step-function",
16+
"functions": [
17+
{
18+
"name": "arn:aws:lambda:us-east-1:YOUR_ACCCOUNT_NUMBER:function:ApiCaller:$LATEST",
19+
"payload": {}
20+
}
21+
],
22+
"end": true
23+
}
24+
]
25+
}

src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "0.1.0",
55
"specVersion": "0.8",
66
"dataInputSchema": {
7-
"schema": "file://resources/schemas/input-data.json"
7+
"schema": "file://resources/schemas/input-data.json",
8+
"failOnValidationErrors": false
89
},
910
"states": [
1011
{

src/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<None Update="Resources\events\petstore.json">
4545
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4646
</None>
47+
<None Update="Resources\extensions\state-type-extension.json">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</None>
4750
<None Update="Resources\functions\petstore.json">
4851
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4952
</None>
@@ -68,6 +71,9 @@
6871
<None Update="Resources\secrets\default.yaml">
6972
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7073
</None>
74+
<None Update="Resources\workflows\extended.json">
75+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
76+
</None>
7177
<None Update="Resources\workflows\external-function-definition.json">
7278
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7379
</None>

src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,23 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
using System.Runtime.Serialization;
1817

19-
namespace ServerlessWorkflow.Sdk.Models
18+
namespace ServerlessWorkflow.Sdk.Models;
19+
20+
/// <summary>
21+
/// Enumerates all types of actions
22+
/// </summary>
23+
public static class ActionExecutionMode
2024
{
2125

2226
/// <summary>
23-
/// Enumerates all types of actions
27+
/// Indicates a sequential execution of actions
28+
/// </summary>
29+
public const string Sequential = "sequential";
30+
31+
/// <summary>
32+
/// Indicates a parallel execution of actions
2433
/// </summary>
25-
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
26-
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
27-
public enum ActionExecutionMode
28-
{
29-
/// <summary>
30-
/// Indicates a sequential execution of actions
31-
/// </summary>
32-
[EnumMember(Value = "sequential")]
33-
Sequential,
34-
/// <summary>
35-
/// Indicates a parallel execution of actions
36-
/// </summary>
37-
[EnumMember(Value = "parallel")]
38-
Parallel
39-
}
34+
public const string Parallel = "parallel";
4035

4136
}

src/ServerlessWorkflow.Sdk/ActionType.cs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,28 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
using System.Runtime.Serialization;
1817

19-
namespace ServerlessWorkflow.Sdk
18+
namespace ServerlessWorkflow.Sdk;
19+
20+
/// <summary>
21+
/// Enumerates all types of actions
22+
/// </summary>
23+
public static class ActionType
2024
{
2125

2226
/// <summary>
23-
/// Enumerates all types of actions
27+
/// Indicates an action that invokes a function
28+
/// </summary>
29+
public const string Function = "function";
30+
31+
/// <summary>
32+
/// Indicates an action that executes a cloud event trigger
33+
/// </summary>
34+
public const string Trigger = "trigger";
35+
36+
/// <summary>
37+
/// Indicates an action that executes a subflow
2438
/// </summary>
25-
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
26-
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
27-
public enum ActionType
28-
{
29-
/// <summary>
30-
/// Indicates an action that invokes a function
31-
/// </summary>
32-
[EnumMember(Value = "function")]
33-
Function = 1,
34-
/// <summary>
35-
/// Indicates an action that executes a cloud event trigger
36-
/// </summary>
37-
[EnumMember(Value = "trigger")]
38-
Trigger = 2,
39-
/// <summary>
40-
/// Indicates an action that executes a subflow
41-
/// </summary>
42-
[EnumMember(Value = "subflow")]
43-
Subflow = 4
44-
}
39+
public const string Subflow = "subflow";
4540

4641
}

src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,27 @@
1515
*
1616
*/
1717

18-
namespace ServerlessWorkflow.Sdk
18+
namespace ServerlessWorkflow.Sdk;
19+
20+
/// <summary>
21+
/// Enumerates all supported authentication schemes
22+
/// </summary>
23+
public static class AuthenticationScheme
1924
{
2025

2126
/// <summary>
22-
/// Enumerates all supported authentication schemes
27+
/// Indicates the basic (username/password) authentication scheme
28+
/// </summary>
29+
public const string Basic = "basic";
30+
31+
/// <summary>
32+
/// Indicates the bearer (JwT) authentication scheme
33+
/// </summary>
34+
public const string Bearer = "bearer";
35+
36+
/// <summary>
37+
/// Indicates the OAuth 2 authentication scheme
2338
/// </summary>
24-
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
25-
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
26-
public enum AuthenticationScheme
27-
{
28-
/// <summary>
29-
/// Indicates the basic (username/password) authentication scheme
30-
/// </summary>
31-
[EnumMember(Value = "basic")]
32-
Basic = 1,
33-
/// <summary>
34-
/// Indicates the bearer (JwT) authentication scheme
35-
/// </summary>
36-
[EnumMember(Value = "bearer")]
37-
Bearer = 2,
38-
/// <summary>
39-
/// Indicates the OAuth 2 authentication scheme
40-
/// </summary>
41-
[EnumMember(Value = "oauth2")]
42-
OAuth2 = 4
43-
}
39+
public const string OAuth2 = "oauth2";
4440

4541
}

src/ServerlessWorkflow.Sdk/EventKind.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,23 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
using System.Runtime.Serialization;
1817

19-
namespace ServerlessWorkflow.Sdk
18+
namespace ServerlessWorkflow.Sdk;
19+
20+
/// <summary>
21+
/// Enumerates all kinds of workflow events
22+
/// </summary>
23+
public static class EventKind
2024
{
2125

2226
/// <summary>
23-
/// Enumerates all kinds of workflow events
27+
/// Indicates an event to consume
28+
/// </summary>
29+
public const string Consumed = "consumed";
30+
31+
/// <summary>
32+
/// Indicates an event to produce
2433
/// </summary>
25-
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
26-
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
27-
public enum EventKind
28-
{
29-
/// <summary>
30-
/// Indicates an event to consume
31-
/// </summary>
32-
[EnumMember(Value = "consumed")]
33-
Consumed = 1,
34-
/// <summary>
35-
/// Indicates an event to produce
36-
/// </summary>
37-
[EnumMember(Value = "produced")]
38-
Produced = 2
39-
}
34+
public const string Produced = "produced";
4035

4136
}

0 commit comments

Comments
 (0)