Documentation
¶
Overview ¶
Package asyncapi3 emits AsyncAPI 3.0.0 documents from Go code.
Marshaled output is deterministic (maps sort, struct order is fixed), so regenerating an unchanged document is byte-identical — a contract relied on by regen-diff CI gates.
Index ¶
- Constants
- func Check(generated []byte, path string) error
- func MergeSchemas(dst, src map[string]json.RawMessage) error
- func SchemaFromType(v any, opts ...ReflectOption) (json.RawMessage, map[string]json.RawMessage, error)
- func ValidateBytes(document []byte) error
- type Channel
- type Components
- type Contact
- type Document
- type ExternalDocs
- type Info
- type License
- type Message
- type Operation
- type OperationReply
- type Parameter
- type RefObj
- type ReflectOption
- type Server
- type Tag
Constants ¶
const ( ActionSend = "send" ActionReceive = "receive" )
const Version = "3.0.0"
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check compares freshly generated document bytes against the committed artifact at path, so contract-drift gating runs as one tested code path locally and in CI instead of shell logic in a workflow.
func MergeSchemas ¶
func MergeSchemas(dst, src map[string]json.RawMessage) error
MergeSchemas folds src into dst, failing on same-name definitions with different content — a silent overwrite would corrupt one of the schemas.
func SchemaFromType ¶
func SchemaFromType(v any, opts ...ReflectOption) (json.RawMessage, map[string]json.RawMessage, error)
func ValidateBytes ¶
ValidateBytes checks an already-marshalled AsyncAPI document against the embedded official AsyncAPI 3.0.0 meta-schema.
Types ¶
type Channel ¶
type Channel struct {
Address string `json:"address,omitempty"`
Title string `json:"title,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Messages map[string]Message `json:"messages,omitempty"`
Parameters map[string]Parameter `json:"parameters,omitempty"`
Servers []RefObj `json:"servers,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Bindings json.RawMessage `json:"bindings,omitempty"`
}
type Components ¶
type Components struct {
Schemas map[string]json.RawMessage `json:"schemas,omitempty"`
Messages map[string]Message `json:"messages,omitempty"`
Parameters map[string]Parameter `json:"parameters,omitempty"`
Servers map[string]Server `json:"servers,omitempty"`
Channels map[string]Channel `json:"channels,omitempty"`
}
type Document ¶
type Document struct {
AsyncAPI string `json:"asyncapi"`
ID string `json:"id,omitempty"`
Info Info `json:"info"`
DefaultContentType string `json:"defaultContentType,omitempty"`
Servers map[string]Server `json:"servers,omitempty"`
Channels map[string]Channel `json:"channels,omitempty"`
Operations map[string]Operation `json:"operations,omitempty"`
Components *Components `json:"components,omitempty"`
}
type ExternalDocs ¶
type Info ¶
type Info struct {
Title string `json:"title"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty"`
License *License `json:"license,omitempty"`
Tags []Tag `json:"tags,omitempty"`
ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}
type Message ¶
type Message struct {
Ref string `json:"$ref,omitempty"`
Name string `json:"name,omitempty"`
Title string `json:"title,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
ContentType string `json:"contentType,omitempty"`
Headers json.RawMessage `json:"headers,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
Examples json.RawMessage `json:"examples,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Bindings json.RawMessage `json:"bindings,omitempty"`
}
type Operation ¶
type Operation struct {
Action string `json:"action,omitempty"`
Channel RefObj `json:"channel,omitzero"`
Title string `json:"title,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Messages []RefObj `json:"messages,omitempty"`
Reply *OperationReply `json:"reply,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Bindings json.RawMessage `json:"bindings,omitempty"`
}
type OperationReply ¶
type ReflectOption ¶
type ReflectOption func(*reflectConfig)
func RequireAll ¶
func RequireAll() ReflectOption
RequireAll marks every property of every reflected definition as required. Correct only for payloads whose Go structs never use omitempty — Go then marshals every field on every message.
type Server ¶
type Server struct {
Host string `json:"host"`
Protocol string `json:"protocol"`
Pathname string `json:"pathname,omitempty"`
Description string `json:"description,omitempty"`
Title string `json:"title,omitempty"`
Summary string `json:"summary,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Bindings json.RawMessage `json:"bindings,omitempty"`
}
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
requestreply
command
Command requestreply emits an AsyncAPI 3.0 document for an in-band authentication handshake: the server asks for a token, the client answers on the same channel.
|
Command requestreply emits an AsyncAPI 3.0 document for an in-band authentication handshake: the server asks for a token, the client answers on the same channel. |
|
websocket
command
Command websocket emits an AsyncAPI 3.0 document for a server-to-client WebSocket broadcast, with the payload schema reflected from the Go struct that is actually written to the socket.
|
Command websocket emits an AsyncAPI 3.0 document for a server-to-client WebSocket broadcast, with the payload schema reflected from the Go struct that is actually written to the socket. |