Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Home
Alex Wichmann edited this page May 25, 2025
·
3 revisions
The AsyncAPI.NET library is a document object model (DOM) for an AsyncAPI description document. It provides a set of classes for constructing semantically valid AsyncAPI specifications. The library also includes a writer for serializing the DOM into JSON or YAML AsyncAPI specifications
Getting started
varmyFirstAsyncApi=newAsyncApiDocument{Info=newAsyncApiInfo{Title="my first asyncapi",Version="1.0.0",},Channels=newDictionary<string,AsyncApiChannel>{{"UserSignup",newAsyncApiChannel{Address="user/signedUp",Messages=newDictionary<string,AsyncApiMessage>(){{"UserMessage",newAsyncApiMessage{Payload=newAsyncApiJsonSchema(){Type=SchemaType.Object,Properties=newDictionary<string,AsyncApiJsonSchema>(){{"displayName",newAsyncApiJsonSchema(){Type=SchemaType.String,Description="Name of the user",}},},},}},},}},},Operations=newDictionary<string,AsyncApiOperation>(){{"ConsumerUserSignups",newAsyncApiOperation{Action=AsyncApiAction.Receive,Channel=newAsyncApiChannelReference("#/channels/UserSignup"),}},},};varyamlV2=myFirstAsyncApi.SerializeAsYaml(AsyncApiVersion.AsyncApi2_0);// asyncapi: 2.6.0// info:// title: my first asyncapi// version: 1.0.0// channels:// user/signedUp:// publish:// message:// payload:// type: object// properties:// displayName:// type: string// description: Name of the uservaryamlV3=myFirstAsyncApi.SerializeAsYaml(AsyncApiVersion.AsyncApi3_0);// asyncapi: 3.0.0// info:// title: my first asyncapi// version: 1.0.0// channels:// UserSignup:// address: user/signedUp// messages:// UserMessage:// payload:// type: object// properties:// displayName:// type: string// description: Name of the user// operations:// ConsumerUserSignups:// action: receive// channel:// $ref: '#/channels/UserSignup'// components: { }Reading
varhttpClient=newHttpClient{BaseAddress=newUri("https://raw.githubusercontent.com/asyncapi/spec/"),};varstream=awaithttpClient.GetStreamAsync("master/examples/streetlights-kafka.yml");varasyncApiDocument=newAsyncApiStreamReader().Read(stream,outvardiagnostic);You can read more about more advanced ways to of reading or writing in the Wiki