asyncapi

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package asyncapi renders schema.Schema values as an AsyncAPI 2.6 document.

It imports only the schema package — no codec logic is involved. The same schema.Schema that drives OpenAPI output can describe AsyncAPI message payloads.

Typical usage:

doc, err := asyncapi.NewDocumentBuilder(asyncapi.Info{
    Title:   "User Events",
    Version: "1.0.0",
}).
    AddChannel("user/created", asyncapi.ChannelItem{
        Subscribe: &asyncapi.Operation{
            Summary: "User created event",
            Message: asyncapi.Message{
                Schema:     UserCodec.Schema,
                SchemaName: "User",
            },
        },
    }).
    Build()

yamlBytes, err := doc.MarshalYAML()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelItem

type ChannelItem struct {
	Description string
	// Parameters describes the {varName} placeholders in the topic template.
	// Keyed by variable name (without braces). Auto-populated by the events
	// builder from TopicParamCodecs schemas and TopicParams descriptions.
	Parameters map[string]Parameter
	// Subscribe is the operation where the application receives messages.
	Subscribe *Operation
	// Publish is the operation where the application sends messages.
	Publish *Operation
}

ChannelItem describes one channel with optional subscribe and publish operations.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is a full AsyncAPI 2.6 document produced by DocumentBuilder. Use MarshalJSON or MarshalYAML to serialise it.

func (Document) MarshalJSON

func (d Document) MarshalJSON() ([]byte, error)

MarshalJSON encodes the document as JSON bytes.

func (Document) MarshalYAML

func (d Document) MarshalYAML() ([]byte, error)

MarshalYAML encodes the document as YAML bytes.

type DocumentBuilder

type DocumentBuilder struct {
	// contains filtered or unexported fields
}

DocumentBuilder accumulates channels and named schemas, then produces a Document.

func NewDocumentBuilder

func NewDocumentBuilder(info Info) *DocumentBuilder

NewDocumentBuilder returns a builder initialised with the given Info.

func (*DocumentBuilder) AddChannel

func (b *DocumentBuilder) AddChannel(name string, c ChannelItem) *DocumentBuilder

AddChannel registers a named channel in the document.

func (*DocumentBuilder) AddSchema

func (b *DocumentBuilder) AddSchema(name string, s schema.Schema) *DocumentBuilder

AddSchema registers a named schema in components/schemas. Explicitly registered schemas take precedence over schemas inferred from channels.

func (*DocumentBuilder) AddServer

func (b *DocumentBuilder) AddServer(name string, s Server) *DocumentBuilder

AddServer registers a named server in the document.

func (*DocumentBuilder) Build

func (b *DocumentBuilder) Build() (Document, error)

Build validates the accumulated channels and produces a Document.

Validation:

  • Each channel must have at least one of Subscribe or Publish set.

type Info

type Info struct {
	Title       string
	Version     string
	Description string
}

Info holds the metadata for an AsyncAPI document.

type Message

type Message struct {
	Name string
	// Schema is the payload schema. Required when SchemaName is non-empty.
	Schema schema.Schema
	// SchemaName, when non-empty, emits a $ref and registers Schema in components/schemas.
	SchemaName  string
	ContentType string // defaults to "application/json"
}

Message describes the payload of an AsyncAPI operation.

When SchemaName is non-empty, the renderer emits a $ref in the payload and registers Schema under that name in components/schemas automatically. When SchemaName is empty, Schema is inlined as the payload.

type Operation

type Operation struct {
	Summary     string
	Description string
	Tags        []string
	Message     Message
}

Operation describes a subscribe or publish operation on a channel.

type Parameter added in v0.5.0

type Parameter struct {
	Description string
	Schema      schema.Schema
}

Parameter describes a channel parameter in an AsyncAPI 2.6 document.

Channel parameters correspond to {varName} placeholders in topic templates. Each parameter may carry a description and a JSON Schema.

type Server

type Server struct {
	URL         string
	Protocol    string // e.g. "amqp", "mqtt", "kafka", "https"
	Description string
}

Server describes one entry in the AsyncAPI servers map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL