diff --git a/src/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs b/src/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs index c333e46..3e2137f 100644 --- a/src/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs +++ b/src/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs @@ -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(json); + + //act + var result = await this.WorkflowValidator.ValidateAsync(workflow); + var loadedWorflowJson = JsonConvert.SerializeObject(workflow); + var deserializedWorkflow = JsonConvert.DeserializeObject(loadedWorflowJson); + + //assert + result.IsValid.Should().BeTrue(); + deserializedWorkflow.Extensions.Should().NotBeNull(); + } + } } diff --git a/src/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json index af56589..819b7e4 100644 --- a/src/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json +++ b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json @@ -1,3 +1,4 @@ { - "schema": "file://resources/schemas/input-data.json" + "schema": "file://resources/schemas/input-data.json", + "failOnValidationErrors": false } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.UnitTests/Resources/extensions/state-type-extension.json b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/extensions/state-type-extension.json new file mode 100644 index 0000000..ae6e80d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/extensions/state-type-extension.json @@ -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" ] + } + } +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/extended.json b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/extended.json new file mode 100644 index 0000000..e9ae04c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/extended.json @@ -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 + } + ] +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json index 67c150b..fbb5355 100644 --- a/src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json +++ b/src/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json @@ -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": [ { diff --git a/src/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj b/src/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj index e24ec1e..e304c82 100644 --- a/src/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj +++ b/src/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj @@ -44,6 +44,9 @@ Always + + PreserveNewest + Always @@ -68,6 +71,9 @@ Always + + PreserveNewest + PreserveNewest diff --git a/src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs b/src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs index c1b5e64..d8d3e18 100644 --- a/src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs +++ b/src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs @@ -14,28 +14,23 @@ * limitations under the License. * */ -using System.Runtime.Serialization; -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Enumerates all types of actions +/// +public static class ActionExecutionMode { /// - /// Enumerates all types of actions + /// Indicates a sequential execution of actions + /// + public const string Sequential = "sequential"; + + /// + /// Indicates a parallel execution of actions /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum ActionExecutionMode - { - /// - /// Indicates a sequential execution of actions - /// - [EnumMember(Value = "sequential")] - Sequential, - /// - /// Indicates a parallel execution of actions - /// - [EnumMember(Value = "parallel")] - Parallel - } + public const string Parallel = "parallel"; } diff --git a/src/ServerlessWorkflow.Sdk/ActionType.cs b/src/ServerlessWorkflow.Sdk/ActionType.cs index 32f308f..f6ee57f 100644 --- a/src/ServerlessWorkflow.Sdk/ActionType.cs +++ b/src/ServerlessWorkflow.Sdk/ActionType.cs @@ -14,33 +14,28 @@ * limitations under the License. * */ -using System.Runtime.Serialization; -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all types of actions +/// +public static class ActionType { /// - /// Enumerates all types of actions + /// Indicates an action that invokes a function + /// + public const string Function = "function"; + + /// + /// Indicates an action that executes a cloud event trigger + /// + public const string Trigger = "trigger"; + + /// + /// Indicates an action that executes a subflow /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum ActionType - { - /// - /// Indicates an action that invokes a function - /// - [EnumMember(Value = "function")] - Function = 1, - /// - /// Indicates an action that executes a cloud event trigger - /// - [EnumMember(Value = "trigger")] - Trigger = 2, - /// - /// Indicates an action that executes a subflow - /// - [EnumMember(Value = "subflow")] - Subflow = 4 - } + public const string Subflow = "subflow"; } diff --git a/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs b/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs index 6018bce..39cde8c 100644 --- a/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs +++ b/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs @@ -15,31 +15,27 @@ * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all supported authentication schemes +/// +public static class AuthenticationScheme { /// - /// Enumerates all supported authentication schemes + /// Indicates the basic (username/password) authentication scheme + /// + public const string Basic = "basic"; + + /// + /// Indicates the bearer (JwT) authentication scheme + /// + public const string Bearer = "bearer"; + + /// + /// Indicates the OAuth 2 authentication scheme /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum AuthenticationScheme - { - /// - /// Indicates the basic (username/password) authentication scheme - /// - [EnumMember(Value = "basic")] - Basic = 1, - /// - /// Indicates the bearer (JwT) authentication scheme - /// - [EnumMember(Value = "bearer")] - Bearer = 2, - /// - /// Indicates the OAuth 2 authentication scheme - /// - [EnumMember(Value = "oauth2")] - OAuth2 = 4 - } + public const string OAuth2 = "oauth2"; } diff --git a/src/ServerlessWorkflow.Sdk/EventKind.cs b/src/ServerlessWorkflow.Sdk/EventKind.cs index 76de686..1fad3c1 100644 --- a/src/ServerlessWorkflow.Sdk/EventKind.cs +++ b/src/ServerlessWorkflow.Sdk/EventKind.cs @@ -14,28 +14,23 @@ * limitations under the License. * */ -using System.Runtime.Serialization; -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all kinds of workflow events +/// +public static class EventKind { /// - /// Enumerates all kinds of workflow events + /// Indicates an event to consume + /// + public const string Consumed = "consumed"; + + /// + /// Indicates an event to produce /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum EventKind - { - /// - /// Indicates an event to consume - /// - [EnumMember(Value = "consumed")] - Consumed = 1, - /// - /// Indicates an event to produce - /// - [EnumMember(Value = "produced")] - Produced = 2 - } + public const string Produced = "produced"; } diff --git a/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs index c3471cc..6e36feb 100644 --- a/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs +++ b/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs @@ -33,7 +33,7 @@ public static class WorkflowDefinitionExtensions /// The to query /// The type of s to get. A null value gets all s /// A new containing the s of the specified type declared in the - public static IEnumerable GetActions(this WorkflowDefinition workflow, ActionType? type = null) + public static IEnumerable GetActions(this WorkflowDefinition workflow, string? type = null) { var actions = workflow.States.SelectMany(s => s switch { @@ -44,8 +44,7 @@ public static IEnumerable GetActions(this WorkflowDefinition w ParallelStateDefinition parallelState => parallelState.Branches.SelectMany(b => b.Actions), _ => Array.Empty() }); - if (type.HasValue) - actions = actions.Where(a => a.Type == type.Value); + if (!string.IsNullOrWhiteSpace(type)) actions = actions.Where(a => a.Type == type); return actions; } diff --git a/src/ServerlessWorkflow.Sdk/FunctionType.cs b/src/ServerlessWorkflow.Sdk/FunctionType.cs index 068f0f6..e247bba 100644 --- a/src/ServerlessWorkflow.Sdk/FunctionType.cs +++ b/src/ServerlessWorkflow.Sdk/FunctionType.cs @@ -14,46 +14,41 @@ * limitations under the License. * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all types of functions +/// +public static class FunctionType { /// - /// Enumerates all types of functions + /// Indicates a REST function + /// + public const string Rest = "rest"; + + /// + /// Indicates an Remote Procedure Call (RPC) + /// + public const string Rpc = "rpc"; + + /// + /// Indicates a GraphQL function + /// + public const string GraphQL = "graphql"; + + /// + /// Indicates an OData function + /// + public const string OData = "odata"; + /// + /// Indicates an expression function + /// + public const string Expression = "expression"; + + /// + /// Indicates an Async API function /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum FunctionType - { - /// - /// Indicates a REST function - /// - [EnumMember(Value = "rest")] - Rest = 1, - /// - /// Indicates an Remote Procedure Call (RPC) - /// - [EnumMember(Value = "rpc")] - Rpc = 2, - /// - /// Indicates a GraphQL function - /// - [EnumMember(Value = "graphql")] - GraphQL = 4, - /// - /// Indicates an OData function - /// - [EnumMember(Value = "odata")] - OData = 8, - /// - /// Indicates an expression function - /// - [EnumMember(Value = "expression")] - Expression = 16, - /// - /// Indicates an Async API function - /// - [EnumMember(Value = "asyncapi")] - AsyncApi = 32 - } + public const string AsyncApi = "asyncapi"; } diff --git a/src/ServerlessWorkflow.Sdk/InvocationMode.cs b/src/ServerlessWorkflow.Sdk/InvocationMode.cs index e4c2904..9ea7ae5 100644 --- a/src/ServerlessWorkflow.Sdk/InvocationMode.cs +++ b/src/ServerlessWorkflow.Sdk/InvocationMode.cs @@ -14,25 +14,22 @@ * limitations under the License. * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all invocation modes +/// +public static class InvocationMode { + + /// + /// Indicates a synchronous invocation mode + /// + public const string Synchronous = "sync"; + /// - /// Enumerates all invocation modes + /// Indicates an asynchronous invocation mode /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum InvocationMode - { - /// - /// Indicates a synchronous invocation mode - /// - [EnumMember(Value = "sync")] - Synchronous, - /// - /// Indicates an asynchronous invocation mode - /// - [EnumMember(Value = "async")] - Asynchronous - } + public const string Asynchronous = "async"; } diff --git a/src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs index 5d952dc..9cd09a1 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs @@ -14,196 +14,198 @@ * limitations under the License. * */ -using System; -using System.Collections.Generic; -using System.Linq; -using YamlDotNet.Serialization; -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the object used to define a workflow action +/// +[ProtoContract] +[DataContract] +public class ActionDefinition { /// - /// Represents the object used to define a workflow action + /// Gets/sets the unique action definition name /// - [ProtoContract] - [DataContract] - public class ActionDefinition - { + [ProtoMember(1)] + [DataMember(Order = 1)] + public virtual string? Name { get; set; } - /// - /// Gets/sets the unique action definition name - /// - [ProtoMember(1)] - [DataMember(Order = 1)] - public virtual string? Name { get; set; } - - /// - /// Gets the 's type - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - public virtual ActionType Type + /// + /// Gets the 's type + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + public virtual string Type + { + get { - get - { - if (this.Function != null) - return ActionType.Function; - else if (this.Event != null) - return ActionType.Trigger; - else if (this.Subflow != null) - return ActionType.Subflow; - else - throw new InvalidOperationException("Failed to determine the action type"); - } + if (this.Function != null) + return ActionType.Function; + else if (this.Event != null) + return ActionType.Trigger; + else if (this.Subflow != null) + return ActionType.Subflow; + else + return string.Empty; } + } - /// - /// Gets/sets a that represents the function to invoke - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "functionRef")] - [System.Text.Json.Serialization.JsonPropertyName("functionRef")] - [YamlMember(Alias = "functionRef")] - [ProtoMember(2, Name = "functionRef")] - [DataMember(Order = 2, Name = "functionRef")] - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] - protected virtual OneOf? FunctionValue { get; set; } - - /// - /// Gets the object used to configure the reference of the function to invoke - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual FunctionReference? Function + /// + /// Gets/sets a that represents the function to invoke + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "functionRef")] + [System.Text.Json.Serialization.JsonPropertyName("functionRef")] + [YamlMember(Alias = "functionRef")] + [ProtoMember(2, Name = "functionRef")] + [DataMember(Order = 2, Name = "functionRef")] + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] + protected virtual OneOf? FunctionValue { get; set; } + + /// + /// Gets the object used to configure the reference of the function to invoke + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual FunctionReference? Function + { + get { - get - { - if (this.FunctionValue?.T1Value == null - && !string.IsNullOrWhiteSpace(this.FunctionValue?.T2Value)) - return new FunctionReference() { RefName = this.FunctionValue.T2Value }; - else - return this.FunctionValue?.T1Value; - } - set - { - if (value == null) - this.FunctionValue = null; + if (this.FunctionValue?.T1Value == null + && !string.IsNullOrWhiteSpace(this.FunctionValue?.T2Value)) + return new FunctionReference() { RefName = this.FunctionValue.T2Value }; else - this.FunctionValue = value; - } + return this.FunctionValue?.T1Value; + } + set + { + if (value == null) + this.FunctionValue = null; + else + this.FunctionValue = value; } + } + + /// + /// Gets the object used to configure the reference of the event to produce or consume + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "eventRef")] + [System.Text.Json.Serialization.JsonPropertyName("eventRef")] + [YamlMember(Alias = "eventRef")] + [ProtoMember(3, Name = "eventRef")] + [DataMember(Order = 3, Name = "eventRef")] + public virtual EventReference? Event { get; set; } + + /// + /// Gets/sets a that references a subflow to run + /// + [YamlMember(Alias = "subFlowRef")] + [ProtoMember(4, Name = "subFlowRef")] + [DataMember(Order = 4, Name = "subFlowRef")] + [Newtonsoft.Json.JsonProperty(PropertyName = "subFlowRef"), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] + [System.Text.Json.Serialization.JsonPropertyName("subFlowRef"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] + protected virtual OneOf? SubflowValue { get; set; } - /// - /// Gets the object used to configure the reference of the event to produce or consume - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "eventRef")] - [System.Text.Json.Serialization.JsonPropertyName("eventRef")] - [YamlMember(Alias = "eventRef")] - [ProtoMember(3, Name = "eventRef")] - [DataMember(Order = 3, Name = "eventRef")] - public virtual EventReference? Event { get; set; } - - /// - /// Gets/sets a that references a subflow to run - /// - [YamlMember(Alias = "subFlowRef")] - [ProtoMember(4, Name = "subFlowRef")] - [DataMember(Order = 4, Name = "subFlowRef")] - [Newtonsoft.Json.JsonProperty(PropertyName = "subFlowRef"), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] - [System.Text.Json.Serialization.JsonPropertyName("subFlowRef"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] - protected virtual OneOf? SubflowValue { get; set; } - - /// - /// Gets the object used to configure the reference of the subflow to run - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual SubflowReference? Subflow + /// + /// Gets the object used to configure the reference of the subflow to run + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual SubflowReference? Subflow + { + get { - get + if (this.SubflowValue?.T1Value == null + && !string.IsNullOrWhiteSpace(this.SubflowValue?.T2Value)) { - if (this.SubflowValue?.T1Value == null - && !string.IsNullOrWhiteSpace(this.SubflowValue?.T2Value)) + var components = this.SubflowValue.T2Value.Split(':', StringSplitOptions.RemoveEmptyEntries); + var id = components.First(); + var version = null as string; + if (components.Length > 1) { - var components = this.SubflowValue.T2Value.Split(':', StringSplitOptions.RemoveEmptyEntries); - var id = components.First(); - var version = null as string; - if (components.Length > 1) - { - version = components.Last(); - id = this.SubflowValue.T2Value[..^(version.Length + 1)]; - } - return new() { WorkflowId = id, Version = version }; + version = components.Last(); + id = this.SubflowValue.T2Value[..^(version.Length + 1)]; } - return this.SubflowValue?.T1Value; - } - set - { - if (value == null) - this.SubflowValue = null; - else - this.SubflowValue = value; + return new() { WorkflowId = id, Version = version }; } + return this.SubflowValue?.T1Value; } - - /// - /// Gets/sets the name of the workflow retry definition to use. If not defined uses the default runtime retry definition - /// - [ProtoMember(5)] - [DataMember(Order = 5)] - public virtual string? RetryRef { get; set; } - - /// - /// Gets/sets a containing references to defined s for which the action should not be retried. Used only when `` is set to `true` - /// - [ProtoMember(6)] - [DataMember(Order = 6)] - public virtual List? NonRetryableErrors { get; set; } - - /// - /// Gets/sets a containing references to defined s for which the action should be retried. Used only when `` is set to `false` - /// - [ProtoMember(7)] - [DataMember(Order = 7)] - public virtual List? RetryableErrors { get; set; } - - /// - /// Gets/sets an object used to define the way to filter the action's data - /// - [ProtoMember(8)] - [DataMember(Order = 8)] - public ActionDataFilterDefinition? ActionDataFilter { get; set; } - - /// - /// Gets/sets the 's execution delay configuration - /// - [ProtoMember(9)] - [DataMember(Order = 9)] - public virtual ActionExecutionDelayDefinition? Sleep { get; set; } - - /// - /// Gets/sets an expression to be evaluated positively as a condition for the to execute. - /// - [ProtoMember(10)] - [DataMember(Order = 10)] - public virtual string? Condition { get; set; } - - /// - public override string? ToString() + set { - if (string.IsNullOrWhiteSpace(this.Name)) - return base.ToString(); + if (value == null) + this.SubflowValue = null; else - return this.Name; + this.SubflowValue = value; } + } + /// + /// Gets/sets the name of the workflow retry definition to use. If not defined uses the default runtime retry definition + /// + [ProtoMember(5)] + [DataMember(Order = 5)] + public virtual string? RetryRef { get; set; } + + /// + /// Gets/sets a containing references to defined s for which the action should not be retried. Used only when `` is set to `true` + /// + [ProtoMember(6)] + [DataMember(Order = 6)] + public virtual List? NonRetryableErrors { get; set; } + + /// + /// Gets/sets a containing references to defined s for which the action should be retried. Used only when `` is set to `false` + /// + [ProtoMember(7)] + [DataMember(Order = 7)] + public virtual List? RetryableErrors { get; set; } + + /// + /// Gets/sets an object used to define the way to filter the action's data + /// + [ProtoMember(8)] + [DataMember(Order = 8)] + public ActionDataFilterDefinition? ActionDataFilter { get; set; } + + /// + /// Gets/sets the 's execution delay configuration + /// + [ProtoMember(9)] + [DataMember(Order = 9)] + public virtual ActionExecutionDelayDefinition? Sleep { get; set; } + + /// + /// Gets/sets an expression to be evaluated positively as a condition for the to execute. + /// + [ProtoMember(10)] + [DataMember(Order = 10)] + public virtual string? Condition { get; set; } + + /// + /// Gets/sets an containing the 's extension properties + /// + [ProtoMember(11)] + [DataMember(Order = 11)] + [Newtonsoft.Json.JsonExtensionData] + [System.Text.Json.Serialization.JsonExtensionData] + public virtual IDictionary? ExtensionProperties { get; set; } + + /// + public override string? ToString() + { + if (string.IsNullOrWhiteSpace(this.Name)) + return base.ToString(); + else + return this.Name; } } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs index cf53a2e..b43d3d4 100644 --- a/src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs @@ -47,7 +47,7 @@ public class AuthenticationDefinition [YamlMember(Alias = "scheme")] [ProtoMember(2, Name = "scheme")] [DataMember(Order = 2, Name = "scheme")] - public virtual AuthenticationScheme Scheme { get; set; } + public virtual string Scheme { get; set; } = null!; /// /// Gets/sets a that represents the 's @@ -81,7 +81,7 @@ public virtual AuthenticationProperties Properties AuthenticationScheme.Basic => this.PropertiesValue.T1Value.ToObject(), AuthenticationScheme.Bearer => this.PropertiesValue.T1Value.ToObject(), AuthenticationScheme.OAuth2 => this.PropertiesValue.T1Value.ToObject(), - _ => throw new NotSupportedException($"The specified authentication scheme '{EnumHelper.Stringify(this.Scheme)}' is not supported") + _ => throw new NotSupportedException($"The specified authentication scheme '{this.Scheme}' is not supported") }; } set diff --git a/src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs index fb2c04f..d42abaf 100644 --- a/src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs @@ -43,7 +43,7 @@ public class BranchDefinition /// [ProtoMember(2)] [DataMember(Order = 2)] - public virtual ActionExecutionMode ActionMode { get; set; } + public virtual string ActionMode { get; set; } = ActionExecutionMode.Sequential; /// /// Gets/sets an containing the actions to be executed in this branch diff --git a/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs index 607a1f9..9e325b9 100644 --- a/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs @@ -14,86 +14,91 @@ * limitations under the License. * */ -using System.Collections.Generic; + using System.ComponentModel; using System.ComponentModel.DataAnnotations; -using YamlDotNet.Serialization; -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents an object used to define events and their correlations +/// +[ProtoContract] +[DataContract] +public class EventDefinition { /// - /// Represents an object used to define events and their correlations + /// Gets/sets the Unique event name /// - [ProtoContract] - [DataContract] - public class EventDefinition - { + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(1)] + [DataMember(Order = 1)] + public virtual string Name { get; set; } = null!; - /// - /// Gets/sets the Unique event name - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(1)] - [DataMember(Order = 1)] - public virtual string Name { get; set; } = null!; - - /// - /// Gets/sets the cloud event source - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(2)] - [DataMember(Order = 2)] - public virtual string? Source { get; set; } + /// + /// Gets/sets the cloud event source + /// + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(2)] + [DataMember(Order = 2)] + public virtual string? Source { get; set; } - /// - /// Gets/sets the cloud event type - /// - [ProtoMember(3)] - [DataMember(Order = 3)] - public virtual string Type { get; set; } = null!; + /// + /// Gets/sets the cloud event type + /// + [ProtoMember(3)] + [DataMember(Order = 3)] + public virtual string Type { get; set; } = null!; - /// - /// Gets/sets a value that defines the CloudEvent as either '' or '' by the workflow. Default is ''. - /// - [ProtoMember(4)] - [DataMember(Order = 4)] - [DefaultValue(EventKind.Consumed)] - public virtual EventKind Kind { get; set; } = EventKind.Consumed; + /// + /// Gets/sets a value that defines the CloudEvent as either '' or '' by the workflow. Default is ''. + /// + [ProtoMember(4)] + [DataMember(Order = 4)] + [DefaultValue(EventKind.Consumed)] + public virtual string Kind { get; set; } = EventKind.Consumed; - /// - /// Gets/sets an containing the s used to define the way the cloud event is correlated - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "correlation"), MinLength(1)] - [System.Text.Json.Serialization.JsonPropertyName("correlation")] - [YamlMember(Alias = "correlation")] - [ProtoMember(5, Name = "correlation")] - [DataMember(Order = 5, Name = "correlation")] - public virtual List? Correlations { get; set; } + /// + /// Gets/sets an containing the s used to define the way the cloud event is correlated + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "correlation"), MinLength(1)] + [System.Text.Json.Serialization.JsonPropertyName("correlation")] + [YamlMember(Alias = "correlation")] + [ProtoMember(5, Name = "correlation")] + [DataMember(Order = 5, Name = "correlation")] + public virtual List? Correlations { get; set; } - /// - /// Gets/sets a boolean indicating whether or not to use the event's data only (thus making data the top level element, instead of including all context attributes at top level). Defaults to true. - /// - [ProtoMember(6)] - [DataMember(Order = 6)] - [DefaultValue(true)] - public virtual bool DataOnly { get; set; } = true; + /// + /// Gets/sets a boolean indicating whether or not to use the event's data only (thus making data the top level element, instead of including all context attributes at top level). Defaults to true. + /// + [ProtoMember(6)] + [DataMember(Order = 6)] + [DefaultValue(true)] + public virtual bool DataOnly { get; set; } = true; - /// - /// Gets/sets the 's metadata - /// - [ProtoMember(7)] - [DataMember(Order = 7)] - public virtual DynamicObject? Metadata { get; set; } + /// + /// Gets/sets the 's metadata + /// + [ProtoMember(7)] + [DataMember(Order = 7)] + public virtual DynamicObject? Metadata { get; set; } - /// - public override string ToString() - { - return this.Name; - } + /// + /// Gets/sets an containing the 's extension properties + /// + [ProtoMember(8)] + [DataMember(Order = 8)] + [Newtonsoft.Json.JsonExtensionData] + [System.Text.Json.Serialization.JsonExtensionData] + public virtual IDictionary? ExtensionProperties { get; set; } + /// + public override string ToString() + { + return this.Name; } } diff --git a/src/ServerlessWorkflow.Sdk/Models/EventReference.cs b/src/ServerlessWorkflow.Sdk/Models/EventReference.cs index 7f803cf..a84ac71 100644 --- a/src/ServerlessWorkflow.Sdk/Models/EventReference.cs +++ b/src/ServerlessWorkflow.Sdk/Models/EventReference.cs @@ -14,131 +14,136 @@ * limitations under the License. * */ -using System; + using System.ComponentModel.DataAnnotations; -using YamlDotNet.Serialization; -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + + +/// +/// Represents a reference to an +/// +[ProtoContract] +[DataContract] +public class EventReference { /// - /// Represents a reference to an + /// Gets the name of the event to produce /// - [ProtoContract] - [DataContract] - public class EventReference - { + [Required] + [Newtonsoft.Json.JsonRequired, Newtonsoft.Json.JsonProperty(PropertyName = "triggerEventRef")] + [System.Text.Json.Serialization.JsonPropertyName("triggerEventRef")] + [YamlMember(Alias = "triggerEventRef")] + [ProtoMember(1, IsRequired = true, Name = "triggerEventRef")] + [DataMember(Order = 1, IsRequired = true, Name = "triggerEventRef")] + public virtual string ProduceEvent { get; set; } = null!; - /// - /// Gets the name of the event to produce - /// - [Required] - [Newtonsoft.Json.JsonRequired, Newtonsoft.Json.JsonProperty(PropertyName = "triggerEventRef")] - [System.Text.Json.Serialization.JsonPropertyName("triggerEventRef")] - [YamlMember(Alias = "triggerEventRef")] - [ProtoMember(1, IsRequired = true, Name = "triggerEventRef")] - [DataMember(Order = 1, IsRequired = true, Name = "triggerEventRef")] - public virtual string ProduceEvent { get; set; } = null!; - - /// - /// Gets the name of the event to consume - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "resultEventRef")] - [System.Text.Json.Serialization.JsonPropertyName("resultEventRef")] - [YamlMember(Alias = "resultEventRef")] - [ProtoMember(2)] - [DataMember(Order = 2)] - public virtual string ResultEvent { get; set; } = null!; + /// + /// Gets the name of the event to consume + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "resultEventRef")] + [System.Text.Json.Serialization.JsonPropertyName("resultEventRef")] + [YamlMember(Alias = "resultEventRef")] + [ProtoMember(2)] + [DataMember(Order = 2)] + public virtual string ResultEvent { get; set; } = null!; - /// - /// Gets/sets the data to become the cloud event's payload. - /// If string type, an expression which selects parts of the states data output to become the data (payload) of the event referenced by ''. - /// If object type, a custom object to become the data (payload) of the event referenced by ''. - /// - [ProtoMember(3, Name = "data")] - [DataMember(Order = 3, Name = "data")] - [YamlMember(Alias = "data")] - [Newtonsoft.Json.JsonProperty(PropertyName = "data"), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] - [System.Text.Json.Serialization.JsonPropertyName("data"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] - protected virtual OneOf? DataValue { get; set; } + /// + /// Gets/sets the data to become the cloud event's payload. + /// If string type, an expression which selects parts of the states data output to become the data (payload) of the event referenced by ''. + /// If object type, a custom object to become the data (payload) of the event referenced by ''. + /// + [ProtoMember(3, Name = "data")] + [DataMember(Order = 3, Name = "data")] + [YamlMember(Alias = "data")] + [Newtonsoft.Json.JsonProperty(PropertyName = "data"), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] + [System.Text.Json.Serialization.JsonPropertyName("data"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] + protected virtual OneOf? DataValue { get; set; } - /// - /// Gets/sets a custom object to become the data (payload) of the event referenced by '' - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual DynamicObject? Data + /// + /// Gets/sets a custom object to become the data (payload) of the event referenced by '' + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual DynamicObject? Data + { + get { - get - { - return this.DataValue?.T1Value; - } - set - { - if (value == null) - this.DataValue = null; - else - this.DataValue = value; - } + return this.DataValue?.T1Value; } - - /// - /// Gets/sets an expression which selects parts of the states data output to become the data (payload) of the event referenced by '' - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual string? DataExpression + set { - get - { - return this.DataValue?.T2Value; - } - set - { - if (value == null) - this.DataValue = null; - else - this.DataValue = value; - } + if (value == null) + this.DataValue = null; + else + this.DataValue = value; } + } - /// - /// Gets/sets additional extension context attributes to the produced event - /// - [ProtoMember(4)] - [DataMember(Order = 4)] - public virtual DynamicObject? ContextAttributes { get; set; } + /// + /// Gets/sets an expression which selects parts of the states data output to become the data (payload) of the event referenced by '' + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual string? DataExpression + { + get + { + return this.DataValue?.T2Value; + } + set + { + if (value == null) + this.DataValue = null; + else + this.DataValue = value; + } + } - /// - /// Gets the maximum amount of time to wait for the result event. If not defined it be set to the actionExecutionTimeout - /// - [ProtoMember(5)] - [DataMember(Order = 5)] - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.Iso8601TimeSpanConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? ConsumeEventTimeout { get; set; } + /// + /// Gets/sets additional extension context attributes to the produced event + /// + [ProtoMember(4)] + [DataMember(Order = 4)] + public virtual DynamicObject? ContextAttributes { get; set; } - /// - /// Gets/sets the reference event's . Default is . - /// - /// - /// Default value of this property is sync, meaning that workflow execution should wait until the function completes (the result event is received). - /// If set to async, workflow execution should just produce the trigger event and should not wait for the result event - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "invoke")] - [System.Text.Json.Serialization.JsonPropertyName("invoke")] - [YamlMember(Alias = "invoke")] - [ProtoMember(6, Name = "invoke")] - [DataMember(Order = 6, Name = "invoke")] - public virtual InvocationMode InvocationMode { get; set; } = InvocationMode.Synchronous; + /// + /// Gets the maximum amount of time to wait for the result event. If not defined it be set to the actionExecutionTimeout + /// + [ProtoMember(5)] + [DataMember(Order = 5)] + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.Iso8601TimeSpanConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.Iso8601NullableTimeSpanConverter))] + public virtual TimeSpan? ConsumeEventTimeout { get; set; } + /// + /// Gets/sets the reference event's . Default is . + /// + /// + /// Default value of this property is sync, meaning that workflow execution should wait until the function completes (the result event is received). + /// If set to async, workflow execution should just produce the trigger event and should not wait for the result event + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "invoke")] + [System.Text.Json.Serialization.JsonPropertyName("invoke")] + [YamlMember(Alias = "invoke")] + [ProtoMember(6, Name = "invoke")] + [DataMember(Order = 6, Name = "invoke")] + public virtual string InvocationMode { get; set; } = Sdk.InvocationMode.Synchronous; - } + /// + /// Gets/sets an containing the 's extension properties + /// + [ProtoMember(7)] + [DataMember(Order = 7)] + [Newtonsoft.Json.JsonExtensionData] + [System.Text.Json.Serialization.JsonExtensionData] + public virtual IDictionary? ExtensionProperties { get; set; } } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs index 219719c..b85f8f5 100644 --- a/src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs @@ -46,7 +46,7 @@ public class EventStateTriggerDefinition /// [ProtoMember(2)] [DataMember(Order = 2)] - public virtual ActionExecutionMode ActionMode { get; set; } + public virtual string ActionMode { get; set; } = ActionExecutionMode.Sequential; /// /// Gets/sets an containing the actions to be performed if expression matches diff --git a/src/ServerlessWorkflow.Sdk/Models/ExtensionStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ExtensionStateDefinition.cs new file mode 100644 index 0000000..1abb191 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ExtensionStateDefinition.cs @@ -0,0 +1,41 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace ServerlessWorkflow.Sdk.Models; + +///

