Examples
Fourteen worked examples live in the repository, under examples/. Each directory holds three files: the TypeSpec source, the tspconfig.yaml it was compiled with, and the asyncapi.yaml the emitter wrote from it.
The output is committed, so you can read an input and its output side by side without running anything. Every one of the fourteen passes the official AsyncAPI parser.
The examples
| Example | What it shows |
|---|---|
| Hello world | The smallest document the emitter can produce. @service and @info, and nothing else. |
| Payload schemas | The shapes of the schema layer: models, scalars, enums, arrays, records, and the constraints on them. |
| Schema composition | Four ways to build one schema out of others, plus the raw-schema escape hatch. |
| Message metadata | Everything that sits around a payload: headers, correlation ids, examples, tags and links. |
| Channels and parameters | Channel ids, templated addresses, and the parameters an address declares. |
| Servers and security | Servers, server variables, and the security schemes a server offers. |
| Request and reply | Three operations, and the two shapes an AsyncAPI reply can take. |
| Kafka user signup | One realistic Kafka contract, with all four Kafka bindings on one document. |
| MQTT bindings | The three MQTT decorators, and the one kind of name the generic @binding still carries. |
| Streetlights | The canonical AsyncAPI example, written in TypeSpec. |
| Multiple protocols | One application over Kafka, WebSocket and SQS, from one payload model. |
| HTTP callbacks | The HTTP bindings on a webhook, including the statusCode of a reply. |
| Enterprise brokers | AMQP, JMS, IBM MQ and Anypoint MQ describing one destination four ways. |
| Streaming platforms | NATS, Pulsar, Google Cloud Pub/Sub and Solace, and the fields each one requires. |
| Specification extensions | The x- fields the specification leaves to the author, on all four objects that take one. |
Running one
Clone the repository and compile inside the directory you want:
git clone https://github.com/marvin-hsu/tsp-asyncapi.git
cd tsp-asyncapi
pnpm install && pnpm build
cd examples/01-hello-world
pnpm exec tsp compile .The emitter writes asyncapi.yaml next to main.tsp, overwriting the copy in the repository. git diff then shows whether your build produces what was committed.
TIP
Every main.tsp starts with import "../..";, which points at the root of this repository. In your own project, depend on the package and write import "tsp-asyncapi"; instead.