ByteBard.AsyncAPI.NET 2.0.1

Prefix Reserved
dotnet add package ByteBard.AsyncAPI.NET --version 2.0.1
                    
NuGet\Install-Package ByteBard.AsyncAPI.NET -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ByteBard.AsyncAPI.NET" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ByteBard.AsyncAPI.NET" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ByteBard.AsyncAPI.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ByteBard.AsyncAPI.NET --version 2.0.1
                    
#r "nuget: ByteBard.AsyncAPI.NET, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=ByteBard.AsyncAPI.NET&version=2.0.1
                    
Install ByteBard.AsyncAPI.NET as a Cake Addin
#tool nuget:?package=ByteBard.AsyncAPI.NET&version=2.0.1
                    
Install ByteBard.AsyncAPI.NET as a Cake Tool

AsyncAPI.NET

This serves as the official future of AsyncAPI.NET. To be able to give the level of support I want, I have had to fork my original work from the The LEGO Group, and create my own. This is unfortunate, but after much back and not a lot of forth, I have decided that it was time.

Build & Test

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. V3 is currently in pre-release - so grab that if you need V3 CHANGELOG
Wiki and getting started guide

Installation

Generally you want to use Readers and Bindings. They have however been split to allow for different scenarios without polluting with unnecesary packages.

Install the NuGet packages:

ByteBard.AsyncAPI.NET

Nuget
Nuget

ByteBard.AsyncAPI.Readers

Nuget
Nuget

ByteBard.AsyncAPI.Bindings

Nuget
Nuget

Example Usage

Main classes to know:

  • AsyncApiStringReader
  • AsyncApiStringWriter
    • There is an extension on the AsyncApiDocument type which allows Serializing as well (new AsyncApiDocument().SerializeAsJson() or new AsyncApiDocument().SerializeAsYaml()

Writing

var specification =
"""
asyncapi: 3.0.0
info:
  title: UsersAPI
  version: 1.0.0
  externalDocs:
    description: Find more info here
    url: https://www.asyncapi.com
  tags:
    - name: e-commerce
servers:
  production:
    host: "rabbitmq.in.mycompany.com:5672"
    pathname: "/production"
    protocol: "amqp"
channels:
  UserSignup:
    address: "user/signedup"
    messages: 
      UserMessage: 
        payload:
          type: object
          properties:
            displayName:
              type: string
              description: Name of the user
operations:
  ConsumeUserSignups:
    action: receive
    channel: 
      $ref: "#/channels/UserSignup"
""";
var reader = new AsyncApiStringReader();
var document = reader.Read(specification, out var diagnostics);
var v2Document = document.SerializeAsYaml(AsyncApiVersion.AsyncApi2_0);
var v3Document = document.SerializeAsJson(AsyncApiVersion.AsyncApi3_0);

Reading

There are 3 reader types

  1. AsyncApiStringReader
  2. AsyncApiTextReader
  3. AsyncApiStreamReader

All 3 supports both json and yaml.

StreamReader
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);
StringReader
var yaml =
	"""
	asyncapi: 2.6.0
	  info:
	    title: my first asyncapi
	channels:
	  users:
	    subscribe:
	      operationId: users
	      description: my users channel
	      message:
	        $ref: '#/components/messages/MyMessage'
	components:
	  messages:
	    MyMessage:
	      name: Hello!
	""";

var asyncApiDocument = new AsyncApiStringReader().Read(yaml, out var diagnostic);

All readers will write warnings and errors to the diagnostics.

Reference Resolution

Internal references are resolved by default. This includes component and non-component references e.g #/components/messages/MyMessage and #/servers/0. External references can be resolved by setting ReferenceResolution to ResolveAllReferences. The default implementation will resolve anything prefixed with file://, http:// & https://, however a custom implementation can be made, by inhereting from the IStreamLoader interface and setting the ExternalReferenceLoader in the AsyncApiReaderSettings. External references are always force converted to Json during resolution. This means that both yaml and json is supported - but not other serialization languages.

var settings = new AsyncApiReaderSettings { ReferenceResolution = ReferenceResolution.ResolveAllReferences };
var document = new AsyncApiStringReader(settings).Read(json, out var diagnostics);

Reference resolution can be disabled by setting ReferenceResolution to DoNotResolveReferences.

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(yaml, out var diagnostic);

Attribution

Contribution

This project welcomes contributions and suggestions. Do you want to contribute to the project? Find out how here.

License

Apache 2.0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 is compatible. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ByteBard.AsyncAPI.NET:

Package Downloads
ByteBard.AsyncAPI.NET.Readers

AsyncAPI.NET Readers for JSON and YAML documents

ByteBard.AsyncAPI.NET.Bindings

AsyncAPI.NET Bindings

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 125 5/31/2025
2.0.0 173 5/25/2025
2.0.0-beta.6 125 3/28/2025
1.0.1 2,221 4/24/2025
1.0.0 178 3/28/2025