Skip to content

Commit

Permalink
fix(Sdk): Hide OneOf properties from users, and instead add propertie…
Browse files Browse the repository at this point in the history
…s for its the type alternatives it encapsulates

Signed-off-by: Charles d'Avernas <charles.davernas@neuroglia.io>
  • Loading branch information
cdavernas committed Aug 21, 2024
1 parent 6eab8a1 commit d5196bd
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha2.10</VersionSuffix>
<VersionSuffix>alpha2.11</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha2.10</VersionSuffix>
<VersionSuffix>alpha2.11</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
26 changes: 23 additions & 3 deletions src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,31 @@ public record HttpCallDefinition
public required virtual string Method { get; set; }

/// <summary>
/// Gets/sets the definition of the endpoint to request
/// Gets/sets the endpoint at which to get the defined resource
/// </summary>
[IgnoreDataMember, JsonIgnore, YamlIgnore]
public virtual EndpointDefinition Endpoint
{
get => this.EndpointValue.T1Value ?? new() { Uri = this.EndpointUri };
set => this.EndpointValue = value;
}

/// <summary>
/// Gets/sets the endpoint at which to get the defined resource
/// </summary>
[IgnoreDataMember, JsonIgnore, YamlIgnore]
public virtual Uri EndpointUri
{
get => this.EndpointValue.T1Value?.Uri ?? this.EndpointValue.T2Value!;
set => this.EndpointValue = value;
}

/// <summary>
/// Gets/sets the endpoint at which to get the defined resource
/// </summary>
[Required]
[DataMember(Name = "endpoint", Order = 2), JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)]
public required virtual OneOf<EndpointDefinition, Uri> Endpoint { get; set; }
[DataMember(Name = "endpoint", Order = 2), JsonInclude, JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)]
protected virtual OneOf<EndpointDefinition, Uri> EndpointValue { get; set; } = null!;

/// <summary>
/// Gets/sets a name/value mapping of the headers, if any, of the HTTP request to perform
Expand Down
24 changes: 22 additions & 2 deletions src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
/// Gets/sets the endpoint at which to get the defined resource
/// </summary>
[IgnoreDataMember, JsonIgnore, YamlIgnore]
public virtual EndpointDefinition Endpoint
{
get => this.EndpointValue.T1Value ?? new() { Uri = this.EndpointUri };
set => this.EndpointValue = value;
}

/// <summary>
/// Gets/sets the endpoint at which to get the defined resource
/// </summary>
[IgnoreDataMember, JsonIgnore, YamlIgnore]
public virtual Uri EndpointUri
{
get => this.EndpointValue.T1Value?.Uri ?? this.EndpointValue.T2Value!;
set => this.EndpointValue = value;
}

/// <summary>
/// Gets/sets the endpoint at which to get the defined resource
/// </summary>
[Required]
[DataMember(Name = "endpoint", Order = 2), JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)]
public virtual OneOf<EndpointDefinition, Uri> Endpoint { get; set; } = null!;
[DataMember(Name = "endpoint", Order = 2), JsonInclude, JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)]
protected virtual OneOf<EndpointDefinition, Uri> EndpointValue { get; set; } = null!;

}
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha2.10</VersionSuffix>
<VersionSuffix>alpha2.11</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down

0 comments on commit d5196bd

Please sign in to comment.