AsyncAPI.NET
6.0.0-beta.92
See the version list below for details.
dotnet add package AsyncAPI.NET --version 6.0.0-beta.92
NuGet\Install-Package AsyncAPI.NET -Version 6.0.0-beta.92
<PackageReference Include="AsyncAPI.NET" Version="6.0.0-beta.92" />
paket add AsyncAPI.NET --version 6.0.0-beta.92
#r "nuget: AsyncAPI.NET, 6.0.0-beta.92"
// Install AsyncAPI.NET as a Cake Addin #addin nuget:?package=AsyncAPI.NET&version=6.0.0-beta.92&prerelease // Install AsyncAPI.NET as a Cake Tool #tool nuget:?package=AsyncAPI.NET&version=6.0.0-beta.92&prerelease
AsyncAPI.NET
The AsyncAPI.NET SDK contains a useful object model for the AsyncAPI specification in .NET along with common serializers to extract raw AsyncAPI JSON and YAML documents from the model as well.
CHANGELOG
Wiki and getting started guide
Installation
Install the NuGet packages:
AsyncAPI.NET
AsyncAPI.Readers
AsyncAPI.Bindings
Example Usage
Main classes to know:
- AsyncApiStringReader
- AsyncApiStringWriter
- There is an extension on the AsyncApiDocument type which allows Serializing as well (
new AsyncApiDocument().SerializeAsJson()
ornew AsyncApiDocument().SerializeAsYaml()
- There is an extension on the AsyncApiDocument type which allows Serializing as well (
Writing
var myFirstAsyncApi = new AsyncApiDocument
{
Info = new AsyncApiInfo
{
Title = "my first asyncapi"
},
Channels = new Dictionary<string, AsyncApiChannel>
{
{
"users", new AsyncApiChannel
{
Subscribe = new AsyncApiOperation
{
OperationId = "users",
Description = "my users channel"
}
}
}
}
};
var yaml = myFirstAsyncApi.SerializeAsYaml();
//asyncapi: '2.5.0'
// info:
// title: my first asyncapi
// channels:
// users:
// subscribe:
// operationId: users
// description: my users channel
Reading
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://raw.githubusercontent.com/asyncapi/spec/"),
};
var stream = await httpClient.GetStreamAsync("master/examples/streetlights-kafka.yml");
var asyncApiDocument = new AsyncApiStreamReader().Read(stream, out var diagnostic);
Reading External $ref
You can read externally referenced AsyncAPI documents by setting the ReferenceResolution
property of the AsyncApiReaderSettings
object to ReferenceResolutionSetting.ResolveAllReferences
and providing an implementation for the IAsyncApiExternalReferenceReader
interface. This interface contains a single method to which the built AsyncAPI.NET reader library will pass the location content contained in a $ref
property (usually some form of path) and interface will return the content which is retrieved from wherever the $ref
points to as a string
. The AsyncAPI.NET reader will then automatically infer the T
type of the content and recursively parse the external content into an AsyncAPI document as a child of the original document that contained the $ref
. This means that you can have externally referenced documents that themselves contain external references.
This interface allows users to load the content of their external reference however and from whereever is required. A new instance of the implementor of IAsyncApiExternalReferenceReader
should be registered with the ExternalReferenceReader
property of the AsyncApiReaderSettings
when creating the reader from which the GetExternalResource
method will be called when resolving external references.
Below is a very simple example of implementation for IAsyncApiExternalReferenceReader
that simply loads a file and returns it as a string found at the reference endpoint.
using System.IO;
public class AsyncApiExternalFileSystemReader : IAsyncApiExternalReferenceReader
{
public string Load(string reference)
{
return File.ReadAllText(reference);
}
}
This can then be configured in the reader as follows:
var settings = new AsyncApiReaderSettings
{
ReferenceResolution = ReferenceResolutionSetting.ResolveAllReferences,
ExternalReferenceReader = new AsyncApiExternalFileSystemReader(),
};
var reader = new AsyncApiStringReader(settings);
This would function for a AsyncAPI document with following reference to load the content of message.yaml
as a AsyncApiMessage
object inline with the document object.
asyncapi: 2.3.0
info:
title: test
version: 1.0.0
channels:
workspace:
publish:
message:
$ref: "../../../message.yaml"
Bindings
To add support for reading bindings, simply add the bindings you wish to support, to the Bindings
collection of AsyncApiReaderSettings
.
There is a nifty helper to add different types of bindings, or like in the example All
of them.
var settings = new AsyncApiReaderSettings();
settings.Bindings = BindingsCollection.All;
var asyncApiDocument = new AsyncApiStringReader(settings).Read(stream, out var diagnostic);
Attribution
Contribution
This project welcomes contributions and suggestions. Do you want to contribute to the project? Find out how here.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Text.Json (>= 8.0.2)
-
net6.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on AsyncAPI.NET:
Package | Downloads |
---|---|
AsyncAPI.NET.Readers
AsyncAPI.NET Readers for JSON and YAML documents |
|
AsyncAPI.NET.Bindings
AsyncAPI.NET Bindings |
|
Benzene.Schema.OpenApi
Package Description |
|
AsyncAPI.Net.UI
A .Net library to generate AsyncAPI documentation by code first, to easily share and maintain your event-driven architecture. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.0.0-beta.99 | 367 | 10/25/2024 |
6.0.0-beta.98 | 53 | 10/14/2024 |
6.0.0-beta.97 | 1,653 | 9/4/2024 |
6.0.0-beta.96 | 83 | 8/22/2024 |
6.0.0-beta.95 | 121 | 8/16/2024 |
6.0.0-beta.94 | 65 | 8/12/2024 |
6.0.0-beta.93 | 68 | 8/8/2024 |
6.0.0-beta.92 | 79 | 7/4/2024 |
6.0.0-beta.91 | 56 | 6/14/2024 |
5.2.4 | 11,090 | 7/29/2024 |
5.2.3 | 120 | 7/29/2024 |
5.2.2 | 126 | 7/29/2024 |
5.2.2-beta.87 | 61 | 6/14/2024 |
5.2.1 | 1,800 | 6/12/2024 |
5.2.1-beta.86 | 52 | 5/28/2024 |
5.2.1-beta.85 | 52 | 5/28/2024 |
5.2.1-beta.84 | 934 | 5/21/2024 |
5.2.0 | 6,818 | 3/30/2024 |
5.2.0-beta.83 | 69 | 3/30/2024 |
5.2.0-beta.82 | 65 | 3/30/2024 |
5.2.0-beta.81 | 72 | 3/30/2024 |
5.2.0-beta.80 | 67 | 3/26/2024 |
5.2.0-beta.79 | 69 | 3/26/2024 |
5.2.0-beta.78 | 72 | 3/26/2024 |
5.2.0-beta.77 | 69 | 3/26/2024 |
5.2.0-beta.76 | 72 | 3/25/2024 |
5.2.0-beta.75 | 59 | 3/14/2024 |
5.2.0-beta.74 | 63 | 2/27/2024 |
5.2.0-beta.73 | 871 | 2/26/2024 |
5.2.0-beta.72 | 72 | 2/26/2024 |
5.2.0-beta.71 | 57 | 2/26/2024 |
5.1.1 | 1,582 | 2/16/2024 |
5.1.1-beta.69 | 59 | 2/16/2024 |
5.1.0 | 325 | 2/15/2024 |
5.1.0-beta | 225 | 2/13/2024 |
5.0.0 | 3,045 | 12/14/2023 |
4.2.0-beta | 1,191 | 11/1/2023 |
4.1.0 | 25,161 | 9/27/2023 |
4.1.0-beta | 1,201 | 9/25/2023 |
4.0.2 | 19,189 | 8/1/2023 |
4.0.2-beta | 631 | 7/30/2023 |
4.0.1 | 1,368 | 7/11/2023 |
4.0.1-beta | 786 | 6/29/2023 |
4.0.0 | 2,982 | 6/12/2023 |
4.0.0-beta | 1,042 | 6/5/2023 |
3.0.2 | 1,573 | 3/30/2023 |
3.0.1 | 3,111 | 3/13/2023 |
2.0.2 | 922 | 2/22/2023 |
2.0.1 | 2,240 | 2/8/2023 |
2.0.0 | 1,014 | 2/8/2023 |