Saunter 0.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Saunter --version 0.3.0
NuGet\Install-Package Saunter -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Saunter" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Saunter --version 0.3.0
#r "nuget: Saunter, 0.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Saunter as a Cake Addin
#addin nuget:?package=Saunter&version=0.3.0

// Install Saunter as a Cake Tool
#tool nuget:?package=Saunter&version=0.3.0

Saunter

CI NuGet Badge

Saunter is an AsyncAPI documentation generator for dotnet.

ℹ Note that pre version 1.0.0, the API is regarded as unstable and breaking changes may be introduced.

Getting Started

See examples/StreetlightsAPI.

  1. Install the Saunter package

    dotnet add package Saunter
    
  2. In the ConfigureServices method of Startup.cs, configure Saunter.

    // Add Saunter to the application services. 
    services.AddAsyncApiSchemaGeneration(options =>
    {
        // Specify example type(s) from assemblies to scan.
        options.AssemblyMarkerTypes = new[] {typeof(StreetlightMessageBus)};
    
        // Build as much (or as little) of the AsyncApi document as you like.
        // Saunter will generate Channels, Operations, Messages, etc, but you
        // may want to specify Info here.
        options.AsyncApi = new AsyncApiDocument
        {
            Info = new Info("Streetlights API", "1.0.0")
            {
                Description = "The Smartylighting Streetlights API allows you\nto remotely manage the city lights.",
                License = new License("Apache 2.0")
                {
                    Url = "https://www.apache.org/licenses/LICENSE-2.0"
                }
            },
            Servers =
            {
                { "mosquitto", new Server("test.mosquitto.org", "mqtt") }
            }
        };
    });
    
  3. Add attributes to your classes which publish or subscribe to messages.

    [AsyncApi] // Tells Saunter to scan this class.
    public class StreetlightMessageBus : IStreetlightMessageBus
    {
        [Channel("publish/light/measured")] // Creates a Channel
        [PublishOperation(typeof(LightMeasuredEvent), Summary = "Inform about environmental lighting conditions for a particular streetlight.")] // A simple Publish operation.
        public void PublishLightMeasuredEvent(Streetlight streetlight, int lumens) {}
    
  4. Add saunter middleware to host the AsyncApi json document. In the Configure method of Startup.cs:

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapAsyncApiDocuments();
    });
    
  5. Use the published AsyncApi document:

    // HTTP GET /asyncapi/asyncapi.json
    {
        // Properties from Startup.cs
        "asyncapi": "2.0.0",
        "info": {
            "title": "Streetlights API",
            "version": "1.0.0",
            "description": "The Smartylighting Streetlights API allows you\nto remotely manage the city lights.",
           // ...
        },
        // Properties generated from Attributes
        "channels": {
            "light/measured": {
            "publish": {
                "operationId": "PublishLightMeasuredEvent",
                "summary": "Inform about environmental lighting conditions for a particular streetlight.",
            //...
    }
    

Bindings

Bindings are used to describe protocol specific information. These can be added by creating a Filter which will be applied to each operation during the AsyncAPI document generation.

To use a filter, create a class which implements IOperationFilter and register it in Startup.cs

In the filter you can set custom binding information.

public class MyCustomOperationFilter : IOperationFilter
{
    public void Apply(Operation operation, OperationFilterContext context)
    {
        // Here you have access to the generated Operation which you can modify.
        // You are also provided with the Context which contains things like the MethodInfo and Attribute
        // used to generate the Operation.
        
        operation.Bindings = new OperationBindings
        {
            Http = // set http binding info
            Kafka = // set kafka binding info
            // etc
        }
    }
}
services.AddAsyncApiSchemaGeneration(options =>
{
    options.OperationFilters.Add(new MyCustomOperationFilter());
});

Once these steps are complete, when you generate your documentation any class with a [PublishOperation] or [SubscribeOperation] attributes will have the binding information added to the documentation.

Http Bindings

Example HTTP binding operation filter

public class HttpOperationFilter : IOperationFilter
{
    public void Apply(Operation operation, OperationFilterContext context)
    {
        operation.Bindings = new OperationBindings
        {
            Http = new HttpOperationBinding
            {
                Type = "request",
                Method = "GET",
                Query = new HttpOperationBindingQuery
                {
                    Type = "object",
                    Required = new string[] { "companyId" },
                    Properties = new
                    {
                        CompanyId = new
                        {
                            Type = "number",
                            Minimum = 1,
                            Desciption = "The Id of the company."
                        }
                    },
                    AdditionalProperties = false
                },
                BindingVersion = "0.1.0"
            }
        };
    }
}

Kafka Bindings

Example Kafka binding operation filter

public class KafkaOperationFilter : IOperationFilter
{
    public void Apply(Operation operation, OperationFilterContext context)
    {
        operation.Bindings = new OperationBindings
        {
            Kafka = new KafkaOperationBinding
            {          
                GroupId = new KafkaOperationBindingGroupId
                {
                    Type = "string",
                    Enum = new string[] { "myGroupId" }     
                },
                ClientId = new KafkaOperationBindingClientId
                {
                    Type = "string",
                    Enum = new string[] { "myClientId" }
                },
                BindingVersion = "0.1.0"
            }
        };
    }
}

Contributing

See our contributing guide.

Feel free to get involved in the project by opening issues, or submitting pull requests.

Thanks

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Saunter:

Package Downloads
EasyDesk.CleanArchitecture.Web

Utilities for the ASP.NET Core web layer of the clean architecture as seen by EasyDesk.

Ev.ServiceBus.AsyncApi

This package helps you generate an Async API Schema. Resources registered in Ev.ServiceBus will be automatically added to the schema.

SlimMessageBus.Host.AsyncApi The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Extension for SlimMessageBus that adds AsyncAPI specification generator for the Saunter library

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Saunter:

Repository Stars
zarusz/SlimMessageBus
Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
Version Downloads Last updated
0.13.0 67,409 1/16/2024
0.12.0 317,010 6/15/2023
0.11.0 233,749 10/3/2022
0.10.0 9,220 8/22/2022
0.9.1 209,272 11/8/2021
0.9.0 23,411 10/17/2021
0.8.0 10,495 9/10/2021
0.7.1 34,815 8/4/2021
0.7.0 356 8/4/2021
0.6.0 1,645 8/3/2021
0.5.0 801 7/28/2021
0.4.0 7,947 7/27/2021
0.3.1 1,072 7/19/2021
0.3.0 4,655 7/19/2021
0.2.0 90,323 8/4/2020
0.1.0 594 7/2/2020
0.1.0-alpha-46 197 7/1/2020
0.1.0-alpha-44 828 5/4/2020
0.1.0-alpha-42 203 5/4/2020
0.1.0-alpha-41 219 4/9/2020
0.1.0-alpha-39 213 4/9/2020
0.1.0-alpha-37 220 3/20/2020
0.1.0-alpha-34 220 10/21/2019
0.1.0-alpha-32 202 10/21/2019
0.1.0-alpha-29 257 10/21/2019
0.1.0-alpha-25 212 10/7/2019