gen-asyncapi

module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT

README

gen-asyncapi

Go Reference CI coverage version license

Feed it an AsyncAPI 3 document and it spits out Go or TypeScript types, strict JSON decoding and a client for your WebSocket API. Run it from go generate with a small config file and the path to your spec, and the generated file lands next to your code.

Decoding is strict. A frame either matches its schema or you get an error that names every message it tried and why each one said no.

Spec loading comes from go-asyncapi. Grab that one directly if you want to read AsyncAPI 3 documents in Go without generating anything.

Contents

Install

go install github.com/psyb0t/gen-asyncapi/cmd/gen-asyncapi@latest

As a Go tool in your module, so go tool gen-asyncapi runs the version your go.mod pins:

go get -tool github.com/psyb0t/gen-asyncapi/cmd/gen-asyncapi@latest

A TypeScript project needs no Go module, just Go installed: Install and run has the go run line.

Quick start

Drop a config.yaml and a gen.go where the code should go:

# config.yaml
package: chat
output: chat.gen.go
// gen.go
package chat

//go:generate go tool gen-asyncapi --config=config.yaml ../../api/asyncapi.yaml

Run go generate ./... and chat.gen.go appears, with a struct per schema, strict UnmarshalJSON and Validate, a Handler for incoming messages and a Client with one method per outgoing one:

conn, err := gorillaws.Dial(
	ctx,
	chat.ServerProductionURL,
	gorillaws.WithBearerToken(token),
)
if err != nil {
	return err
}

client := chat.NewClient(conn)
defer client.Close()

err = client.JoinRoom(ctx, chat.JoinRequest{ID: id, Room: "lobby"})

Add -language=typescript -o=chat.gen.ts and the same spec turns into one dependency-free .ts file whose client takes a browser WebSocket.

Documentation

The full documentation lives at https://psyb0t.github.io/gen-asyncapi/.

Page What it covers
Install and run Install routes, the command line, go generate, logging, upgrades
Configuration Every config key, its default and what fails validation
Go output Structs, enums, unions, sending and receiving in Go
TypeScript output Interfaces, validators and the browser client
Message matching How incoming frames are told apart, and message-matchers
What gets generated Each spec part and what it becomes in both languages
AsyncAPI 3 coverage Every AsyncAPI object and schema keyword, one row each
Example packages The committed examples and what each one proves
Agent integrations The agent skill for Claude Code, Codex and OpenClaw
Troubleshooting Generator errors and runtime decoding errors, with fixes
Development Make targets, the dev image, CI and releases

Agent integrations

The skill teaches a coding agent how to set up the generator and use the code it writes, in Go and TypeScript:

claude plugin marketplace add psyb0t/agents
claude plugin install gen-asyncapi@psyb0t

Codex and OpenClaw installs are on the Agent integrations page.

Development

Everything runs in the Dockerfile.dev image. You need Docker and Make.

make help           # list targets
make generate       # regenerate the examples
make lint           # shellcheck, shfmt, go fix, golangci-lint
make test-coverage  # go test -race with a 90% coverage gate, then make test-ts
make docs           # build the documentation site into .testing/docs-site

Development covers the rest, including CI and releases. Contributor and agent instructions are in AGENTS.md.

Sponsor

Buy Me a Coffee

License

MIT. The specs in examples/official come from the AsyncAPI specification repository under Apache 2.0.

Directories

Path Synopsis
Package asyncapirt is the support code that gen-asyncapi generated packages call: validation helpers, strict object decoding, incoming message matching, and the transport interface the generated client sends and receives through.
Package asyncapirt is the support code that gen-asyncapi generated packages call: validation helpers, strict object decoding, incoming message matching, and the transport interface the generated client sends and receives through.
gorillaws
Package gorillaws is an asyncapirt.Transport over gorilla/websocket.
Package gorillaws is an asyncapirt.Transport over gorilla/websocket.
cmd
gen-asyncapi command
Command gen-asyncapi generates Go or TypeScript types, strict JSON decoding and a client from an AsyncAPI 3 document:
Command gen-asyncapi generates Go or TypeScript types, strict JSON decoding and a client from an AsyncAPI 3 document:
examples
chat
Package chat is generated from chat.yaml, a spec that uses every feature gen-asyncapi supports.
Package chat is generated from chat.yaml, a spec that uses every feature gen-asyncapi supports.
kitchensink
Package kitchensink is generated from kitchensink.yaml, which uses every AsyncAPI 3.0 object and every schema keyword the generator reads.
Package kitchensink is generated from kitchensink.yaml, which uses every AsyncAPI 3.0 object and every schema keyword the generator reads.
official/adeo_kafka_request_reply
Package adeo_kafka_request_reply is generated from the official AsyncAPI example adeo-kafka-request-reply-asyncapi.yml.
Package adeo_kafka_request_reply is generated from the official AsyncAPI example adeo-kafka-request-reply-asyncapi.yml.
official/anyof
Package anyof is generated from the official AsyncAPI example anyof-asyncapi.yml.
Package anyof is generated from the official AsyncAPI example anyof-asyncapi.yml.
official/application_headers
Package application_headers is generated from the official AsyncAPI example application-headers-asyncapi.yml.
Package application_headers is generated from the official AsyncAPI example application-headers-asyncapi.yml.
official/correlation_id
Package correlation_id is generated from the official AsyncAPI example correlation-id-asyncapi.yml.
Package correlation_id is generated from the official AsyncAPI example correlation-id-asyncapi.yml.
official/gitter_streaming
Package gitter_streaming is generated from the official AsyncAPI example gitter-streaming-asyncapi.yml.
Package gitter_streaming is generated from the official AsyncAPI example gitter-streaming-asyncapi.yml.
official/kraken_websocket_request_reply_message_filter_in_reply
Package kraken_websocket_request_reply_message_filter_in_reply is generated from the official AsyncAPI example kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml.
Package kraken_websocket_request_reply_message_filter_in_reply is generated from the official AsyncAPI example kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml.
official/kraken_websocket_request_reply_multiple_channels
Package kraken_websocket_request_reply_multiple_channels is generated from the official AsyncAPI example kraken-websocket-request-reply-multiple-channels-asyncapi.yml.
Package kraken_websocket_request_reply_multiple_channels is generated from the official AsyncAPI example kraken-websocket-request-reply-multiple-channels-asyncapi.yml.
official/mercure
Package mercure is generated from the official AsyncAPI example mercure-asyncapi.yml.
Package mercure is generated from the official AsyncAPI example mercure-asyncapi.yml.
official/not
Package not is generated from the official AsyncAPI example not-asyncapi.yml.
Package not is generated from the official AsyncAPI example not-asyncapi.yml.
official/oneof
Package oneof is generated from the official AsyncAPI example oneof-asyncapi.yml.
Package oneof is generated from the official AsyncAPI example oneof-asyncapi.yml.
official/operation_security
Package operation_security is generated from the official AsyncAPI example operation-security-asyncapi.yml.
Package operation_security is generated from the official AsyncAPI example operation-security-asyncapi.yml.
official/rpc_client
Package rpc_client is generated from the official AsyncAPI example rpc-client-asyncapi.yml.
Package rpc_client is generated from the official AsyncAPI example rpc-client-asyncapi.yml.
official/rpc_server
Package rpc_server is generated from the official AsyncAPI example rpc-server-asyncapi.yml.
Package rpc_server is generated from the official AsyncAPI example rpc-server-asyncapi.yml.
official/simple
Package simple is generated from the official AsyncAPI example simple-asyncapi.yml.
Package simple is generated from the official AsyncAPI example simple-asyncapi.yml.
official/slack_rtm
Package slack_rtm is generated from the official AsyncAPI example slack-rtm-asyncapi.yml.
Package slack_rtm is generated from the official AsyncAPI example slack-rtm-asyncapi.yml.
official/streetlights_kafka
Package streetlights_kafka is generated from the official AsyncAPI example streetlights-kafka-asyncapi.yml.
Package streetlights_kafka is generated from the official AsyncAPI example streetlights-kafka-asyncapi.yml.
official/streetlights_mqtt
Package streetlights_mqtt is generated from the official AsyncAPI example streetlights-mqtt-asyncapi.yml.
Package streetlights_mqtt is generated from the official AsyncAPI example streetlights-mqtt-asyncapi.yml.
official/streetlights_operation_security
Package streetlights_operation_security is generated from the official AsyncAPI example streetlights-operation-security-asyncapi.yml.
Package streetlights_operation_security is generated from the official AsyncAPI example streetlights-operation-security-asyncapi.yml.
official/websocket_gemini
Package websocket_gemini is generated from the official AsyncAPI example websocket-gemini-asyncapi.yml.
Package websocket_gemini is generated from the official AsyncAPI example websocket-gemini-asyncapi.yml.
shapes
Package shapes is generated from shapes.yaml, which covers the schema forms the chat example does not: unions without a discriminator keyword, primitive variants, typed maps, nullable fields, recursive schemas and numeric enums.
Package shapes is generated from shapes.yaml, which covers the schema forms the chat example does not: unions without a discriminator keyword, primitive variants, typed maps, nullable fields, recursive schemas and numeric enums.
internal

Jump to

Keyboard shortcuts

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