Examples
Every example is a self-contained TypeSpec project. CI compiles all of them with zero diagnostics and validates each emitted document against the official AsyncAPI 3.1.0 JSON Schema.
Featured examples
Section titled “Featured examples”| Example | What it shows |
|---|---|
streetlights-mqtt |
The canonical AsyncAPI Streetlights example: MQTT server with variables, channel address templating via @parameter, constraints, and enum payloads. |
kafka-orders |
Kafka bindings at spec-correct placements (topic/partitions/replicas on the channel, groupId on the operation), scramSha512 security, and @discriminator polymorphism. |
websocket-chat |
WebSocket bindings (method/query), @header, @correlationId, @reply with a runtime-expression address, and generic Page<T> schema naming. |
reusable-components |
The components.* showcase: @operationTrait, @messageTrait, @parameter, @reusableCorrelationId, @reusableBinding, and @useChannelServer. |
split-schemas |
Multi-file output: one file per schema, with every $ref rewritten to an external path. |
More examples
Section titled “More examples”| Example | What it shows |
|---|---|
simple / smoke / basic-events |
Minimal getting-started specs, including a custom output-file. |
kafka |
Kafka bindings with a schema-keyed payload. |
multi-channel |
Multiple channels sharing models. |
comprehensive-protocols |
Many protocols in one document. |
advanced |
Advanced decorator combinations. |
real-world |
Four realistic multi-file event systems (HTTP, Kafka, WebSocket, multi-protocol). |
mixed-rest-events |
A REST namespace and an event namespace in one program, without phantom OpenAPI routes. |
schema-extensions |
@jsonSchemaExtension and @extension vendor keywords. |
Run them
Section titled “Run them”git clone https://github.com/LarsArtmann/typespec-asyncapicd typespec-asyncapipnpm installpnpm run buildpnpm run check-examplesOr compile one example by hand:
cd examples/streetlights-mqttpnpm exec tsp compile main.tspcat tsp-output/@lars-artmann/typespec-asyncapi/asyncapi.yamlWhere to go next
Section titled “Where to go next”- Quick Start — build your first spec from scratch
- Protocol Bindings — placement and version rules for each protocol
- Multi-File Output — the
split-schemasoption in depth