Skip to content

The AsyncAPI.NET SDK contains a useful object model for AsyncAPI documents in .NET

License

Notifications You must be signed in to change notification settings

LEGO/AsyncAPI.NET

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2ef2b73 · Oct 26, 2023
Sep 8, 2023
Nov 24, 2022
Jun 29, 2022
Oct 26, 2023
Oct 26, 2023
Mar 31, 2023
Nov 25, 2022
Feb 8, 2022
Jun 7, 2023
Sep 27, 2023
Feb 7, 2023
Feb 13, 2023
Feb 13, 2023
Nov 24, 2022
Jun 7, 2023
Nov 23, 2022

Repository files navigation

AsyncAPI.NET

GitHub Workflow Status

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

Nuget
Nuget

AsyncAPI.Readers

Nuget
Nuget

AsyncAPI.Bindings

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 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);

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.Add(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

Modified Apache 2.0 (Section 6)

About

The AsyncAPI.NET SDK contains a useful object model for AsyncAPI documents in .NET

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages