Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 18
Message Payloads
Alex Wichmann edited this page Sep 2, 2024
·
4 revisions
AsyncAPI.Net supports 2 types of message payloads
The payload types are AsyncApiSchemaPayload and AsyncApiAvroSchemaPayload respectively
newAsyncApiSchema(){Title="title1",AllOf=newList<AsyncApiSchema>{newAsyncApiSchema{Title="title2",Properties=newDictionary<string,AsyncApiSchema>{["property1"]=newAsyncApiSchema{Type=SchemaType.Integer,},["property2"]=newAsyncApiSchema{Type=SchemaType.String,MaxLength=15,},},},newAsyncApiSchema{Title="title3",Properties=newDictionary<string,AsyncApiSchema>{["property3"]=newAsyncApiSchema{Properties=newDictionary<string,AsyncApiSchema>{["property4"]=newAsyncApiSchema{Type=SchemaType.Boolean,},},},["property5"]=newAsyncApiSchema{Type=SchemaType.String,MinLength=2,},},Nullable=true,},},Nullable=true,ExternalDocs=newAsyncApiExternalDocumentation{Url=newUri("http://example.com/externalDocs"),},};Due to the nature of the avro, the payload type has a helper method bool TryGetAs<T>(out T schema) to make the casting logic slightly easier on you.
The Avro types are implemented through a common base class AvroSchema
As avro supports adding custom properties to the schemas as "metadata", these when deserialized, will be added to the Metadata Dictionary which exists on all implemented Avro types
Supported types:
- Record
- Fixed
- Enum
- Union
- Map
- Array
- Primitive
- Field
Note, all above types are prefixed "Avro" within the dotnet classes.
newAvroRecord{Name="User",Namespace="com.example",Fields=newList<AvroField>{newAvroField{Name="username",Type=AvroPrimitiveType.String,Doc="The username of the user.",Default=newAsyncApiAny("guest"),Order=AvroFieldOrder.Ascending,},newAvroField{Name="status",Type=newAvroEnum{Name="Status",Symbols=newList<string>{"ACTIVE","INACTIVE","BANNED"},},Doc="The status of the user.",},newAvroField{Name="emails",Type=newAvroArray{Items=AvroPrimitiveType.String,},Doc="A list of email addresses.",},newAvroField{Name="metadata",Type=newAvroMap{Values=AvroPrimitiveType.String,},Doc="Metadata associated with the user.",},newAvroField{Name="address",Type=newAvroRecord{Name="Address",Fields=newList<AvroField>{newAvroField{Name="street",Type=AvroPrimitiveType.String},newAvroField{Name="city",Type=AvroPrimitiveType.String},newAvroField{Name="zipcode",Type=AvroPrimitiveType.String},},},Doc="The address of the user.",},newAvroField{Name="profilePicture",Type=newAvroFixed{Name="ProfilePicture",Size=256,},Doc="A fixed-size profile picture.",},newAvroField{Name="contact",Type=newAvroUnion{Types=newList<AvroSchema>{AvroPrimitiveType.Null,newAvroRecord{Name="PhoneNumber",Fields=newList<AvroField>{newAvroField{Name="countryCode",Type=AvroPrimitiveType.Int},newAvroField{Name="number",Type=AvroPrimitiveType.String},},},},},Doc="The contact information of the user, which can be either null or a phone number.",},},};