All Projects → tehmantra → Saunter

tehmantra / Saunter

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

Projects that are alternatives of or similar to Saunter

Slack Api Specs
Open API specifications for platform products by Slack
Stars: ✭ 148 (+279.49%)
Mutual labels:  openapi, documentation
ApiFramework
Everything is an (Open)API
Stars: ✭ 26 (-33.33%)
Mutual labels:  aspnetcore, openapi
Openapi Codegen
OpenAPI 3.0 CodeGen plus Node.js minus the Java and emojis
Stars: ✭ 224 (+474.36%)
Mutual labels:  openapi, documentation
Shins
Shins development continues at
Stars: ✭ 250 (+541.03%)
Mutual labels:  openapi, documentation
Optic
Optic documents and tests your API as you build it
Stars: ✭ 760 (+1848.72%)
Mutual labels:  openapi, documentation
L5 Swagger
OpenApi or Swagger integration to Laravel
Stars: ✭ 1,781 (+4466.67%)
Mutual labels:  openapi, documentation
MinimalApi
ASP.NET Core 7.0 - Minimal API Example - Todo API implementation using ASP.NET Core Minimal API, Entity Framework Core, Token authentication, Versioning, Unit Testing, Integration Testing and Open API.
Stars: ✭ 156 (+300%)
Mutual labels:  aspnetcore, openapi
Swagger Combine
Combines multiple Swagger schemas into one dereferenced schema.
Stars: ✭ 102 (+161.54%)
Mutual labels:  openapi, documentation
Oas Kit
Convert Swagger 2.0 definitions to OpenAPI 3.0 and resolve/validate/lint
Stars: ✭ 516 (+1223.08%)
Mutual labels:  openapi, documentation
Awesome Openapi3
😎 A list of awesome projects related to OpenAPI 3.0.x, curated by the community
Stars: ✭ 469 (+1102.56%)
Mutual labels:  openapi, documentation
Nswag
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
Stars: ✭ 4,825 (+12271.79%)
Mutual labels:  openapi, aspnetcore
Apispec
A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..
Stars: ✭ 831 (+2030.77%)
Mutual labels:  openapi, documentation
Kin Openapi
OpenAPI 3.0 implementation for Go (parsing, converting, validation, and more)
Stars: ✭ 776 (+1889.74%)
Mutual labels:  openapi, documentation
Widdershins
OpenAPI / Swagger, AsyncAPI & Semoasa definitions to (re)Slate compatible markdown
Stars: ✭ 856 (+2094.87%)
Mutual labels:  openapi, documentation
Paw Swaggerimporter
Swagger/OpenAPI 2.0 Importer for Paw
Stars: ✭ 34 (-12.82%)
Mutual labels:  openapi
Immuni Documentation
Repo for Immuni's documentation.
Stars: ✭ 985 (+2425.64%)
Mutual labels:  documentation
Server
The core infrastructure backend (API, database, Docker, etc).
Stars: ✭ 8,797 (+22456.41%)
Mutual labels:  aspnetcore
Rolodex
📇API Documentation Generator for Phoenix
Stars: ✭ 34 (-12.82%)
Mutual labels:  openapi
Docs.go.cd
GoCD user documentation
Stars: ✭ 37 (-5.13%)
Mutual labels:  documentation
Sphinx Automodapi
Sphinx extension for generating API documentation
Stars: ✭ 36 (-7.69%)
Mutual labels:  documentation

Saunter

CI NuGet Badge

Saunter is an AsyncAPI documentation generator for dotnet.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].