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 ¶
MarshalJSON encodes the document as JSON bytes.
func (Document) MarshalYAML ¶
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 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.