Skip to content

Added support for extensions #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ public async Task Validate_Workflow_WithExternalInputDataSchema_ShouldWork()
deserializedWorkflow.DataInputSchemaUri.Should().NotBeNull();
}

[Fact]
public async Task Validate_Workflow_WithExtensions_ShouldWork()
{
//arrange
var json = File.ReadAllText(Path.Combine("resources", "workflows", "extended.json"));
var workflow = JsonConvert.DeserializeObject<WorkflowDefinition>(json);

//act
var result = await this.WorkflowValidator.ValidateAsync(workflow);
var loadedWorflowJson = JsonConvert.SerializeObject(workflow);
var deserializedWorkflow = JsonConvert.DeserializeObject<WorkflowDefinition>(loadedWorflowJson);

//assert
result.IsValid.Should().BeTrue();
deserializedWorkflow.Extensions.Should().NotBeNull();
}

}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"schema": "file://resources/schemas/input-data.json"
"schema": "file://resources/schemas/input-data.json",
"failOnValidationErrors": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"type": "object",
"properties": {
"states": {
"items": {
"anyOf": [
{
"$ref": "#/definitions/x-aws-step-function-state"
}
]
}
}
},
"definitions": {
"x-aws-step-function-state": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "State name"
},
"type": {
"type": "string",
"const": "x-aws-step-function",
"description": "State type"
},
"functions": {
"type": "array",
"minLength": 1,
"items": {
"$ref": "#/definitions/x-aws-step-function"
}
},
"end": {
"$ref": "#/definitions/end",
"description": "State end definition"
},
"transition": {
"description": "Next transition of the workflow after the state",
"$ref": "#/definitions/transition"
},
"metadata": {
"$ref": "common.json#/definitions/metadata"
}
},
"required": [ "name", "type", "functions" ],
"additionalProperties": false
},
"x-aws-step-function": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"payload": {
"type": "object"
}
},
"required": [ "name" ]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"id": "extended-workflow",
"name": "Extended workflow",
"version": "1.0.0",
"specVersion": "0.8",
"extensions": [
{
"extensionId": "customState",
"resource": "resources\\extensions\\state-type-extension.json"
}
],
"states": [
{
"name": "AWS Step Function State",
"type": "x-aws-step-function",
"functions": [
{
"name": "arn:aws:lambda:us-east-1:YOUR_ACCCOUNT_NUMBER:function:ApiCaller:$LATEST",
"payload": {}
}
],
"end": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"version": "0.1.0",
"specVersion": "0.8",
"dataInputSchema": {
"schema": "file://resources/schemas/input-data.json"
"schema": "file://resources/schemas/input-data.json",
"failOnValidationErrors": false
},
"states": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<None Update="Resources\events\petstore.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\extensions\state-type-extension.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\functions\petstore.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand All @@ -68,6 +71,9 @@
<None Update="Resources\secrets\default.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\workflows\extended.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\workflows\external-function-definition.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
31 changes: 13 additions & 18 deletions src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,23 @@
* limitations under the License.
*
*/
using System.Runtime.Serialization;

namespace ServerlessWorkflow.Sdk.Models
namespace ServerlessWorkflow.Sdk.Models;

/// <summary>
/// Enumerates all types of actions
/// </summary>
public static class ActionExecutionMode
{

/// <summary>
/// Enumerates all types of actions
/// Indicates a sequential execution of actions
/// </summary>
public const string Sequential = "sequential";

/// <summary>
/// Indicates a parallel execution of actions
/// </summary>
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
public enum ActionExecutionMode
{
/// <summary>
/// Indicates a sequential execution of actions
/// </summary>
[EnumMember(Value = "sequential")]
Sequential,
/// <summary>
/// Indicates a parallel execution of actions
/// </summary>
[EnumMember(Value = "parallel")]
Parallel
}
public const string Parallel = "parallel";

}
41 changes: 18 additions & 23 deletions src/ServerlessWorkflow.Sdk/ActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,28 @@
* limitations under the License.
*
*/
using System.Runtime.Serialization;

namespace ServerlessWorkflow.Sdk
namespace ServerlessWorkflow.Sdk;

/// <summary>
/// Enumerates all types of actions
/// </summary>
public static class ActionType
{

/// <summary>
/// Enumerates all types of actions
/// Indicates an action that invokes a function
/// </summary>
public const string Function = "function";

/// <summary>
/// Indicates an action that executes a cloud event trigger
/// </summary>
public const string Trigger = "trigger";

/// <summary>
/// Indicates an action that executes a subflow
/// </summary>
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
public enum ActionType
{
/// <summary>
/// Indicates an action that invokes a function
/// </summary>
[EnumMember(Value = "function")]
Function = 1,
/// <summary>
/// Indicates an action that executes a cloud event trigger
/// </summary>
[EnumMember(Value = "trigger")]
Trigger = 2,
/// <summary>
/// Indicates an action that executes a subflow
/// </summary>
[EnumMember(Value = "subflow")]
Subflow = 4
}
public const string Subflow = "subflow";

}
40 changes: 18 additions & 22 deletions src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@
*
*/

namespace ServerlessWorkflow.Sdk
namespace ServerlessWorkflow.Sdk;

/// <summary>
/// Enumerates all supported authentication schemes
/// </summary>
public static class AuthenticationScheme
{

/// <summary>
/// Enumerates all supported authentication schemes
/// Indicates the basic (username/password) authentication scheme
/// </summary>
public const string Basic = "basic";

/// <summary>
/// Indicates the bearer (JwT) authentication scheme
/// </summary>
public const string Bearer = "bearer";

/// <summary>
/// Indicates the OAuth 2 authentication scheme
/// </summary>
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
public enum AuthenticationScheme
{
/// <summary>
/// Indicates the basic (username/password) authentication scheme
/// </summary>
[EnumMember(Value = "basic")]
Basic = 1,
/// <summary>
/// Indicates the bearer (JwT) authentication scheme
/// </summary>
[EnumMember(Value = "bearer")]
Bearer = 2,
/// <summary>
/// Indicates the OAuth 2 authentication scheme
/// </summary>
[EnumMember(Value = "oauth2")]
OAuth2 = 4
}
public const string OAuth2 = "oauth2";

}
31 changes: 13 additions & 18 deletions src/ServerlessWorkflow.Sdk/EventKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,23 @@
* limitations under the License.
*
*/
using System.Runtime.Serialization;

namespace ServerlessWorkflow.Sdk
namespace ServerlessWorkflow.Sdk;

/// <summary>
/// Enumerates all kinds of workflow events
/// </summary>
public static class EventKind
{

/// <summary>
/// Enumerates all kinds of workflow events
/// Indicates an event to consume
/// </summary>
public const string Consumed = "consumed";

/// <summary>
/// Indicates an event to produce
/// </summary>
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))]
public enum EventKind
{
/// <summary>
/// Indicates an event to consume
/// </summary>
[EnumMember(Value = "consumed")]
Consumed = 1,
/// <summary>
/// Indicates an event to produce
/// </summary>
[EnumMember(Value = "produced")]
Produced = 2
}
public const string Produced = "produced";

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static class WorkflowDefinitionExtensions
/// <param name="workflow">The <see cref="WorkflowDefinition"/> to query</param>
/// <param name="type">The type of <see cref="ActionDefinition"/>s to get. A null value gets all <see cref="ActionDefinition"/>s</param>
/// <returns>A new <see cref="IEnumerable{T}"/> containing the <see cref="ActionDefinition"/>s of the specified type declared in the <see cref="WorkflowDefinition"/></returns>
public static IEnumerable<ActionDefinition> GetActions(this WorkflowDefinition workflow, ActionType? type = null)
public static IEnumerable<ActionDefinition> GetActions(this WorkflowDefinition workflow, string? type = null)
{
var actions = workflow.States.SelectMany(s => s switch
{
Expand All @@ -44,8 +44,7 @@ public static IEnumerable<ActionDefinition> GetActions(this WorkflowDefinition w
ParallelStateDefinition parallelState => parallelState.Branches.SelectMany(b => b.Actions),
_ => Array.Empty<ActionDefinition>()
});
if (type.HasValue)
actions = actions.Where(a => a.Type == type.Value);
if (!string.IsNullOrWhiteSpace(type)) actions = actions.Where(a => a.Type == type);
return actions;
}

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy