-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from serverlessworkflow/feat-catalog-component
Added a new `CatalogDefinition` model
- Loading branch information
Showing
11 changed files
with
229 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright © 2024-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; | ||
|
||
/// <summary> | ||
/// Represents the definition of a workflow component catalog | ||
/// </summary> | ||
[DataContract] | ||
public record CatalogDefinition | ||
{ | ||
|
||
/// <summary> | ||
/// Gets the name of the default catalog | ||
/// </summary> | ||
public const string DefaultCatalogName = "default"; | ||
|
||
/// <summary> | ||
/// Gets/sets the endpoint that defines the root URL at which the catalog is located | ||
/// </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 that defines the root URL at which the catalog is located | ||
/// </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 that defines the root URL at which the catalog is located | ||
/// </summary> | ||
[Required] | ||
[DataMember(Name = "endpoint", Order = 1), JsonInclude, JsonPropertyName("endpoint"), JsonPropertyOrder(1), YamlMember(Alias = "endpoint", Order = 1)] | ||
protected virtual OneOf<EndpointDefinition, Uri> EndpointValue { get; set; } = null!; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/ServerlessWorkflow.Sdk/Properties/ValidationErrors.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/ServerlessWorkflow.Sdk/Validation/CatalogDefinitionValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright © 2024-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. | ||
|
||
using FluentValidation; | ||
using ServerlessWorkflow.Sdk.Models; | ||
|
||
namespace ServerlessWorkflow.Sdk.Validation; | ||
|
||
/// <summary> | ||
/// Represents the <see cref="IValidator"/> used to validate <see cref="CatalogDefinition"/>s | ||
/// </summary> | ||
public class CatalogDefinitionValidator | ||
: AbstractValidator<CatalogDefinition> | ||
{ | ||
|
||
/// <inheritdoc/> | ||
public CatalogDefinitionValidator(IServiceProvider serviceProvider) | ||
{ | ||
this.ServiceProvider = serviceProvider; | ||
this.RuleFor(c => c.Endpoint) | ||
.NotNull() | ||
.When(c => c.EndpointUri == null); | ||
this.RuleFor(c => c.EndpointUri) | ||
.NotNull() | ||
.When(c => c.Endpoint == null); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the current <see cref="IServiceProvider"/> | ||
/// </summary> | ||
protected IServiceProvider ServiceProvider { get; } | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/ServerlessWorkflow.Sdk/Validation/CatalogKeyValuePairValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © 2024-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. | ||
|
||
using FluentValidation; | ||
using ServerlessWorkflow.Sdk.Models; | ||
|
||
namespace ServerlessWorkflow.Sdk.Validation; | ||
|
||
/// <summary> | ||
/// Represents the <see cref="IValidator"/> used to validate <see cref="CatalogDefinition"/> key/value pairs | ||
/// </summary> | ||
public class CatalogKeyValuePairValidator | ||
: AbstractValidator<KeyValuePair<string, CatalogDefinition>> | ||
{ | ||
|
||
/// <inheritdoc/> | ||
public CatalogKeyValuePairValidator(IServiceProvider serviceProvider) | ||
{ | ||
this.ServiceProvider = serviceProvider; | ||
this.RuleFor(t => t.Value) | ||
.Custom((value, context) => | ||
{ | ||
var key = context.InstanceToValidate.Key; | ||
var validator = new CatalogDefinitionValidator(serviceProvider); | ||
var validationResult = validator.Validate(value); | ||
foreach (var error in validationResult.Errors) context.AddFailure($"{key}.{error.PropertyName}", error.ErrorMessage); | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the current <see cref="IServiceProvider"/> | ||
/// </summary> | ||
protected IServiceProvider ServiceProvider { get; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters