• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Saunter is a code-first AsyncAPI documentation generator for dotnet.

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();
        endpoints.MapAsyncApiUi();
    });
  5. Use the published AsyncApi document:

    // HTTP GET /asyncapi/asyncapi.json
    {
        // Properties from Startup.cs
        "asyncapi": "2.1.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.",
            //...
    }
  6. Use the published AsyncAPI UI:

    AsyncAPI UI

Configuration

See the options source code for detailed info.

Common options are below:

services.AddAsyncApiSchemaGeneration(options =>
{
    options.AssemblyMarkerTypes = new[] { typeof(Startup) };   // Tell Saunter where to scan for your classes.
    
    options.AddChannelItemFilter<MyChannelItemFilter>();       // Dynamically update ChanelItems
    options.AddOperationFilter<MyOperationFilter>();           // Dynamically update Operations
    
    options.Middleware.Route = "/asyncapi/asyncapi.json";      // AsyncAPI JSON document URL
    options.Middleware.UiBaseRoute = "/asyncapi/ui/";          // AsyncAPI UI URL
    options.Middleware.UiTitle = "My AsyncAPI Documentation";  // AsyncAPI UI page title
}

JSON Schema Settings

The JSON schema generation can be customized using the options.JsonSchemaGeneratorSettings. Saunter defaults to the popular camelCase naming strategy for both properties and types.

For example, setting to use PascalCase:

services.AddAsyncApiSchemaGeneration(options =>
{
    options.JsonSchemaGeneratorSettings.TypeNameGenerator = new DefaultTypeNameGenerator();

    // Note: need to assign a new JsonSerializerSettings, not just set the properties within it.
    options.JsonSchemaGeneratorSettings.SerializerSettings = new JsonSerializerSettings 
    {
        ContractResolver = new DefaultContractResolver(),
        Formatting = Formatting.Indented;
    };
}

You have access to the full range of both NJsonSchema and JSON.NET settings to configure the JSON schema generation, including custom ContractResolvers.

Bindings

Bindings are used to describe protocol specific information. These can be added to the AsyncAPI document and then applied to different components by setting the BindingsRef property in the relevant attributes [OperationAttribute], [MessageAttribute], [ChannelAttribute]

// Startup.cs
services.AddAsyncApiSchemaGeneration(options =>
{
    options.AsyncApi = new AsyncApiDocument
    {
        Components = 
        {
            ChannelBindings = 
            {
                ["my-amqp-binding"] = new ChannelBindings
                {
                    Amqp = new AmqpChannelBinding
                    {
                        Is = AmqpChannelBindingIs.RoutingKey,
                        Exchange = new AmqpChannelBindingExchange
                        {
                            Name = "example-exchange",
                            VirtualHost = "/development"
                        }
                    }
                }
            }
        }
    }
});
[Channel("light.measured", BindingsRef = "my-amqp-binding")] // Set the BindingsRef property
public void PublishLightMeasuredEvent(Streetlight streetlight, int lumens) {}

Available bindings:

Multiple AsyncAPI documents

You can generate multiple AsyncAPI documents by using the ConfigureNamedAsyncApi extension method.

// Startup.cs

// Add Saunter to the application services. 
services.AddAsyncApiSchemaGeneration(options =>
{
    // Specify example type(s) from assemblies to scan.
    options.AssemblyMarkerTypes = new[] {typeof(FooMessageBus)};
}

// Configure one or more named AsyncAPI documents
services.ConfigureNamedAsyncApi("Foo", asyncApi => 
{
    asyncApi.Info = new Info("Foo API", "1.0.0");
    // ...
});

services.ConfigureNamedAsyncApi("Bar", asyncApi => 
{
    asyncApi.Info = new Info("Bar API", "1.0.0");
    // ...
});

Classes need to be decorated with the AsyncApiAttribute specifying the name of the AsyncAPI document.

[AsyncApi("Foo")]
public class FooMessageBus 
{
    // Any channels defined in this class will be added to the "Foo" document
}


[AsyncApi("Bar")]
public class BarMessageBus 
{
    // Any channels defined in this class will be added to the "Bar" document
}

Each document can be accessed by specifying the name in the URL

// GET /asyncapi/foo/asyncapi.json
{
    "info": {
        "title": "Foo API"
    }
}

// GET /asyncapi/bar/asyncapi.json
{
    "info": {
        "title": "Bar API"
    }
}

Contributing

See our contributing guide.

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

You can also find me on the AsyncAPI community slack.

Thanks

More Repositories

1

spec

The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
JavaScript
4,215
star
2

generator

Use your AsyncAPI definition to generate literally anything. Markdown documentation, Node.js code, HTML documentation, anything!
JavaScript
758
star
3

website

AsyncAPI specification website
TypeScript
453
star
4

modelina

A library for generating typed models based on inputs such as AsyncAPI, OpenAPI, and JSON Schema documents with high customization
TypeScript
312
star
5

cli

CLI to work with your AsyncAPI files. You can validate them and in the future use a generator and even bootstrap a new file. Contributions are welcomed!
TypeScript
184
star
6

asyncapi-react

React component for rendering documentation from your specification in real-time in the browser. It also provides a WebComponent and bundle for Angular and Vue
TypeScript
174
star
7

studio

Visually design your AsyncAPI files and event-driven architecture.
TypeScript
167
star
8

parser-js

AsyncAPI parser for Javascript (browser-compatible too).
TypeScript
116
star
9

community

AsyncAPI community-related stuff.
98
star
10

glee

Glee — The AsyncAPI framework that will make you smile again :)
TypeScript
88
star
11

bindings

AsyncAPI bindings specifications
71
star
12

jasyncapi

/jay-sync-api/ is a Java code-first tool for AsyncAPI specification
Kotlin
67
star
13

java-spring-template

Java Spring template for the AsyncAPI Generator
Java
66
star
14

html-template

HTML template for AsyncAPI Generator. Use it to generate a static docs. It is using AsyncAPI React component under the hood.
JavaScript
63
star
15

parser-go

It parses AsyncAPI documents.
Go
55
star
16

spec-json-schemas

AsyncAPI schema versions
JavaScript
54
star
17

github-action-for-cli

GitHub Action with generator, validator, converter and others - all in one for your AsyncAPI documents with AsyncAPI CLI as backbone
Shell
46
star
18

go-watermill-template

Go template for the AsyncAPI Generator using Watermill module
JavaScript
46
star
19

nodejs-template

This template generates a server using your AsyncAPI document. It supports multiple different protocols, like Kafka or MQTT. It is designed in the way that generated code is a library and with it's API you can start the server, send messages or register a middleware for listening incoming messages. Runtime message validation included.
JavaScript
40
star
20

java-spring-cloud-stream-template

Java Spring Cloud Stream template for the AsyncAPI Generator
JavaScript
31
star
21

avro-schema-parser

An AsyncAPI schema parser for Avro 1.x schemas.
TypeScript
31
star
22

bundler

Combine multiple AsyncAPI specification files into one.
TypeScript
30
star
23

.github

Location of all reusable community health files
29
star
24

vs-asyncapi-preview

VSCode AsyncAPI Preview Extension
TypeScript
28
star
25

server-api

Server API providing official AsyncAPI tools
TypeScript
26
star
26

markdown-template

Markdown template for the AsyncAPI Generator
JavaScript
26
star
27

diff

Diff is a library that compares two AsyncAPI Documents and provides information about the differences by pointing out explicitly information like breaking changes.
TypeScript
26
star
28

python-paho-template

Python Paho template for the AsyncAPI generator
JavaScript
25
star
29

nodejs-ws-template

Node.js WebSockets template for the AsyncAPI Generator. It showcases how from a single AsyncAPI document you can generate a server and a client at the same time.
JavaScript
23
star
30

conference-website

Website for the AsyncAPI online conference
JavaScript
23
star
31

ts-nats-template

Node.js/Typescript template for NATS
JavaScript
21
star
32

converter-go

Convert AsyncAPI documents from older to newer versions with Golang
Go
20
star
33

generator-react-sdk

Generator React SDK enabling the AsyncAPI generator to support React as the rendering engine for templates.
TypeScript
19
star
34

dotnet-nats-template

.NET template for NATS
JavaScript
18
star
35

converter-js

Convert to or migrate between AsyncAPI versions with the converter
TypeScript
18
star
36

template-for-generator-templates

This is a GitHub repository template for generator templates to make it much easier to start writing your own generator template.
JavaScript
18
star
37

simulator

Asynchronous traffic simulation application using async-api
TypeScript
16
star
38

EDAVisualiser

View your system, events, applications through different perspectives
TypeScript
15
star
39

optimizer

AsyncAPI offers many different ways to reuse certain parts of the document like messages or schemas definitions or references to external files, not to even mention the traits. There is a need for a tool that can be plugged into any workflows and optimize documents that are generated from code, but not only.
TypeScript
14
star
40

tck

(WIP) Test Compatibility Suite for AsyncAPI
Java
13
star
41

chatbot

The project's aim is to develop a chatbot that can help people create spec documents without knowing the specification.To get started with, the bot will consume the spec, JSON schema and serves the user as an expert. So based on a set of questions and answers it will generate an AsyncApi spec document according to the use cases.
JavaScript
12
star
42

openapi-schema-parser

An AsyncAPI schema parser for OpenAPI 3.0.x and Swagger 2.x schemas.
TypeScript
12
star
43

extensions-catalog

Catalog of extensions for AsyncAPI specification
11
star
44

shape-up-process

This repo contains pitches and the current cycle bets. More info about the Shape Up process: https://basecamp.com/shapeup
JavaScript
11
star
45

java-template

Java template for the AsyncAPI Generator
JavaScript
10
star
46

jasyncapi-idea-plugin

/jay-sync-api/-idea-plugin is a IDEA plugin for AsyncAPI specification
Kotlin
10
star
47

dotnet-rabbitmq-template

This template is for generating a .NET C# wrapper for the RabbitMQ client based on your AsyncAPI document.
JavaScript
10
star
48

brand

AsyncAPI brand guidelines and strategy
8
star
49

parser-api

Global API definition for all AsyncAPI Parser implementations.
8
star
50

problem

Library that implements the Problem interface. Reference https://www.rfc-editor.org/rfc/rfc7807
TypeScript
7
star
51

php-template

PHP Template for AsyncAPI generator
PHP
7
star
52

training

All about trainings, workshops, courses, etc.
6
star
53

raml-dt-schema-parser

AsyncAPI schema parser for RAML data types
TypeScript
5
star
54

enterprise-patterns

Enterprise patterns using AsyncAPI
4
star
55

protobuf-schema-parser

Schema parser for Protobuf compatible with AsyncAPI JS Parser
TypeScript
4
star
56

template-for-go-projects

This is a repository template for golang projects
Makefile
2
star
57

generator-filters

Library with reusable generator filters that you can use in your templates
JavaScript
2
star
58

generator-hooks

Library with reusable generator hooks that you can use in your templates
JavaScript
1
star