Skip to content
TypeSpec EMITS AsyncAPI
17 stars v1.3.0 on npm AsyncAPI 3.1.0 · AJV-validated

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
api.tsp — what you write
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;
tsp compile .
asyncapi.yaml — what you ship schema-valid
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.

Try it

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.

Waiting to load
api.tsp editable
asyncapi.yaml real output
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.

Why this emitter

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.

TypeSpec EMITS AsyncAPI
How it works

Model, compile, validate, ship

Four deterministic steps from typed source to a spec-compliant AsyncAPI document.

01

Model in TypeSpec

Define event schemas, channels, operations, servers, and security in one typed language. Decorators carry AsyncAPI semantics; the compiler carries the validation.

02

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.

03

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.

04

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.

Comparison

This emitter vs the alternatives

A capability snapshot against the other TypeSpec AsyncAPI emitter and hand-written YAML (checked October 2026).

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.

Use cases

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.

Get started

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.