Examples
Every directory under examples/ is a project that compiles as it stands. It holds the TypeSpec source, the tspconfig.yaml it was compiled with, and the output. The output is committed, so you can read an input and its output side by side without running anything.
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 @jsonSchemaExtension 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. It also carries an Avro payload and a Protobuf payload. |
| 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. |
| Protobuf payloads | Two Protobuf packages over RabbitMQ, with the .proto files emitted next to the document. |
| Avro schemas | One order domain written as Avro schema files by tsp-avro. No AsyncAPI document. |
| Avro payloads | Two Avro records over Kafka, with the .avsc files emitted next to the document. |
Running one
Clone the repository, then compile inside the directory you want:
bash
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.