Created
April 7, 2023 15:38
-
-
Save VisualBean/13ac0f0f94250f8ec7ef1042078039a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LEGO.AsyncAPI; | |
using LEGO.AsyncAPI.Models; | |
// Build the document | |
var document = new AsyncApiDocument() | |
{ | |
Info = new AsyncApiInfo | |
{ | |
Title = "Example", | |
Version = "0.1.0" | |
} | |
}; | |
// Add the channel | |
document.Channels["user/signedup"] = new AsyncApiChannel() | |
{ | |
Subscribe = new AsyncApiOperation() | |
{ | |
Message = new List<AsyncApiMessage>() | |
{ | |
new AsyncApiMessage() | |
{ | |
Description = "An event describing that a user just signed up.", | |
// The payload consists of one or more layers of JsonSchema why it can look a bit daunting | |
Payload = new AsyncApiSchema() | |
{ | |
Type = new List<SchemaType>() | |
{ | |
SchemaType.Object, | |
}, | |
Properties = new Dictionary<string, AsyncApiSchema>() | |
{ | |
{ | |
"fullName", new AsyncApiSchema() | |
{ | |
Type = new List<SchemaType>() | |
{ | |
SchemaType.String, | |
} | |
} | |
}, | |
{ | |
"email", new AsyncApiSchema() | |
{ | |
Type = new List<SchemaType>() | |
{ | |
SchemaType.String | |
}, | |
Format = "email", | |
} | |
}, | |
{ | |
"age", new AsyncApiSchema() | |
{ | |
Type = new List<SchemaType>() | |
{ | |
SchemaType.Integer, | |
}, | |
Minimum = 18, | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
// Serialize the document to yaml | |
var serialized = document.Serialize(AsyncApiVersion.AsyncApi2_0, AsyncApiFormat.Yaml); | |
Console.WriteLine(serialized); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment