Stop hand-writing AsyncAPI YAML.
Model your event schemas, channels, and operations in TypeSpec — compile to AsyncAPI 3.1 documents that validate against the official JSON Schema.
22 protocols 19 bindings 30 decorators 38 diagnostics 308 compliance tests
pnpm add @lars-artmann/typespec-asyncapi import "@lars-artmann/typespec-asyncapi";
using TypeSpec.AsyncAPI;
@service(#{ title: "Orders" })
namespace Orders;
model OrderPlaced {
orderId: string;
total: decimal;
placedAt: utcDateTime;
}
@channel("orders.placed")
@publish
@protocol(#{ protocol: "kafka", topic: "orders.placed", partitions: 6 })
op publishOrderPlaced(): OrderPlaced;
asyncapi: 3.1.0
info:
title: Orders
version: 1.0.0
channels:
orders.placed:
address: orders.placed
messages:
OrderPlaced:
$ref: "#/components/messages/OrderPlaced"
bindings:
kafka:
partitions: 6
topic: orders.placed
bindingVersion: 0.5.0
operations:
publishOrderPlaced:
action: send
channel:
$ref: "#/channels/orders.placed"
messages:
- $ref: "#/channels/orders.placed/messages/OrderPlaced"
components:
messages:
OrderPlaced:
name: OrderPlaced
contentType: application/json
title: OrderPlaced
payload:
$ref: "#/components/schemas/OrderPlaced"
schemas:
OrderPlaced:
properties:
orderId:
type: string
total:
format: decimal
type: string
placedAt:
format: date-time
type: string
type: object
required:
- orderId
- total
- placedAt
Real output, not a mockup — the complete document the emitter writes for the file on the left. A test compiles this exact pair and validates it against the official AsyncAPI 3.1.0 JSON Schema.
The real compiler, running in this tab
This is not a screenshot. The TypeSpec compiler and this emitter are bundled into the page, compiled against an in-memory file system, and re-run on every edit.
Loading the compiler…
Runs entirely in your browser — your spec is never uploaded. The engine (~310 KB gzipped) loads only when this section comes into view.
import "@lars-artmann/typespec-asyncapi";
using TypeSpec.AsyncAPI;
@service(#{ title: "Orders" })
namespace Orders;
model OrderPlaced {
orderId: string;
total: decimal;
placedAt: utcDateTime;
}
@channel("orders.placed")
@publish
@protocol(#{ protocol: "kafka", topic: "orders.placed", partitions: 6 })
op publishOrderPlaced(): OrderPlaced;
import "@lars-artmann/typespec-asyncapi";
using TypeSpec.AsyncAPI;
@service(#{ title: "Sensors" })
namespace Sensors;
model Reading {
sensorId: string;
celsius: float32;
at: utcDateTime;
}
@channel("sensors.reading")
@publish
@protocol(#{ protocol: "mqtt", qos: 1, retain: false })
op publishReading(): Reading;
import "@lars-artmann/typespec-asyncapi";
using TypeSpec.AsyncAPI;
@service(#{ title: "Chat" })
namespace Chat;
model ChatMessage {
room: string;
author: string;
text: string;
sentAt: utcDateTime;
}
@channel("chat.messages")
@publish
@protocol(#{ protocol: "ws" })
op publishMessage(): ChatMessage;
import "@lars-artmann/typespec-asyncapi";
using TypeSpec.AsyncAPI;
@service(#{ title: "Inventory" })
namespace Inventory;
@message(#{ title: "StockLevel" })
model StockLevel {
sku: string;
available: int32;
}
@channel("inventory.stock")
@subscribe
@protocol(#{ protocol: "kafka", topic: "inventory-stock" })
op onStockLevel(): StockLevel;
@channel("inventory.alerts")
@publish
@protocol(#{ protocol: "mqtt", qos: 2 })
op publishAlert(): StockLevel;
Typed in. Validated out.
Everything between your TypeSpec source and a spec-compliant AsyncAPI 3.1 document is table-driven, tested, and deterministic.
Validated AsyncAPI 3.1
Every byte of output is checked against the official AsyncAPI 3.1.0 JSON Schema (AJV) across a 308-test compliance suite — invalid specs cannot ship.
22 protocols, 19 bindings
Kafka, MQTT, AMQP, WebSocket, NATS, and more. All bindings auto-generated from @asyncapi/specs with version auto-injection and placement checking.
30 typed decorators
Channels, messages, servers, security schemes, traits, parameters, and protocol bindings — declared in TypeSpec with compile-time validation, not YAML indentation.
Clean $ref architecture
Named models, enums, and generic instantiations (Page<User> → PageUser) become reusable components.schemas entries with spec-correct reference chains.
One compile, many outputs
Emit single-file YAML or JSON, or split every schema into its own file with rewritten $ref pointers. Version info flows in from @typespec/versioning.
38 compile-time diagnostics
Unsupported protocols, misplaced bindings, malformed server URLs, and invalid security schemes are caught in your editor before they reach the output.
Model, compile, validate, ship
Four deterministic steps from typed source to a spec-compliant AsyncAPI document.
Model in TypeSpec
Define event schemas, channels, operations, servers, and security in one typed language. Decorators carry AsyncAPI semantics; the compiler carries the validation.
Compile with tsp
tsp compile resolves imports, checks 38 diagnostics, and hands the type graph to the emitter — invalid protocols and misplaced bindings never reach the output.
Emit the spec
A table-driven schema pipeline maps every scalar, constraint, union, and generic instantiation to JSON Schema, assembling the $ref chain AsyncAPI 3.1 expects.
Validate and ship
The 308-test compliance suite proves every emitted document against the official AsyncAPI 3.1.0 JSON Schema — feed it to AsyncAPI Studio, generators, or CI.
This emitter vs the alternatives
A capability snapshot against the other TypeSpec AsyncAPI emitter and hand-written YAML (checked October 2026).
| Capability | typespec-asyncapi | tsp-asyncapi | Hand-written YAML |
|---|---|---|---|
| AsyncAPI version | 3.1.0 (latest) | 3.0.0 | any |
| Output validation | 308 AJV compliance tests | 15 property tests | Spectral, at best |
| Protocols | 22, bindings spec-generated | 13, hand-written | manual per protocol |
| Reusable components | 7 slots, 11 decorators | not supported | copy-paste |
| Multi-file output | split-schemas + $ref rewrite | not supported | manual |
| Compile-time diagnostics | 38 codes | deferred | lint only |
| Typed source of truth | TypeSpec | TypeSpec | none |
AsyncAPI version
- typespec-asyncapi
- 3.1.0 (latest)
- tsp-asyncapi
- 3.0.0
- Hand-written
- any
Output validation
- typespec-asyncapi
- 308 AJV compliance tests
- tsp-asyncapi
- 15 property tests
- Hand-written
- Spectral, at best
Protocols
- typespec-asyncapi
- 22, bindings spec-generated
- tsp-asyncapi
- 13, hand-written
- Hand-written
- manual per protocol
Reusable components
- typespec-asyncapi
- 7 slots, 11 decorators
- tsp-asyncapi
- not supported
- Hand-written
- copy-paste
Multi-file output
- typespec-asyncapi
- split-schemas + $ref rewrite
- tsp-asyncapi
- not supported
- Hand-written
- manual
Compile-time diagnostics
- typespec-asyncapi
- 38 codes
- tsp-asyncapi
- deferred
- Hand-written
- lint only
Typed source of truth
- typespec-asyncapi
- TypeSpec
- tsp-asyncapi
- TypeSpec
- Hand-written
- none
The real differentiator is the first two rows: no other workflow proves, on every build, that the emitted document passes the official AsyncAPI 3.1.0 JSON Schema. More on the ecosystem.
Built for event-driven teams
Where a typed, validated AsyncAPI source of truth pays for itself.
AsyncAPI as code
Schemas, examples, security schemes, and bindings regenerate from source — the spec can no longer drift from the system it describes.
Multi-protocol estates
One TypeSpec namespace, Kafka + MQTT + WebSocket bindings with auto-injected versions and spec-checked placements across 22 protocols.
CI compliance gates
Every build emits documents that pass the official AsyncAPI 3.1.0 JSON Schema — contract violations fail the pipeline, not production.
Docs that stay current
Descriptions, tags, examples, and external docs live next to the operations they describe, so documentation updates itself on every compile.
Your first validated spec is one compile away
Install the emitter, add two decorators to a TypeSpec file, and generate AsyncAPI 3.1 that already passes the official JSON Schema.