+/// Represents the definition of an extension state +/// +[DiscriminatedByDefault] +[DataContract] +[ProtoContract] +public class ExtensionStateDefinition + : StateDefinition +{ + + /// + /// Initializes a new + /// + public ExtensionStateDefinition() : base(StateType.Extension) { } + + /// + /// Initializes a new + /// + /// The type of the extension state + public ExtensionStateDefinition(string type) : base(type) { } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ForEachStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ForEachStateDefinition.cs index c0cf743..2c4d1ef 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ForEachStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ForEachStateDefinition.cs @@ -76,7 +76,7 @@ public ForEachStateDefinition() ///
[ProtoMember(5)] [DataMember(Order = 5)] - public virtual ActionExecutionMode Mode { get; set; } + public virtual string Mode { get; set; } = ActionExecutionMode.Sequential; /// /// Gets/sets an of actions to be executed for each of the elements of the diff --git a/src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs index ac9fa83..f33abfd 100644 --- a/src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs @@ -14,64 +14,70 @@ * limitations under the License. * */ -using System.ComponentModel.DataAnnotations; -namespace ServerlessWorkflow.Sdk.Models + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents an object used to define a reusable function +/// +[ProtoContract] +[DataContract] +public class FunctionDefinition { /// - /// Represents an object used to define a reusable function + /// Gets/sets a unique function name /// - [ProtoContract] - [DataContract] - public class FunctionDefinition - { - - /// - /// Gets/sets a unique function name - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(1)] - [DataMember(Order = 1)] - public virtual string Name { get; set; } = null!; + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(1)] + [DataMember(Order = 1)] + public virtual string Name { get; set; } = null!; - /// - /// Gets/sets the operation. If type '', combination of the function/service OpenAPI definition URI and the operationID of the operation that needs to be invoked, separated by a '#'. - /// If type is `` defines the workflow expression. - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(2)] - [DataMember(Order = 2)] - public virtual string Operation { get; set; } = null!; + /// + /// Gets/sets the operation. If type '', combination of the function/service OpenAPI definition URI and the operationID of the operation that needs to be invoked, separated by a '#'. + /// If type is `` defines the workflow expression. + /// + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(2)] + [DataMember(Order = 2)] + public virtual string Operation { get; set; } = null!; - /// - /// Gets/sets the type of the defined function. Defaults to '' - /// - [ProtoMember(3)] - [DataMember(Order = 3)] - public virtual FunctionType Type { get; set; } = FunctionType.Rest; + /// + /// Gets/sets the type of the defined function. Defaults to '' + /// + [ProtoMember(3)] + [DataMember(Order = 3)] + public virtual string Type { get; set; } = FunctionType.Rest; - /// - /// Gets/sets the reference to the to use when invoking the function. Ignored when has been set to - /// - [ProtoMember(4)] - [DataMember(Order = 4)] - public virtual string? AuthRef { get; set; } + /// + /// Gets/sets the reference to the to use when invoking the function. Ignored when has been set to + /// + [ProtoMember(4)] + [DataMember(Order = 4)] + public virtual string? AuthRef { get; set; } - /// - /// Gets/sets the function's metadata - /// - [ProtoMember(5)] - [DataMember(Order = 5)] - public virtual DynamicObject? Metadata { get; set; } + /// + /// Gets/sets the function's metadata + /// + [ProtoMember(5)] + [DataMember(Order = 5)] + public virtual DynamicObject? Metadata { get; set; } - /// - public override string ToString() - { - return this.Name; - } + /// + /// Gets/sets an containing the 's extension properties + /// + [ProtoMember(6)] + [DataMember(Order = 6)] + [Newtonsoft.Json.JsonExtensionData] + [System.Text.Json.Serialization.JsonExtensionData] + public virtual IDictionary? ExtensionProperties { get; set; } + /// + public override string ToString() + { + return this.Name; } } diff --git a/src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs b/src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs index 16f8dfb..a41f377 100644 --- a/src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs +++ b/src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs @@ -14,48 +14,53 @@ * limitations under the License. * */ -using System.ComponentModel.DataAnnotations; -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents a reference to a +/// +[ProtoContract] +[DataContract] +public class FunctionReference { /// - /// Represents a reference to a + /// Gets/sets the referenced function's name /// - [ProtoContract] - [DataContract] - public class FunctionReference - { + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(1, IsRequired = true)] + [DataMember(Order = 1, IsRequired = true)] + public virtual string RefName { get; set; } = null!; - /// - /// Gets/sets the referenced function's name - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(1, IsRequired = true)] - [DataMember(Order = 1, IsRequired = true)] - public virtual string RefName { get; set; } = null!; - - /// - /// Gets/sets a that contains the parameters of the function to invoke - /// - [ProtoMember(2)] - [DataMember(Order = 2)] - public virtual DynamicObject? Arguments { get; set; } - - /// - /// Gets/sets a GraphQL selection set - /// - [ProtoMember(3)] - [DataMember(Order = 3)] - public virtual string? SelectionSet { get; set; } - - /// - public override string ToString() - { - return this.RefName; - } + /// + /// Gets/sets a that contains the parameters of the function to invoke + /// + [ProtoMember(2)] + [DataMember(Order = 2)] + public virtual DynamicObject? Arguments { get; set; } + /// + /// Gets/sets a GraphQL selection set + /// + [ProtoMember(3)] + [DataMember(Order = 3)] + public virtual string? SelectionSet { get; set; } + + /// + /// Gets/sets an containing the 's extension properties + /// + [ProtoMember(4)] + [DataMember(Order = 4)] + [Newtonsoft.Json.JsonExtensionData] + [System.Text.Json.Serialization.JsonExtensionData] + public virtual IDictionary? ExtensionProperties { get; set; } + + /// + public override string ToString() + { + return this.RefName; } } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/InjectStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/InjectStateDefinition.cs index 6440f2f..faf7517 100644 --- a/src/ServerlessWorkflow.Sdk/Models/InjectStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/InjectStateDefinition.cs @@ -15,39 +15,34 @@ * */ -using System.ComponentModel.DataAnnotations; - -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents a workflow state that injects static data into state data input +/// +[DiscriminatorValue(StateType.Inject)] +[DataContract] +[ProtoContract] +public class InjectStateDefinition + : StateDefinition { /// - /// Represents a workflow state that injects static data into state data input + /// Initializes a new /// - [DiscriminatorValue(StateType.Inject)] - [DataContract] - [ProtoContract] - public class InjectStateDefinition - : StateDefinition + public InjectStateDefinition() + : base(StateType.Inject) { - /// - /// Initializes a new - /// - public InjectStateDefinition() - : base(StateType.Inject) - { - - } - - /// - /// Gets/sets the which can be set as state's data input and can be manipulated via filter - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(1, IsRequired = true)] - [DataMember(Order = 1, IsRequired = true)] - public virtual DynamicObject Data { get; set; } = null!; - } + /// + /// Gets/sets the object to inject within the state's data input and can be manipulated via filter + /// + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(1, IsRequired = true)] + [DataMember(Order = 1, IsRequired = true)] + public virtual DynamicObject Data { get; set; } = null!; + } diff --git a/src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs b/src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs index 3b0dc3a..a9e379a 100644 --- a/src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs +++ b/src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs @@ -36,8 +36,8 @@ public class OAuth2AuthenticationProperties [Newtonsoft.Json.JsonProperty("grant_type")] [System.Text.Json.Serialization.JsonPropertyName("grant_type")] [ProtoMember(1)] - [DataMember(Name= "grant_type", Order = 1)] - public virtual OAuth2GrantType GrantType { get; set; } + [DataMember(Name = "grant_type", Order = 1)] + public virtual string GrantType { get; set; } = null!; /// /// Gets/sets the uri of the OAuth2 authority to use to generate an access token @@ -120,7 +120,7 @@ public class OAuth2AuthenticationProperties [System.Text.Json.Serialization.JsonPropertyName("subject_token_type")] [ProtoMember(10)] [DataMember(Name = "subject_token_type", Order = 10)] - public virtual OAuth2TokenType? SubjectTokenType { get; set; } + public virtual string? SubjectTokenType { get; set; } /// /// Gets/sets a token that represents the identity of the acting party.Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. @@ -138,7 +138,7 @@ public class OAuth2AuthenticationProperties [System.Text.Json.Serialization.JsonPropertyName("actor_token_type")] [ProtoMember(11)] [DataMember(Name = "actor_token_type", Order = 11)] - public virtual OAuth2TokenType? ActorTokenType { get; set; } + public virtual string? ActorTokenType { get; set; } } diff --git a/src/ServerlessWorkflow.Sdk/Models/OperationStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/OperationStateDefinition.cs index d2b2949..90342ea 100644 --- a/src/ServerlessWorkflow.Sdk/Models/OperationStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/OperationStateDefinition.cs @@ -45,7 +45,7 @@ public OperationStateDefinition() /// [ProtoMember(1)] [DataMember(Order = 1)] - public virtual ActionExecutionMode ActionMode { get; set; } = ActionExecutionMode.Sequential; + public virtual string ActionMode { get; set; } = ActionExecutionMode.Sequential; /// /// Gets/sets an of actions to be performed if expression matches diff --git a/src/ServerlessWorkflow.Sdk/Models/ParallelStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ParallelStateDefinition.cs index 9f98354..146e599 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ParallelStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ParallelStateDefinition.cs @@ -50,7 +50,7 @@ public ParallelStateDefinition() /// [ProtoMember(2)] [DataMember(Order = 2)] - public virtual ParallelCompletionType CompletionType { get; set; } = ParallelCompletionType.AllOf; + public virtual string CompletionType { get; set; } = ParallelCompletionType.AllOf; /// /// Gets/sets a value that represents the amount of es to complete for completing the state, when is set to diff --git a/src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs index 8d02c56..9af1b0d 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs @@ -35,7 +35,7 @@ public class ScheduleDefinition [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] [YamlIgnore] - public virtual ScheduleDefinitionType Type => this.Cron == null ? ScheduleDefinitionType.Interval : ScheduleDefinitionType.Cron; + public virtual string Type => this.Cron == null ? ScheduleDefinitionType.Interval : ScheduleDefinitionType.Cron; /// /// Gets/sets the time interval (ISO 8601 format) describing when workflow instances can be created. diff --git a/src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs index 8c599c2..ba1aeef 100644 --- a/src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs @@ -14,294 +14,295 @@ * limitations under the License. * */ -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using YamlDotNet.Serialization; -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents a serverless workflow state definition +/// +[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.AbstractClassConverterFactory))] +[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.AbstractClassConverterFactory))] +[Discriminator(nameof(Type))] +[ProtoContract] +[ProtoInclude(100, typeof(CallbackStateDefinition))] +[ProtoInclude(200, typeof(SleepStateDefinition))] +[ProtoInclude(300, typeof(EventStateDefinition))] +[ProtoInclude(400, typeof(ForEachStateDefinition))] +[ProtoInclude(500, typeof(InjectStateDefinition))] +[ProtoInclude(600, typeof(OperationStateDefinition))] +[ProtoInclude(700, typeof(ParallelStateDefinition))] +[ProtoInclude(800, typeof(SwitchStateDefinition))] +[DataContract] +public abstract class StateDefinition { /// - /// Represents a serverless workflow state definition + /// Initializes a new /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.AbstractClassConverterFactory))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.AbstractClassConverterFactory))] - [Discriminator(nameof(Type))] - [ProtoContract] - [ProtoInclude(100, typeof(CallbackStateDefinition))] - [ProtoInclude(200, typeof(SleepStateDefinition))] - [ProtoInclude(300, typeof(EventStateDefinition))] - [ProtoInclude(400, typeof(ForEachStateDefinition))] - [ProtoInclude(500, typeof(InjectStateDefinition))] - [ProtoInclude(600, typeof(OperationStateDefinition))] - [ProtoInclude(700, typeof(ParallelStateDefinition))] - [ProtoInclude(800, typeof(SwitchStateDefinition))] - [DataContract] - public abstract class StateDefinition + /// The 's type + protected StateDefinition(string type) { + this.Type = type; + } - /// - /// Initializes a new - /// - /// The 's type - protected StateDefinition(StateType type) - { - this.Type = type; - } - - /// - /// Gets/sets the 's id - /// - [ProtoMember(1)] - [DataMember(Order = 1)] - public virtual string? Id { get; set; } + /// + /// Gets/sets the 's id + /// + [ProtoMember(1)] + [DataMember(Order = 1)] + public virtual string? Id { get; set; } - /// - /// Gets/sets the 's id - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(2)] - [DataMember(Order = 2)] - public virtual string Name { get; set; } = null!; + /// + /// Gets/sets the 's id + /// + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(2)] + [DataMember(Order = 2)] + public virtual string Name { get; set; } = null!; - /// - /// Gets the 's type - /// - [YamlMember] - [ProtoMember(3)] - [DataMember(Order = 3)] - public virtual StateType Type { get; protected set; } + /// + /// Gets the 's type + /// + [YamlMember] + [ProtoMember(3)] + [DataMember(Order = 3)] + public virtual string Type { get; protected set; } = null!; - /// - /// Gets/sets the filter to apply to the 's input and output data - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "stateDataFilter")] - [System.Text.Json.Serialization.JsonPropertyName("stateDataFilter")] - [YamlMember(Alias = "stateDataFilter")] - [ProtoMember(5, Name = "stateDataFilter")] - [DataMember(Order = 5, Name = "stateDataFilter")] - public virtual StateDataFilterDefinition? DataFilter { get; set; } + /// + /// Gets/sets the filter to apply to the 's input and output data + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "stateDataFilter")] + [System.Text.Json.Serialization.JsonPropertyName("stateDataFilter")] + [YamlMember(Alias = "stateDataFilter")] + [ProtoMember(5, Name = "stateDataFilter")] + [DataMember(Order = 5, Name = "stateDataFilter")] + public virtual StateDataFilterDefinition? DataFilter { get; set; } - /// - /// Gets/sets the that represents the 's - /// - [YamlMember(Alias = "dataInputSchema")] - [ProtoMember(8, Name = "dataInputSchema")] - [DataMember(Order = 8, Name = "dataInputSchema")] - [Newtonsoft.Json.JsonProperty(PropertyName = "dataInputSchema"), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] - [System.Text.Json.Serialization.JsonPropertyName("dataInputSchema"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] - protected virtual OneOf? DataInputSchemaValue { get; set; } + /// + /// Gets/sets the that represents the 's + /// + [YamlMember(Alias = "dataInputSchema")] + [ProtoMember(8, Name = "dataInputSchema")] + [DataMember(Order = 8, Name = "dataInputSchema")] + [Newtonsoft.Json.JsonProperty(PropertyName = "dataInputSchema"), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] + [System.Text.Json.Serialization.JsonPropertyName("dataInputSchema"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] + protected virtual OneOf? DataInputSchemaValue { get; set; } - /// - /// Gets/sets the 's - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual DataInputSchemaDefinition? DataInputSchema + /// + /// Gets/sets the 's + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual DataInputSchemaDefinition? DataInputSchema + { + get + { + if (this.DataInputSchemaValue?.T1Value == null + && this.DataInputSchemaValue?.T2Value != null) + return new() { SchemaUri = this.DataInputSchemaValue.T2Value }; + else + return this.DataInputSchemaValue?.T1Value; + } + set { - get - { - if (this.DataInputSchemaValue?.T1Value == null - && this.DataInputSchemaValue?.T2Value != null) - return new() { SchemaUri = this.DataInputSchemaValue.T2Value }; - else - return this.DataInputSchemaValue?.T1Value; - } - set - { - if (value == null) - this.DataInputSchemaValue = null; - else - this.DataInputSchemaValue = value; - } + if (value == null) + this.DataInputSchemaValue = null; + else + this.DataInputSchemaValue = value; } + } - /// - /// Gets/sets the referencing the 's - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual Uri? DataInputSchemaUri + /// + /// Gets/sets the referencing the 's + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual Uri? DataInputSchemaUri + { + get + { + return this.DataInputSchemaValue?.T2Value; + } + set { - get - { - return this.DataInputSchemaValue?.T2Value; - } - set - { - if (value == null) - this.DataInputSchemaValue = null; - else - this.DataInputSchemaValue = value; - } + if (value == null) + this.DataInputSchemaValue = null; + else + this.DataInputSchemaValue = value; } + } - /// - /// Gets/sets the configuration of the 's error handling - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "onErrors")] - [System.Text.Json.Serialization.JsonPropertyName("onErrors")] - [YamlMember(Alias = "onErrors")] - [ProtoMember(6, Name = "onErrors")] - [DataMember(Order = 6, Name = "onErrors")] - public virtual List? Errors { get; set; } + /// + /// Gets/sets the configuration of the 's error handling + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "onErrors")] + [System.Text.Json.Serialization.JsonPropertyName("onErrors")] + [YamlMember(Alias = "onErrors")] + [ProtoMember(6, Name = "onErrors")] + [DataMember(Order = 6, Name = "onErrors")] + public virtual List? Errors { get; set; } - /// - /// Gets/sets the id of the used to compensate the - /// - [ProtoMember(9)] - [DataMember(Order = 9)] - public virtual string? CompensatedBy { get; set; } + /// + /// Gets/sets the id of the used to compensate the + /// + [ProtoMember(9)] + [DataMember(Order = 9)] + public virtual string? CompensatedBy { get; set; } - /// - /// Gets/sets a boolean indicating whether or not the is used for compensating another - /// - [ProtoMember(10)] - [DataMember(Order = 10)] - public virtual bool UsedForCompensation { get; set; } + /// + /// Gets/sets a boolean indicating whether or not the is used for compensating another + /// + [ProtoMember(10)] + [DataMember(Order = 10)] + public virtual bool UsedForCompensation { get; set; } - /// - /// Gets/sets the 's metadata - /// - [ProtoMember(11)] - [DataMember(Order = 11)] - public virtual DynamicObject? Metadata { get; set; } + /// + /// Gets/sets the 's metadata + /// + [ProtoMember(11)] + [DataMember(Order = 11)] + public virtual DynamicObject? Metadata { get; set; } - /// - /// Gets/sets the that represents the 's - /// - [ProtoMember(9998, Name = "transition")] - [DataMember(Order = 9998, Name = "transition")] - [YamlMember(Alias = "transition")] - [Newtonsoft.Json.JsonProperty(PropertyName = "transition", Order = 999999998), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] - [System.Text.Json.Serialization.JsonPropertyName("transition"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] - protected virtual OneOf? TransitionValue { get; set; } + /// + /// Gets/sets the that represents the 's + /// + [ProtoMember(9997, Name = "transition")] + [DataMember(Order = 9997, Name = "transition")] + [YamlMember(Alias = "transition")] + [Newtonsoft.Json.JsonProperty(PropertyName = "transition", Order = 999999998), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] + [System.Text.Json.Serialization.JsonPropertyName("transition"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] + protected virtual OneOf? TransitionValue { get; set; } - /// - /// Gets/sets the object used to configure the 's transition to another upon completion - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual TransitionDefinition? Transition + /// + /// Gets/sets the object used to configure the 's transition to another upon completion + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual TransitionDefinition? Transition + { + get + { + if (this.TransitionValue?.T1Value == null + && !string.IsNullOrWhiteSpace(this.TransitionValue?.T2Value)) + return new() { NextState = this.TransitionValue.T2Value }; + else + return this.TransitionValue?.T1Value; + } + set { - get - { - if (this.TransitionValue?.T1Value == null - && !string.IsNullOrWhiteSpace(this.TransitionValue?.T2Value)) - return new() { NextState = this.TransitionValue.T2Value }; - else - return this.TransitionValue?.T1Value; - } - set - { - if (value == null) - this.TransitionValue = null; - else - this.TransitionValue = value; - } + if (value == null) + this.TransitionValue = null; + else + this.TransitionValue = value; } + } - /// - /// Gets/sets the name of the to transition to upon completion - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual string? TransitionToStateName + /// + /// Gets/sets the name of the to transition to upon completion + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual string? TransitionToStateName + { + get { - get - { - return this.TransitionValue?.T2Value; - } - set - { - if (value == null) - this.TransitionValue = null; - else - this.TransitionValue = value; - } + return this.TransitionValue?.T2Value; } + set + { + if (value == null) + this.TransitionValue = null; + else + this.TransitionValue = value; + } + } - /// - /// Gets/sets the that represents the 's - /// - [ProtoMember(9999, Name = "end")] - [DataMember(Order = 9999, Name = "end")] - [YamlMember(Alias = "end")] - [Newtonsoft.Json.JsonProperty(PropertyName = "end", Order = 999999999), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] - [System.Text.Json.Serialization.JsonPropertyName("end"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] - protected virtual OneOf? EndValue { get; set; } + /// + /// Gets/sets the that represents the 's + /// + [ProtoMember(9998, Name = "end")] + [DataMember(Order = 9998, Name = "end")] + [YamlMember(Alias = "end")] + [Newtonsoft.Json.JsonProperty(PropertyName = "end", Order = 999999999), Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.OneOfConverter))] + [System.Text.Json.Serialization.JsonPropertyName("end"), System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Converters.OneOfConverter))] + protected virtual OneOf? EndValue { get; set; } - /// - /// Gets/sets the object used to configure the 's transition to another upon completion - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual EndDefinition? End + /// + /// Gets/sets the object used to configure the 's transition to another upon completion + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual EndDefinition? End + { + get { - get - { - if (this.EndValue?.T1Value == null - && (this.EndValue != null && this.EndValue.T2Value)) - return new() { }; - else - return this.EndValue?.T1Value; - } - set - { - if (value == null) - this.EndValue = null; - else - this.EndValue = value; - } + if (this.EndValue?.T1Value == null + && (this.EndValue != null && this.EndValue.T2Value)) + return new() { }; + else + return this.EndValue?.T1Value; } - - /// - /// Gets/sets a boolean indicating whether or not the is the end of a logicial workflow path - /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] - [YamlIgnore] - [ProtoIgnore] - [IgnoreDataMember] - public virtual bool IsEnd + set { - get - { - if (this.EndValue == null) - return false; - else - return this.EndValue.T2Value; - } - set - { + if (value == null) + this.EndValue = null; + else this.EndValue = value; - } } + } - /// - public override string ToString() + /// + /// Gets/sets a boolean indicating whether or not the is the end of a logicial workflow path + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + [YamlIgnore] + [ProtoIgnore] + [IgnoreDataMember] + public virtual bool IsEnd + { + get + { + if (this.EndValue == null) + return false; + else + return this.EndValue.T2Value; + } + set { - return this.Name; + this.EndValue = value; } + } + /// + /// Gets/sets an containing the 's extension properties + /// + [ProtoMember(9999)] + [DataMember(Order = 9999)] + [Newtonsoft.Json.JsonExtensionData] + [System.Text.Json.Serialization.JsonExtensionData] + public virtual IDictionary? ExtensionProperties { get; set; } + + /// + public override string ToString() + { + return this.Name; } } diff --git a/src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs b/src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs index 2c57387..8f4ec18 100644 --- a/src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs +++ b/src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs @@ -14,106 +14,108 @@ * limitations under the License. * */ -using YamlDotNet.Serialization; -using System.ComponentModel.DataAnnotations; -using System; -using System.Linq; -namespace ServerlessWorkflow.Sdk.Models +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents a reference to a sub +/// +[ProtoContract] +[DataContract] +public class SubflowReference { /// - /// Represents a reference to a sub + /// Initializes a new /// - [ProtoContract] - [DataContract] - public class SubflowReference + public SubflowReference() { - /// - /// Initializes a new - /// - public SubflowReference() - { - - } + } - /// - /// Initializes a new - /// - /// The id of the to run - /// The version of the to run. Defaults to 'latest' - /// The subflow's . Defaults to . - public SubflowReference(string workflowId, string version, InvocationMode invocationMode = InvocationMode.Synchronous) - : this() - { - if (string.IsNullOrWhiteSpace(workflowId)) - throw new ArgumentNullException(nameof(workflowId)); - this.WorkflowId = workflowId; - this.Version = version; - this.InvocationMode = invocationMode; - } + /// + /// Initializes a new + /// + /// The id of the to run + /// The version of the to run. Defaults to 'latest' + /// The subflow's . Defaults to . + public SubflowReference(string workflowId, string version, string invocationMode = Sdk.InvocationMode.Synchronous) + : this() + { + if (string.IsNullOrWhiteSpace(workflowId)) + throw new ArgumentNullException(nameof(workflowId)); + this.WorkflowId = workflowId; + this.Version = version; + this.InvocationMode = invocationMode; + } - /// - /// Initializes a new - /// - /// The id of the to run - /// The subflow's . Defaults to . - public SubflowReference(string workflowId, InvocationMode invocationMode = InvocationMode.Synchronous) - : this(workflowId, null!, invocationMode) - { + /// + /// Initializes a new + /// + /// The id of the to run + /// The subflow's . Defaults to . + public SubflowReference(string workflowId, string invocationMode = Sdk.InvocationMode.Synchronous) + : this(workflowId, null!, invocationMode) + { - } + } - /// - /// Gets/sets the id of the to run - /// - [Required] - [Newtonsoft.Json.JsonRequired] - [ProtoMember(1)] - [DataMember(Order = 1, IsRequired = true)] - public virtual string WorkflowId { get; set; } = null!; + /// + /// Gets/sets the id of the to run + /// + [Required] + [Newtonsoft.Json.JsonRequired] + [ProtoMember(1)] + [DataMember(Order = 1, IsRequired = true)] + public virtual string WorkflowId { get; set; } = null!; - /// - /// Gets/sets the version of the to run. Defaults to 'latest' - /// - [ProtoMember(2)] - [DataMember(Order = 2)] - public virtual string? Version { get; set; } = "latest"; + /// + /// Gets/sets the version of the to run. Defaults to 'latest' + /// + [ProtoMember(2)] + [DataMember(Order = 2)] + public virtual string? Version { get; set; } = "latest"; - /// - /// Gets/sets the subflow's . Defaults to . - /// - /// - /// Default value of this property is sync, meaning that workflow execution should wait until the subflow completes. - /// If set to async, workflow execution should just invoke the subflow and not wait for its results. Note that in this case the action does not produce any results, and the associated actions actionDataFilter as well as its retry definition, if defined, should be ignored. - /// Subflows that are invoked async do not propagate their errors to the associated action definition and the workflow state, meaning that any errors that happen during their execution cannot be handled in the workflow states onErrors definition. - /// Note that errors raised during subflows that are invoked async should not fail workflow execution. - /// - [Newtonsoft.Json.JsonProperty(PropertyName = "invoke")] - [System.Text.Json.Serialization.JsonPropertyName("invoke")] - [YamlMember(Alias = "invoke")] - [ProtoMember(3, Name = "invoke")] - [DataMember(Order = 3, Name = "invoke")] - public virtual InvocationMode InvocationMode { get; set; } = InvocationMode.Synchronous; + /// + /// Gets/sets the subflow's . Defaults to . + /// + /// + /// Default value of this property is sync, meaning that workflow execution should wait until the subflow completes. + /// If set to async, workflow execution should just invoke the subflow and not wait for its results. Note that in this case the action does not produce any results, and the associated actions actionDataFilter as well as its retry definition, if defined, should be ignored. + /// Subflows that are invoked async do not propagate their errors to the associated action definition and the workflow state, meaning that any errors that happen during their execution cannot be handled in the workflow states onErrors definition. + /// Note that errors raised during subflows that are invoked async should not fail workflow execution. + /// + [Newtonsoft.Json.JsonProperty(PropertyName = "invoke")] + [System.Text.Json.Serialization.JsonPropertyName("invoke")] + [YamlMember(Alias = "invoke")] + [ProtoMember(3, Name = "invoke")] + [DataMember(Order = 3, Name = "invoke")] + public virtual string InvocationMode { get; set; } = Sdk.InvocationMode.Synchronous; - /// - /// Parses the specified input into a new - /// - /// The input to parse - /// A new - public static SubflowReference Parse(string input) - { - if (string.IsNullOrWhiteSpace(input)) - throw new ArgumentNullException(nameof(input)); - var components = input.Split(":", StringSplitOptions.RemoveEmptyEntries); - var workflowId = components.First(); - var version = null as string; - if (components.Length > 1) - version = components.Last(); - return new SubflowReference(workflowId, version!); - } + /// + /// Gets/sets an containing the 's extension properties + /// + [ProtoMember(4)] + [DataMember(Order = 4)] + [Newtonsoft.Json.JsonExtensionData] + [System.Text.Json.Serialization.JsonExtensionData] + public virtual IDictionary? ExtensionProperties { get; set; } + /// + /// Parses the specified input into a new + /// + /// The input to parse + /// A new + public static SubflowReference Parse(string input) + { + if (string.IsNullOrWhiteSpace(input)) + throw new ArgumentNullException(nameof(input)); + var components = input.Split(":", StringSplitOptions.RemoveEmptyEntries); + var workflowId = components.First(); + var version = null as string; + if (components.Length > 1) + version = components.Last(); + return new SubflowReference(workflowId, version!); } } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs index d5fd50f..20166e9 100644 --- a/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs @@ -39,7 +39,7 @@ public abstract class SwitchCaseDefinition [YamlIgnore] [ProtoIgnore] [IgnoreDataMember] - public SwitchCaseOutcomeType OutcomeType + public string OutcomeType { get { diff --git a/src/ServerlessWorkflow.Sdk/Models/SwitchStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/SwitchStateDefinition.cs index 231f986..c75c21b 100644 --- a/src/ServerlessWorkflow.Sdk/Models/SwitchStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/SwitchStateDefinition.cs @@ -44,7 +44,7 @@ public SwitchStateDefinition() /// /// Gets the 's type /// - public virtual SwitchStateType SwitchType + public virtual string SwitchType { get { diff --git a/src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs b/src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs index 6a3cd26..8a384f1 100644 --- a/src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs +++ b/src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs @@ -15,30 +15,27 @@ * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all OAuth 2 grant types supported for workflow runtime token generation +/// +public static class OAuth2GrantType { + + /// + /// Indicates the resource-owner password credentials grant type + /// + public const string Password = "password"; + + /// + /// Indicates the client credentials grant type + /// + public const string ClientCredentials = "client_credentials"; + /// - /// Enumerates all OAuth 2 grant types supported for workflow runtime token generation + /// Indicates the token exchange grant type /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum OAuth2GrantType - { - /// - /// Indicates the resource-owner password credentials grant type - /// - [EnumMember(Value = "password")] - Password = 1, - /// - /// Indicates the client credentials grant type - /// - [EnumMember(Value = "client_credentials")] - ClientCredentials = 2, - /// - /// Indicates the token exchange grant type - /// - [EnumMember(Value = "urn:ietf:params:oauth:grant-type:token-exchange")] - TokenExchange = 4 - } + public const string TokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange"; } diff --git a/src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs b/src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs index 44e72f9..3e278d5 100644 --- a/src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs +++ b/src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs @@ -15,25 +15,22 @@ * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all supported token types +/// +public static class OAuth2TokenType { + + /// + /// Indicates an access token + /// + public const string AccessToken = "urn:ietf:params:oauth:token-type:access_token"; + /// - /// Enumerates all supported token types + /// Indicates an identity token /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum OAuth2TokenType - { - /// - /// Indicates an access token - /// - [EnumMember(Value = "urn:ietf:params:oauth:token-type:access_token")] - AccessToken = 1, - /// - /// Indicates an identity token - /// - [EnumMember(Value = "urn:ietf:params:oauth:token-type:id_token")] - IdentityToken = 2 - } + public const string IdentityToken = "urn:ietf:params:oauth:token-type:id_token"; } diff --git a/src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs b/src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs index 0b7eed0..5f5d270 100644 --- a/src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs +++ b/src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs @@ -15,25 +15,22 @@ * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all parallel completion types +/// +public static class ParallelCompletionType { + + /// + /// Indicates that all branches should be completed before completing the parallel execution + /// + public const string AllOf = "allOf"; + /// - /// Enumerates all parallel completion types + /// Indicates that 'N' amount of branches should complete before completing the parallel execution, thus potentially cancelling running branches /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum ParallelCompletionType - { - /// - /// Indicates that all branches should be completed before completing the parallel execution - /// - [EnumMember(Value = "allOf")] - AllOf, - /// - /// Indicates that 'N' amount of branches should complete before completing the parallel execution, thus potentially cancelling running branches - /// - [EnumMember(Value = "atLeast")] - AtLeastN - } + public const string AtLeastN = "atLeast"; } diff --git a/src/ServerlessWorkflow.Sdk/Properties/GlobalUsings.cs b/src/ServerlessWorkflow.Sdk/Properties/GlobalUsings.cs index fcea8bc..674ea54 100644 --- a/src/ServerlessWorkflow.Sdk/Properties/GlobalUsings.cs +++ b/src/ServerlessWorkflow.Sdk/Properties/GlobalUsings.cs @@ -1,7 +1,13 @@ global using Neuroglia; global using Neuroglia.Serialization; global using ProtoBuf; +global using System; +global using System.Collections.Generic; +global using System.ComponentModel.DataAnnotations; +global using System.Linq; global using System.Runtime.Serialization; +global using YamlDotNet.Serialization; using System.Runtime.CompilerServices; + [assembly: InternalsVisibleTo("ServerlessWorkflow.Sdk.UnitTests")] \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/RelativeUriReferenceResolutionMode.cs b/src/ServerlessWorkflow.Sdk/RelativeUriReferenceResolutionMode.cs index 8b152ac..aa3e07e 100644 --- a/src/ServerlessWorkflow.Sdk/RelativeUriReferenceResolutionMode.cs +++ b/src/ServerlessWorkflow.Sdk/RelativeUriReferenceResolutionMode.cs @@ -15,30 +15,27 @@ * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all types of reference resolution modes for relative s +/// +public static class RelativeUriReferenceResolutionMode { + + /// + /// Indicates that relative uris should be converted to an absolute one by combining them to a specified base uri + /// + public const string ConvertToAbsolute = "convertToAbsolute"; + + /// + /// Indicates that relative uris should be converted to a file path relative to a specified base directory + /// + public const string ConvertToRelativeFilePath = "convertToRelativeFilePath"; + /// - /// Enumerates all types of reference resolution modes for relative s + /// Indicates that relative uris should not be resolved /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum RelativeUriReferenceResolutionMode - { - /// - /// Indicates that relative uris should be converted to an absolute one by combining them to a specified base uri - /// - [EnumMember(Value = "convertToAbsolute")] - ConvertToAbsolute, - /// - /// Indicates that relative uris should be converted to a file path relative to a specified base directory - /// - [EnumMember(Value = "convertToRelativeFilePath")] - ConvertToRelativeFilePath, - /// - /// Indicates that relative uris should not be resolved - /// - [EnumMember(Value = "none")] - None - } + public const string None = "none"; } diff --git a/src/ServerlessWorkflow.Sdk/ScheduleDefinitionType.cs b/src/ServerlessWorkflow.Sdk/ScheduleDefinitionType.cs index 86249e7..c2ef60f 100644 --- a/src/ServerlessWorkflow.Sdk/ScheduleDefinitionType.cs +++ b/src/ServerlessWorkflow.Sdk/ScheduleDefinitionType.cs @@ -15,25 +15,23 @@ * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all types of schedule definitions +/// + +public static class ScheduleDefinitionType { + + /// + /// Indicates the definition of a CRON expression based schedule + /// + public const string Cron = "cron"; + /// - /// Enumerates all types of schedule definitions + /// Indicates the definition of an interval based schedule /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum ScheduleDefinitionType - { - /// - /// Indicates the definition of a CRON expression based schedule - /// - [EnumMember(Value = "cron")] - Cron = 1, - /// - /// Indicates the definition of an interval based schedule - /// - [EnumMember(Value = "interval")] - Interval = 2 - } + public const string Interval = "interval"; } diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj index 36a11b5..3255530 100644 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj +++ b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj @@ -50,11 +50,11 @@ - - - - - + + + + + diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.xml b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.xml index ee4d251..04ca115 100644 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.xml +++ b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.xml @@ -114,6 +114,11 @@ Gets/sets an expression to be evaluated positively as a condition for the to execute. + + + Gets/sets an containing the 's extension properties + + @@ -489,6 +494,11 @@ Gets/sets the 's metadata + + + Gets/sets an containing the 's extension properties + + @@ -543,6 +553,11 @@ If set to async, workflow execution should just produce the trigger event and should not wait for the result event + + + Gets/sets an containing the 's extension properties + + Represents a workflow state that awaits one or more events and perform actions when they are received @@ -647,6 +662,22 @@ Gets/sets an to a resource containing the workflow extension definition (json or yaml) + + + Represents the definition of an extension state + + + + + Initializes a new + + + + + Initializes a new + + The type of the extension state + Represents an external definition reference @@ -852,6 +883,11 @@ Gets/sets the function's metadata + + + Gets/sets an containing the 's extension properties + + @@ -875,6 +911,11 @@ Gets/sets a GraphQL selection set + + + Gets/sets an containing the 's extension properties + + @@ -890,7 +931,7 @@ - Gets/sets the which can be set as state's data input and can be manipulated via filter + Gets/sets the object to inject within the state's data input and can be manipulated via filter @@ -1392,7 +1433,7 @@ Represents a serverless workflow state definition - + Initializes a new @@ -1420,7 +1461,7 @@ - Gets/sets the that represents the 's + Gets/sets the that represents the 's @@ -1483,6 +1524,11 @@ Gets/sets a boolean indicating whether or not the is the end of a logicial workflow path + + + Gets/sets an containing the 's extension properties + + @@ -1501,7 +1547,7 @@ Initializes a new - + Initializes a new @@ -1509,7 +1555,7 @@ The version of the to run. Defaults to 'latest' The subflow's . Defaults to . - + Initializes a new @@ -1537,6 +1583,11 @@ Note that errors raised during subflows that are invoked async should not fail workflow execution. + + + Gets/sets an containing the 's extension properties + + Parses the specified input into a new @@ -2205,7 +2256,7 @@ Defines extensions for s - + Gets all the s of the specified type declared in the @@ -2347,7 +2398,7 @@ - Enumerates all types of reference resolution modes for relative s + Enumerates all types of reference resolution modes for relative s @@ -2477,10 +2528,10 @@ - + - + @@ -2902,7 +2953,7 @@ - + @@ -3018,7 +3069,7 @@ The to consume The configured - + Configures the to build to run the specified @@ -3027,7 +3078,7 @@ The 's . Defaults to The service used to build s - + Configures the to build to run the specified @@ -3608,7 +3659,7 @@ The name of the to build The configured - + Sets the type of the to build @@ -3716,7 +3767,7 @@ Defines the fundamentals of a service used to build a with scheme - + Configures the to use the specified when requesting an access token @@ -3772,7 +3823,7 @@ An array containing the audiences to use The configured - + Configures the token that represents the identity of the party on behalf of whom the request is being made.Typically, the subject of this token will be the subject of the security token issued in response to the request. @@ -3780,7 +3831,7 @@ The subject token The configured - + Configures the token that represents the identity of the acting party.Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. @@ -4627,7 +4678,7 @@ - + @@ -4648,10 +4699,10 @@ - + - + @@ -5229,7 +5280,7 @@ Defines the fundamentals of a service used to write s - + Writes the specified to a @@ -5401,7 +5452,7 @@ Gets the service used to serialize and deserialize YAML - + @@ -6065,7 +6116,7 @@ The Serverless Workflow - + Retrieves the JSON content of the specified schema @@ -6074,6 +6125,21 @@ A The JSON content of the specified schema + + + Retrieves the JSON content of the specified 's schema + + The that defines the referenced JSON schema + A + The JSON content of the specified schema + + + + Resolves the specified relative + + The relative to resolve + The resolved + Represents the service used to validate a workflow's s @@ -6210,6 +6276,11 @@ Indicates a callback state + + + Indicates an extension (custom) state + + Enumerates all types of conditions diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs index e38b045..174e2f4 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs @@ -193,7 +193,7 @@ public virtual IEventTriggerActionBuilder WithContextAttributes(IDictionary - public virtual ISubflowActionBuilder Run(string workflowId, string version, InvocationMode invocationMode = InvocationMode.Synchronous) + public virtual ISubflowActionBuilder Run(string workflowId, string version, string invocationMode = InvocationMode.Synchronous) { if (string.IsNullOrWhiteSpace(workflowId)) throw new ArgumentNullException(nameof(workflowId)); @@ -202,7 +202,7 @@ public virtual ISubflowActionBuilder Run(string workflowId, string version, Invo } /// - public virtual ISubflowActionBuilder Run(string workflowId, InvocationMode invocationMode = InvocationMode.Synchronous) + public virtual ISubflowActionBuilder Run(string workflowId, string invocationMode = InvocationMode.Synchronous) { if (string.IsNullOrWhiteSpace(workflowId)) throw new ArgumentNullException(nameof(workflowId)); diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs index f565bbd..85268b7 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs @@ -64,7 +64,7 @@ public virtual IFunctionBuilder WithName(string name) } /// - public virtual IFunctionBuilder OfType(FunctionType type) + public virtual IFunctionBuilder OfType(string type) { this.Function.Type = type; return this; diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs index f212cb1..35139f5 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs @@ -102,7 +102,7 @@ public interface IActionBuilder /// The version of the to run /// The 's . Defaults to /// The service used to build s - ISubflowActionBuilder Run(string workflowId, string version, InvocationMode invocationMode = InvocationMode.Synchronous); + ISubflowActionBuilder Run(string workflowId, string version, string invocationMode = InvocationMode.Synchronous); /// /// Configures the to build to run the specified @@ -110,7 +110,7 @@ public interface IActionBuilder /// The id of the to run /// The 's . Defaults to /// The service used to build s - ISubflowActionBuilder Run(string workflowId, InvocationMode invocationMode = InvocationMode.Synchronous); + ISubflowActionBuilder Run(string workflowId, string invocationMode = InvocationMode.Synchronous); /// /// Builds the diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs index e3d38f5..a3111f2 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs @@ -38,7 +38,7 @@ public interface IFunctionBuilder /// /// The type of the to build /// The configured - IFunctionBuilder OfType(FunctionType type); + IFunctionBuilder OfType(string type); /// /// Sets the 's operation expression. Sets the 's to diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs index 3848b17..58506ba 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs +++ b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs @@ -31,7 +31,7 @@ public interface IOAuth2AuthenticationBuilder /// /// The to use /// The configured - IOAuth2AuthenticationBuilder UseGranType(OAuth2GrantType grantType); + IOAuth2AuthenticationBuilder UseGranType(string grantType); /// /// Configures the to use the specified authority to generate an access token @@ -88,7 +88,7 @@ public interface IOAuth2AuthenticationBuilder /// The type of the specified token /// The subject token /// The configured - IOAuth2AuthenticationBuilder WithSubjectToken(OAuth2TokenType tokenType, string token); + IOAuth2AuthenticationBuilder WithSubjectToken(string tokenType, string token); /// /// Configures the token that represents the identity of the acting party.Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. @@ -96,7 +96,7 @@ public interface IOAuth2AuthenticationBuilder /// The type of the specified token /// The actor token /// The configured - IOAuth2AuthenticationBuilder WithActorToken(OAuth2TokenType tokenType, string token); + IOAuth2AuthenticationBuilder WithActorToken(string tokenType, string token); } diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs index f6731e7..c20dec1 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs +++ b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs @@ -57,7 +57,7 @@ public virtual IOAuth2AuthenticationBuilder UseAudiences(params string[] audienc } /// - public virtual IOAuth2AuthenticationBuilder UseGranType(OAuth2GrantType grantType) + public virtual IOAuth2AuthenticationBuilder UseGranType(string grantType) { this.Properties.GrantType = grantType; return this; @@ -118,7 +118,7 @@ public virtual IOAuth2AuthenticationBuilder WithPassword(string password) } /// - public virtual IOAuth2AuthenticationBuilder WithSubjectToken(OAuth2TokenType tokenType, string token) + public virtual IOAuth2AuthenticationBuilder WithSubjectToken(string tokenType, string token) { if (string.IsNullOrWhiteSpace(token)) throw new ArgumentNullException(nameof(token)); @@ -128,7 +128,7 @@ public virtual IOAuth2AuthenticationBuilder WithSubjectToken(OAuth2TokenType tok } /// - public virtual IOAuth2AuthenticationBuilder WithActorToken(OAuth2TokenType tokenType, string token) + public virtual IOAuth2AuthenticationBuilder WithActorToken(string tokenType, string token) { if (string.IsNullOrWhiteSpace(token)) throw new ArgumentNullException(nameof(token)); diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs b/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs index 982f04f..9abdf1d 100644 --- a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs +++ b/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs @@ -33,7 +33,7 @@ public interface IWorkflowWriter /// The to read the from /// The format of the to read. Defaults to '' /// A new - void Write(WorkflowDefinition workflow, Stream stream, WorkflowDefinitionFormat format = WorkflowDefinitionFormat.Yaml); + void Write(WorkflowDefinition workflow, Stream stream, string format = WorkflowDefinitionFormat.Yaml); } diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs index bd2a282..840d7c7 100644 --- a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs +++ b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs @@ -74,7 +74,7 @@ public virtual async Task ReadAsync(Stream stream, WorkflowR throw new ArgumentNullException(nameof(stream)); if(options == null) options = new WorkflowReaderOptions(); - ISerializer serializer; + Neuroglia.Serialization.ISerializer serializer; var offset = stream.Position; using var reader = new StreamReader(stream); var input = reader.ReadToEnd(); diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs index 5e47ce0..8927eff 100644 --- a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs +++ b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs @@ -37,7 +37,7 @@ public class WorkflowReaderOptions /// /// Gets/sets the to use. Defaults to /// - public virtual RelativeUriReferenceResolutionMode RelativeUriResolutionMode { get; set; } = RelativeUriReferenceResolutionMode.ConvertToRelativeFilePath; + public virtual string RelativeUriResolutionMode { get; set; } = RelativeUriReferenceResolutionMode.ConvertToRelativeFilePath; /// /// Gets/sets a boolean indicating whether or not to load external definitions diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs index 7e5e5ef..c94750a 100644 --- a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs +++ b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs @@ -50,13 +50,13 @@ public WorkflowWriter(IJsonSerializer jsonSerializer, IYamlSerializer yamlSerial protected IYamlSerializer YamlSerializer { get; } /// - public virtual void Write(WorkflowDefinition workflow, Stream stream, WorkflowDefinitionFormat format = WorkflowDefinitionFormat.Yaml) + public virtual void Write(WorkflowDefinition workflow, Stream stream, string format = WorkflowDefinitionFormat.Yaml) { if (workflow == null) throw new ArgumentNullException(nameof(workflow)); if (stream == null) throw new ArgumentNullException(nameof(stream)); - ISerializer serializer = format switch + Neuroglia.Serialization.ISerializer serializer = format switch { WorkflowDefinitionFormat.Json => this.JsonSerializer, WorkflowDefinitionFormat.Yaml => this.YamlSerializer, diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs index 32fad8d..7eecbcc 100644 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs @@ -60,7 +60,7 @@ public override bool IsValid(ValidationContext context, IEnu IEnumerable> validators = this.ServiceProvider.GetServices>(); foreach (IValidator validator in validators) { - ValidationResult validationResult = validator.Validate(elem); + FluentValidation.Results.ValidationResult validationResult = validator.Validate(elem); if (validationResult.IsValid) continue; foreach (var failure in validationResult.Errors) diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs index 42678a8..8e4490a 100644 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs @@ -46,7 +46,7 @@ public EventReferenceValidator(WorkflowDefinition workflow) .Must(BeProduced) .When(e => !string.IsNullOrWhiteSpace(e.ProduceEvent)) .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.ProduceEvent)}") - .WithMessage(eventRef => $"The event with name '{eventRef.ProduceEvent}' must be of kind '{EnumHelper.Stringify(EventKind.Produced)}'"); + .WithMessage(eventRef => $"The event with name '{eventRef.ProduceEvent}' must be of kind '{EventKind.Produced}'"); this.RuleFor(e => e.ResultEvent) .NotEmpty() .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.ResultEvent)}"); @@ -59,7 +59,7 @@ public EventReferenceValidator(WorkflowDefinition workflow) .Must(BeConsumed) .When(e => !string.IsNullOrWhiteSpace(e.ResultEvent)) .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.ResultEvent)}") - .WithMessage(eventRef => $"The event with name '{eventRef.ResultEvent}' must be of kind '{EnumHelper.Stringify(EventKind.Consumed)}'"); + .WithMessage(eventRef => $"The event with name '{eventRef.ResultEvent}' must be of kind '{EventKind.Consumed}'"); } /// diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs index b2c045e..63f1c31 100644 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs @@ -53,7 +53,7 @@ public EventStateTriggerDefinitionValidator(WorkflowDefinition workflow, EventSt .Must(BeConsumed) .When(t => t.Events != null && t.Events.Any()) .WithErrorCode($"{nameof(EventStateTriggerDefinition)}.{nameof(EventStateTriggerDefinition.Events)}") - .WithMessage(eventRef => $"The event with name '{eventRef}' must be of kind '{EnumHelper.Stringify(EventKind.Consumed)}' to be used in an event state trigger"); + .WithMessage(eventRef => $"The event with name '{eventRef}' must be of kind '{EventKind.Consumed}' to be used in an event state trigger"); } /// diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs index 654605c..5906141 100644 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs @@ -42,7 +42,7 @@ public override bool IsValid(ValidationContext context, IEnu foreach (FunctionDefinition function in value) { - ValidationResult validationResult = validator.Validate(function); + FluentValidation.Results.ValidationResult validationResult = validator.Validate(function); if (validationResult.IsValid) { index++; diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs index a9e1c36..51795d8 100644 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs @@ -17,8 +17,6 @@ using FluentValidation; using FluentValidation.Results; using ServerlessWorkflow.Sdk.Models; -using System; -using System.Linq; namespace ServerlessWorkflow.Sdk.Services.Validation { @@ -102,9 +100,9 @@ public WorkflowDefinitionValidator(IServiceProvider serviceProvider) protected IServiceProvider ServiceProvider { get; } /// - public override ValidationResult Validate(ValidationContext context) + public override FluentValidation.Results.ValidationResult Validate(ValidationContext context) { - ValidationResult validationResult = base.Validate(context); + FluentValidation.Results.ValidationResult validationResult = base.Validate(context); if (context.InstanceToValidate.States != null && !context.InstanceToValidate.States.Any(s => s.End != null)) validationResult.Errors.Add(new ValidationFailure("End", $"The workflow's main control flow must specify an EndDefinition")); diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs index 97f489b..4708a98 100644 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs @@ -19,114 +19,155 @@ using Newtonsoft.Json.Schema; using Octokit; using ServerlessWorkflow.Sdk.Models; -using System; using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; +using System.IO; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -namespace ServerlessWorkflow.Sdk.Services.Validation +namespace ServerlessWorkflow.Sdk.Services.Validation; + +/// +/// Represents the default implementation of the interface +/// +public class WorkflowSchemaValidator + : IWorkflowSchemaValidator { /// - /// Represents the default implementation of the interface + /// Initializes a new /// - public class WorkflowSchemaValidator - : IWorkflowSchemaValidator + /// The service used to serialize and deserialize JSON + /// The service used to create s + public WorkflowSchemaValidator(IJsonSerializer serializer, IHttpClientFactory httpClientFactory) { + this.Serializer = serializer; + this.HttpClient = httpClientFactory.CreateClient(); + } - /// - /// Initializes a new - /// - /// The service used to serialize and deserialize JSON - /// The service used to create s - public WorkflowSchemaValidator(IJsonSerializer serializer, IHttpClientFactory httpClientFactory) - { - this.Serializer = serializer; - this.HttpClient = httpClientFactory.CreateClient(); - } + /// + /// Gets the service used to serialize and deserialize JSON + /// + protected IJsonSerializer Serializer { get; } - /// - /// Gets the service used to serialize and deserialize JSON - /// - protected IJsonSerializer Serializer { get; } + /// + /// Gets the used to fetch the Serverless Workflow schema + /// + protected HttpClient HttpClient { get; } - /// - /// Gets the used to fetch the Serverless Workflow schema - /// - protected HttpClient HttpClient { get; } + /// + /// Gets a containing the loaded Serverless Workflow spec s + /// + protected ConcurrentDictionary Schemas { get; } = new(); - /// - /// Gets a containing the loaded Serverless Workflow spec s - /// - protected ConcurrentDictionary Schemas { get; } = new(); + /// + /// Gets the service used to resolve s by + /// + protected JSchemaPreloadedResolver SchemaResolver { get; } = new(); - /// - /// Gets the service used to resolve s by - /// - protected JSchemaPreloadedResolver SchemaResolver { get; } = new(); + /// + public virtual async Task> ValidateAsync(string workflowJson, string specVersion, CancellationToken cancellationToken = default) + { + var workflow = this.Serializer.Deserialize(workflowJson); + var schema = await this.LoadSpecificationSchemaAsync(specVersion, cancellationToken); + workflow.IsValid(schema, out IList validationErrors); + return validationErrors; + } - /// - public virtual async Task> ValidateAsync(string workflowJson, string specVersion, CancellationToken cancellationToken = default) + /// + public virtual async Task> ValidateAsync(WorkflowDefinition workflow, CancellationToken cancellationToken = default) + { + if (workflow == null) throw new ArgumentNullException(nameof(workflow)); + var serializerSettings = JsonConvert.DefaultSettings?.Invoke(); + if (serializerSettings == null) serializerSettings = new(); + serializerSettings.DefaultValueHandling = DefaultValueHandling.Populate | DefaultValueHandling.Ignore; + var obj = JObject.FromObject(workflow, Newtonsoft.Json.JsonSerializer.Create(serializerSettings)); + var schema = await this.LoadSpecificationSchemaAsync(workflow.SpecVersion, cancellationToken); + if(workflow.Extensions?.Any() == true) { - var workflow = this.Serializer.Deserialize(workflowJson); - var schema = await this.LoadSpecificationSchemaAsync(specVersion, cancellationToken); - workflow.IsValid(schema, out IList validationErrors); - return validationErrors; + var schemaObject = JObject.FromObject(schema, Newtonsoft.Json.JsonSerializer.Create(serializerSettings)); + foreach(var extension in workflow.Extensions) + { + var extensionSchemaObject = await this.GetExtensionSchemaObjectAsync(extension, cancellationToken); + schemaObject.Merge(extensionSchemaObject); + } + var json = JsonConvert.SerializeObject(schemaObject, serializerSettings); + schema = JSchema.Parse(json, this.SchemaResolver); } + obj.IsValid(schema, out IList validationErrors); + return validationErrors; + } - /// - public virtual async Task> ValidateAsync(WorkflowDefinition workflow, CancellationToken cancellationToken = default) + /// + /// Loads the Serverless Workflow + /// + /// The Serverless Workflow + protected virtual async Task LoadSpecificationSchemaAsync(string specVersion, CancellationToken cancellationToken = default) + { + if (this.Schemas.TryGetValue(specVersion, out var schema)) return schema; + var client = new GitHubClient(new ProductHeaderValue("serverless-workflow-sdk-net")); + var specJson = null as string; + foreach (var content in await client.Repository.Content.GetAllContentsByRef("serverlessworkflow", "specification", "schema", $"{specVersion[..3]}.x")) { - if (workflow == null) throw new ArgumentNullException(nameof(workflow)); - var serializerSettings = JsonConvert.DefaultSettings?.Invoke(); - if (serializerSettings == null) serializerSettings = new(); - serializerSettings.DefaultValueHandling = DefaultValueHandling.Include; - var obj = JObject.FromObject(workflow, Newtonsoft.Json.JsonSerializer.Create(serializerSettings)); - var schema = await this.LoadSpecificationSchemaAsync(workflow.SpecVersion, cancellationToken); - obj.IsValid(schema, out IList validationErrors); - return validationErrors; + if (string.IsNullOrWhiteSpace(content.DownloadUrl)) continue; + var json = await this.GetSpecificationSchemaJsonAsync(new(content.DownloadUrl), specVersion, cancellationToken); + if (content.Name == "workflow.json") specJson = json; } + schema = JSchema.Parse(specJson!, this.SchemaResolver); + this.Schemas.TryAdd(specVersion, schema); + return schema; + } - /// - /// Loads the Serverless Workflow - /// - /// The Serverless Workflow - protected virtual async Task LoadSpecificationSchemaAsync(string specVersion, CancellationToken cancellationToken = default) + /// + /// Retrieves the JSON content of the specified schema + /// + /// The of the referenced JSON schema + /// The Serverless Workflow specification version + /// A + /// The JSON content of the specified schema + protected virtual async Task GetSpecificationSchemaJsonAsync(Uri uri, string specVersion, CancellationToken cancellationToken = default) + { + using HttpResponseMessage response = await this.HttpClient.GetAsync(uri, cancellationToken); + var json = await response.Content?.ReadAsStringAsync(cancellationToken)!; + this.SchemaResolver.Add(new($"https://serverlessworkflow.io/schemas/{specVersion[..3]}/{uri.PathAndQuery.Split('/', StringSplitOptions.RemoveEmptyEntries).Last()}"), json); + return json; + } + + /// + /// Retrieves the JSON content of the specified 's schema + /// + /// The that defines the referenced JSON schema + /// A + /// The JSON content of the specified schema + protected virtual async Task GetExtensionSchemaObjectAsync(ExtensionDefinition extension, CancellationToken cancellationToken = default) + { + if(extension == null) throw new ArgumentNullException(nameof(extension)); + var uri = extension.Resource; + if (!uri.IsAbsoluteUri) uri = this.ResolveRelativeUri(uri); + string json; + if (uri.IsFile) { - if (this.Schemas.TryGetValue(specVersion, out var schema)) return schema; - var client = new GitHubClient(new ProductHeaderValue("serverless-workflow-sdk-net")); - var specJson = null as string; - foreach (var content in await client.Repository.Content.GetAllContentsByRef("serverlessworkflow", "specification", "schema", $"{specVersion[..3]}.x")) - { - if (string.IsNullOrWhiteSpace(content.DownloadUrl)) - continue; - var json = await this.GetSchemaJsonAsync(new(content.DownloadUrl), specVersion, cancellationToken); - if (content.Name == "workflow.json") - specJson = json; - } - schema = JSchema.Parse(specJson!, this.SchemaResolver); - this.Schemas.TryAdd(specVersion, schema); - return schema; + json = await File.ReadAllTextAsync(uri.LocalPath, cancellationToken); } - - /// - /// Retrieves the JSON content of the specified schema - /// - /// The of the referenced JSON schema - /// The Serverless Workflow specification version - /// A - /// The JSON content of the specified schema - protected virtual async Task GetSchemaJsonAsync(Uri uri, string specVersion, CancellationToken cancellationToken = default) + else { using HttpResponseMessage response = await this.HttpClient.GetAsync(uri, cancellationToken); - var json = await response.Content?.ReadAsStringAsync(cancellationToken)!; - this.SchemaResolver.Add(new($"https://serverlessworkflow.io/schemas/{specVersion[..3]}/{uri.PathAndQuery.Split('/', StringSplitOptions.RemoveEmptyEntries).Last()}"), json); - return json; + json = await response.Content?.ReadAsStringAsync(cancellationToken)!; } + return JObject.Parse(json)!; + } + /// + /// Resolves the specified relative + /// + /// The relative to resolve + /// The resolved + protected virtual Uri ResolveRelativeUri(Uri uri) + { + if (uri == null) throw new ArgumentNullException(nameof(uri)); + var localPath = uri.ToString(); + if (localPath.StartsWith("//") || localPath.StartsWith("\\\\")) localPath = localPath.Substring(2); + return new Uri(Path.Combine(AppContext.BaseDirectory, localPath)); } } diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs index d5b7beb..7c81b24 100644 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs @@ -77,7 +77,7 @@ public override bool IsValid(ValidationContext context, List m.Name == nameof(IValidator.Validate) && m.GetParameters().Length == 1 && m.GetParameters().First().ParameterType != typeof(IValidationContext)); - var validationResult = (ValidationResult)validationMethod.Invoke(validator, args)!; + var validationResult = (FluentValidation.Results.ValidationResult)validationMethod.Invoke(validator, args)!; if (validationResult.IsValid) continue; foreach (var failure in validationResult.Errors) diff --git a/src/ServerlessWorkflow.Sdk/StateType.cs b/src/ServerlessWorkflow.Sdk/StateType.cs index 2fb70e3..5bb21a2 100644 --- a/src/ServerlessWorkflow.Sdk/StateType.cs +++ b/src/ServerlessWorkflow.Sdk/StateType.cs @@ -15,56 +15,57 @@ * */ -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all types of workflow states +/// +public static class StateType { /// - /// Enumerates all types of workflow states + /// Indicates an operation state + /// + public const string Operation = "operation"; + + /// + /// Indicates a sleep state + /// + public const string Sleep = "sleep"; + + /// + /// Indicates an event state + /// + public const string Event = "event"; + + /// + /// Indicates a parallel state + /// + public const string Parallel = "parallel"; + + /// + /// Indicates a switch state + /// + public const string Switch = "switch"; + + /// + /// Indicates an inject state + /// + public const string Inject = "inject"; + + /// + /// Indicates a foreach state + /// + public const string ForEach = "foreach"; + + /// + /// Indicates a callback state + /// + public const string Callback = "callback"; + + /// + /// Indicates an extension (custom) state /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum StateType - { - /// - /// Indicates an operation state - /// - [EnumMember(Value = "operation")] - Operation = 1, - /// - /// Indicates a sleep state - /// - [EnumMember(Value = "sleep")] - Sleep = 2, - /// - /// Indicates an event state - /// - [EnumMember(Value = "event")] - Event = 4, - /// - /// Indicates a parallel state - /// - [EnumMember(Value = "parallel")] - Parallel = 8, - /// - /// Indicates a switch state - /// - [EnumMember(Value = "switch")] - Switch = 16, - /// - /// Indicates an inject state - /// - [EnumMember(Value = "inject")] - Inject = 32, - /// - /// Indicates a foreach state - /// - [EnumMember(Value = "foreach")] - ForEach = 64, - /// - /// Indicates a callback state - /// - [EnumMember(Value = "callback")] - Callback = 128 - } + public const string Extension = "extension"; } diff --git a/src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs b/src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs index 21914df..c54ee9d 100644 --- a/src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs +++ b/src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs @@ -14,28 +14,23 @@ * limitations under the License. * */ -using System.Runtime.Serialization; -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all types of conditions +/// +public static class SwitchCaseOutcomeType { /// - /// Enumerates all types of conditions + /// Indicates a transition condition + /// + public const string Transition = "transition"; + + /// + /// Indicates an end condition /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum SwitchCaseOutcomeType - { - /// - /// Indicates a transition condition - /// - [EnumMember(Value = "transition")] - Transition = 1, - /// - /// Indicates an end condition - /// - [EnumMember(Value = "end")] - End = 2 - } + public const string End = "end"; } diff --git a/src/ServerlessWorkflow.Sdk/SwitchStateType.cs b/src/ServerlessWorkflow.Sdk/SwitchStateType.cs index 0883f87..7e82453 100644 --- a/src/ServerlessWorkflow.Sdk/SwitchStateType.cs +++ b/src/ServerlessWorkflow.Sdk/SwitchStateType.cs @@ -14,28 +14,23 @@ * limitations under the License. * */ -using System.Runtime.Serialization; -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all types of switch states +/// +public static class SwitchStateType { /// - /// Enumerates all types of switch states + /// Indicates a data switch + /// + public const string Data = "data"; + + /// + /// Indicates an event switch /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum SwitchStateType - { - /// - /// Indicates a data switch - /// - [EnumMember(Value = "data")] - Data = 1, - /// - /// Indicates an event switch - /// - [EnumMember(Value = "event")] - Event = 2 - } + public const string Event = "event"; } diff --git a/src/ServerlessWorkflow.Sdk/WorkflowDefinitionFormat.cs b/src/ServerlessWorkflow.Sdk/WorkflowDefinitionFormat.cs index 1f59b03..e9e22a5 100644 --- a/src/ServerlessWorkflow.Sdk/WorkflowDefinitionFormat.cs +++ b/src/ServerlessWorkflow.Sdk/WorkflowDefinitionFormat.cs @@ -14,28 +14,23 @@ * limitations under the License. * */ -using System.Runtime.Serialization; -namespace ServerlessWorkflow.Sdk +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all workflow definition formats +/// +public static class WorkflowDefinitionFormat { /// - /// Enumerates all workflow definition formats + /// Indicates YAML + /// + public const string Yaml = "yaml"; + + /// + /// Indicates JSON /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.StringEnumConverterFactory))] - public enum WorkflowDefinitionFormat - { - /// - /// Indicates YAML - /// - [EnumMember(Value = "yaml")] - Yaml = 1, - /// - /// Indicates JSON - /// - [EnumMember(Value = "json")] - Json = 2 - } + public const string Json = "json"; } 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