From d5196bd883de5af5efeb0162e4090c57c31206e6 Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Wed, 21 Aug 2024 12:52:59 +0200 Subject: [PATCH] fix(Sdk): Hide OneOf properties from users, and instead add properties for its the type alternatives it encapsulates Signed-off-by: Charles d'Avernas --- .../ScriptProcessDefinitionBuilder.cs | 4 +-- .../ServerlessWorkflow.Sdk.Builders.csproj | 2 +- .../ServerlessWorkflow.Sdk.IO.csproj | 2 +- .../Models/Calls/HttpCallDefinition.cs | 26 ++++++++++++++++--- .../Models/ExternalResourceDefinition.cs | 24 +++++++++++++++-- .../ServerlessWorkflow.Sdk.csproj | 2 +- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs index 24f86ed..7db5d67 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs @@ -133,8 +133,8 @@ public override ScriptProcessDefinition Build() Arguments = this.Arguments, Environment = this.Environment }; - if(this.Source != null) process.Source = this.Source; - else if(this.SourceUri != null) process.Source = new() { Endpoint = this.SourceUri }; + if (this.Source != null) process.Source = this.Source; + else if (this.SourceUri != null) process.Source = new() { EndpointUri = this.SourceUri }; return process; } diff --git a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj index 757d8a9..7f63970 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj +++ b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha2.10 + alpha2.11 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj index d0eb938..14fdd03 100644 --- a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj +++ b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha2.10 + alpha2.11 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs index b78749c..82fff94 100644 --- a/src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs @@ -29,11 +29,31 @@ public record HttpCallDefinition public required virtual string Method { get; set; } /// - /// Gets/sets the definition of the endpoint to request + /// Gets/sets the endpoint at which to get the defined resource + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual EndpointDefinition Endpoint + { + get => this.EndpointValue.T1Value ?? new() { Uri = this.EndpointUri }; + set => this.EndpointValue = value; + } + + /// + /// Gets/sets the endpoint at which to get the defined resource + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual Uri EndpointUri + { + get => this.EndpointValue.T1Value?.Uri ?? this.EndpointValue.T2Value!; + set => this.EndpointValue = value; + } + + /// + /// Gets/sets the endpoint at which to get the defined resource /// [Required] - [DataMember(Name = "endpoint", Order = 2), JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)] - public required virtual OneOf Endpoint { get; set; } + [DataMember(Name = "endpoint", Order = 2), JsonInclude, JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)] + protected virtual OneOf EndpointValue { get; set; } = null!; /// /// Gets/sets a name/value mapping of the headers, if any, of the HTTP request to perform diff --git a/src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs index 30c9e1f..2b82108 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs @@ -26,11 +26,31 @@ public record ExternalResourceDefinition [DataMember(Name = "name", Order = 1), JsonPropertyName("name"), JsonPropertyOrder(1), YamlMember(Alias = "name", Order = 1)] public virtual string? Name { get; set; } + /// + /// Gets/sets the endpoint at which to get the defined resource + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual EndpointDefinition Endpoint + { + get => this.EndpointValue.T1Value ?? new() { Uri = this.EndpointUri }; + set => this.EndpointValue = value; + } + + /// + /// Gets/sets the endpoint at which to get the defined resource + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual Uri EndpointUri + { + get => this.EndpointValue.T1Value?.Uri ?? this.EndpointValue.T2Value!; + set => this.EndpointValue = value; + } + /// /// Gets/sets the endpoint at which to get the defined resource /// [Required] - [DataMember(Name = "endpoint", Order = 2), JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)] - public virtual OneOf Endpoint { get; set; } = null!; + [DataMember(Name = "endpoint", Order = 2), JsonInclude, JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)] + protected virtual OneOf EndpointValue { get; set; } = null!; } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj index 1f39806..49e268b 100644 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj +++ b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha2.10 + alpha2.11 $(VersionPrefix) $(VersionPrefix) en