← 返回首页
GitHub - ByteBardOrg/AsyncAPI.NET: The official continuation of LEGO.AsyncAPI.NET from the original author and maintainer. The SDK contains a useful object model for AsyncAPI 3.0 documents in .NET · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

ByteBardOrg/AsyncAPI.NET

Go to file
Code

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.

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. Full support for both 2.6 and 3.0. 2.6 are 'upgraded' to 3.0 during deserialization and can be written back as 2.6 (see writing examples).

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


ByteBard.AsyncAPI.Readers


ByteBard.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() 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

About

The official continuation of LEGO.AsyncAPI.NET from the original author and maintainer. The SDK contains a useful object model for AsyncAPI 3.0 documents in .NET

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

Contributors

Languages

Footer

© 2026 GitHub, Inc.