ServerlessWorkflow.Sdk
0.8.8
Prefix Reserved
See the version list below for details.
dotnet add package ServerlessWorkflow.Sdk --version 0.8.8
NuGet\Install-Package ServerlessWorkflow.Sdk -Version 0.8.8
<PackageReference Include="ServerlessWorkflow.Sdk" Version="0.8.8" />
paket add ServerlessWorkflow.Sdk --version 0.8.8
#r "nuget: ServerlessWorkflow.Sdk, 0.8.8"
// Install ServerlessWorkflow.Sdk as a Cake Addin #addin nuget:?package=ServerlessWorkflow.Sdk&version=0.8.8 // Install ServerlessWorkflow.Sdk as a Cake Tool #tool nuget:?package=ServerlessWorkflow.Sdk&version=0.8.8
Serverless Workflow Specification - .NET SDK
Provides .NET 7.0 API/SPI and Model Validation for the Serverless Workflow Specification
With the SDK, you can:
- Read and write workflow JSON and YAML definitions
- Programmatically build workflow definitions
- Validate workflow definitions (both schema and DSL integrity validation)
Status
Latest Releases | Conformance to spec version |
---|---|
0.8.7 | 0.8 |
Getting Started
dotnet nuget add package ServerlessWorkflow.Sdk
services.AddServerlessWorkflow();
Usage
Build workflows programatically
var workflow = WorkflowDefinition.Create("MyWorkflow", "MyWorkflow", "1.0")
.StartsWith("inject", flow =>
flow.Inject(new { username = "test", password = "123456" }))
.Then("operation", flow =>
flow.Execute("fakeApiFunctionCall", action =>
{
action.Invoke(function =>
function.WithName("fakeFunction")
.SetOperationUri(new Uri("https://fake.com/swagger.json#fake")))
.WithArgument("username", "${ .username }")
.WithArgument("password", "${ .password }");
})
.Execute("fakeEventTrigger", action =>
{
action
.Consume(e =>
e.WithName("fakeEvent")
.WithSource(new Uri("https://fakesource.com"))
.WithType("fakeType"))
.ThenProduce(e =>
e.WithName("otherEvent")
.WithSource(new Uri("https://fakesource.com"))
.WithType("fakeType"));
}))
.End()
.Build();
Read workflows
var reader = WorkflowReader.Create();
using(Stream stream = File.OpenRead("myWorkflow.json"))
{
var definition = reader.Read(stream, WorkflowDefinitionFormat.Json);
}
Write workflows
var writer = WorkflowWriter.Create();
using(Stream stream = new MemoryStream())
{
writer.Write(workflow, stream);
stream.Flush();
stream.Position = 0;
using(StreamReader reader = new StreamReader(stream))
{
var yaml = reader.ReadToEnd();
Console.WriteLine(yaml);
Console.ReadLine();
}
}
Validate workflows
var validator = serviceProvider.GetRequiredService<IValidator<WorkflowDefinition>>();
var validationResult = validator.Validate(myWorkflow);
Extend Workflows
The SDK allows extending the Serverless Workflow in two ways, possibly combined: via metadata and via extensions.
Metadata
Workflow components that support metadata, such as WorkflowDefinition
or StateDefinition
, expose a metadata
property,
which is a dynamic name/value mapping of properties used to enrich the serverless workflow model with information beyond its core definitions.
It has the advantage of being an easy, cross-compatible way of declaring additional data, but lacks well-defined, well-documented schema of the data, thus loosing the ability to validate it without custom implementation.
Adding metadata to a workflow:
var workflow = new WorkflowBuilder()
...
.WithMetadata(new Dictionary<string, object>() { { "metadataPropertyName", metadataPropertyValue } })
...
.Build();
Resulting workflow:
id: sample-workflow
version: 1.0.0
specVersion: 0.8
metadata:
metadataPropertyName: metadataPropertyValue #added to the metadata property of supporting components
...
Extension
Users have the ability to define extensions, providing the ability to extend, override or replace parts of the Serverless Workflow schema.
To do so, you must first create a file containing the JsonSchema of your extension, then reference it in your workflow definition.
Schema of a sample extension that adds a new greet
functionType
:
<table>
<tr>
<th>JSON</th>
<th>YAML</th>
</tr>
<tr>
<td valign="top">
{
"$defs": {
"functions": {
"definitions": {
"function": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "Defines the function type. Is either `rest`, `asyncapi, `rpc`, `graphql`, `odata`, `expression` or `greet`. Default is `rest`",
"enum": [
"rest",
"asyncapi",
"rpc",
"graphql",
"odata",
"expression",
"custom",
"greet"
],
"default": "rest"
}
}
}
}
}
}
}
</td>
<td valign="top">
'$defs':
functions:
definitions:
function:
type: object
properties:
type:
type: string
description: Defines the function type. Is either `rest`, `asyncapi, `rpc`,
`graphql`, `odata`, `expression` or `greet`. Default is `rest`
enum:
- rest
- asyncapi
- rpc
- graphql
- odata
- expression
- custom
- greet
default: rest
</td> </tr> </table>
The above example refers to /$defs/functions
, because upon validation the SDK bundles all the Serverless Workflow Specification's schemas into the $defs
property of a single schema.
*In this case, functions
is the extensionless name of the schema file we want to override (https://serverlessworkflow.io/schemas/latest/functions.json).
A Json Merge Patch is performed sequentially on the bundled schema with the defined extensions, in declaring order.
In this case, the above schema will patch the object defined at /functions/definitions/function
in file https://serverlessworkflow.io/schemas/latest/functions.json
Extending a workflow:
var workflow = new WorkflowBuilder()
.WithId("sample-extended")
.WithName("Sample Extended Workflow")
.WithVersion("1.0.0")
.UseSpecVersion(ServerlessWorkflowSpecVersion.V08)
.UseExtension("extensionId", new Uri("file://.../extensions/greet-function-type.json"))
.StartsWith("do-work", flow => flow.Execute("greet", action => action
.Invoke(function => function
.OfType("greet")
.WithName("greet")
.ForOperation("#"))))
.End()
.Build();
Adding extension properties:
var workflow = new WorkflowBuilder()
...
.WithExtensionProperty("extensionPropertyName", propertyValue } })
...
.Build();
Resulting workflow:
id: sample-workflow
version: 1.0.0
specVersion: 0.8
extensionPropertyName: propertyValue #added as top level property of extended component, as opposed to metadata
...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Cronos (>= 0.7.1)
- FluentValidation.DependencyInjectionExtensions (>= 11.5.2)
- Iso8601DurationHelper (>= 1.1.0)
- JsonCons.Utilities (>= 1.0.0)
- JsonSchema.Net (>= 4.1.5)
- Microsoft.Extensions.Http (>= 7.0.0)
- Neuroglia.Serialization.Json (>= 2.1.3)
- YamlDotNet (>= 13.1.1)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on ServerlessWorkflow.Sdk:
Package | Downloads |
---|---|
Synapse.Integration
This package contains everything you need to integrate Synapse WFMS and its APIs |
|
ServerlessWorkflow.Sdk.IO
Contains services used to read and write ServerlessWorkflow workflow definitions |
|
ServerlessWorkflow.Sdk.Builders
Contains services used to build ServerlessWorkflow workflow definitions programatically |
|
Synapse.Sdk
Contains the definitions for all resources used by Synapse |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on ServerlessWorkflow.Sdk:
Repository | Stars |
---|---|
serverlessworkflow/synapse
Serverless Workflow Management System (WFMS)
|
Version | Downloads | Last updated | |
---|---|---|---|
1.0.0-alpha5.1 | 211 | 10/25/2024 | |
1.0.0-alpha5 | 153 | 10/22/2024 | |
1.0.0-alpha4.1 | 53 | 10/22/2024 | |
1.0.0-alpha4 | 122 | 10/18/2024 | |
1.0.0-alpha3.1 | 66 | 10/18/2024 | |
1.0.0-alpha3 | 301 | 10/11/2024 | |
1.0.0-alpha2.16 | 163 | 10/1/2024 | |
1.0.0-alpha2.15 | 464 | 9/8/2024 | |
1.0.0-alpha2.14 | 66 | 9/6/2024 | |
1.0.0-alpha2.13 | 53 | 9/6/2024 | |
1.0.0-alpha2.12 | 166 | 8/30/2024 | |
1.0.0-alpha2.11 | 127 | 8/21/2024 | |
1.0.0-alpha2.10 | 68 | 8/21/2024 | |
1.0.0-alpha2.9 | 70 | 8/21/2024 | |
1.0.0-alpha2.8 | 117 | 8/9/2024 | |
1.0.0-alpha2.7 | 66 | 8/8/2024 | |
1.0.0-alpha2.6 | 64 | 6/27/2024 | |
1.0.0-alpha2.5 | 111 | 6/26/2024 | |
1.0.0-alpha2.4 | 50 | 6/26/2024 | |
1.0.0-alpha2.3 | 47 | 6/26/2024 | |
1.0.0-alpha2.2 | 54 | 6/25/2024 | |
1.0.0-alpha2.1 | 73 | 6/21/2024 | |
1.0.0-alpha2 | 94 | 6/19/2024 | |
1.0.0-alpha1 | 216 | 5/22/2024 | |
0.8.8 | 259 | 1/4/2024 | |
0.8.7 | 790 | 6/29/2023 | |
0.8.6 | 372 | 11/30/2022 | |
0.8.5 | 346 | 11/18/2022 | |
0.8.4 | 14,469 | 11/4/2022 | |
0.8.3 | 7,664 | 10/26/2022 | |
0.8.2 | 409 | 9/30/2022 | |
0.8.1.16 | 4,442 | 9/28/2022 | |
0.8.1.15 | 1,617 | 9/22/2022 | |
0.8.1.14 | 3,711 | 9/9/2022 | |
0.8.1.13 | 415 | 9/7/2022 | |
0.8.1.12 | 402 | 9/7/2022 | |
0.8.1.11 | 6,066 | 8/30/2022 | |
0.8.1.10 | 2,691 | 8/23/2022 | |
0.8.1.9 | 440 | 8/23/2022 | |
0.8.1.8 | 3,855 | 8/11/2022 | |
0.8.1.7 | 1,585 | 8/9/2022 | |
0.8.1.6 | 1,741 | 5/20/2022 | |
0.8.1.5 | 438 | 5/20/2022 | |
0.8.1.4 | 476 | 5/18/2022 | |
0.8.1.3 | 436 | 5/17/2022 | |
0.8.1.2 | 459 | 5/17/2022 | |
0.8.1.1 | 414 | 5/17/2022 | |
0.8.1 | 426 | 5/16/2022 | |
0.8.0.22 | 427 | 5/16/2022 | |
0.8.0.21 | 522 | 5/10/2022 | |
0.8.0.20 | 657 | 4/14/2022 | |
0.8.0.19 | 591 | 4/14/2022 | |
0.8.0.18 | 441 | 4/14/2022 | |
0.8.0.17 | 457 | 4/13/2022 | |
0.8.0.16 | 444 | 4/13/2022 | |
0.8.0.15 | 584 | 3/7/2022 | |
0.8.0.14 | 429 | 3/7/2022 | |
0.8.0.13 | 470 | 3/3/2022 | |
0.8.0.12 | 438 | 3/2/2022 | |
0.8.0.11 | 456 | 2/25/2022 | |
0.8.0.10 | 459 | 2/24/2022 | |
0.8.0.9 | 469 | 2/24/2022 | |
0.8.0.8 | 436 | 2/23/2022 | |
0.8.0.7 | 424 | 2/23/2022 | |
0.8.0.6 | 439 | 2/22/2022 | |
0.8.0.5 | 419 | 2/21/2022 | |
0.8.0.4 | 430 | 2/21/2022 | |
0.8.0.3 | 450 | 2/18/2022 | |
0.8.0.2 | 443 | 2/15/2022 | |
0.8.0.1 | 425 | 2/14/2022 | |
0.8.0 | 459 | 2/14/2022 | |
0.7.4.4 | 392 | 7/2/2021 | |
0.7.4.3 | 369 | 7/2/2021 | |
0.7.4.2 | 317 | 7/2/2021 | |
0.7.4.1 | 301 | 7/1/2021 | |
0.7.4 | 346 | 7/1/2021 | |
0.7.3 | 316 | 6/16/2021 | |
0.7.2 | 348 | 6/8/2021 | |
0.7.1 | 367 | 6/3/2021 | |
0.7.0 | 311 | 6/2/2021 | |
0.6.3 | 368 | 5/27/2021 | |
0.6.2 | 341 | 5/27/2021 | |
0.6.1 | 801 | 4/19/2021 | |
0.6.0 | 380 | 4/3/2021 |