Generate code

Found an error? Have a suggestion?Edit this page on GitHub

Generate Code from AsyncAPI Documents

This tutorial explains how to generate code from your AsyncAPI documents using the official AsyncAPI Generator.

Prerequisites

  • Node.js v20.12.0 or later
  • npm v10.5.0 or later
  • An AsyncAPI document

Installing the Generator

Install the AsyncAPI Generator globally using npm:

npm install -g @asyncapi/generator

Basic Usage

The basic syntax for generating code is:

ag <asyncapi-file> <template> [options]

For example, to generate HTML documentation:

ag asyncapi.yaml @asyncapi/html-template

Available Templates

The AsyncAPI Generator supports many official templates:

  • @asyncapi/html-template - Generate HTML documentation
  • @asyncapi/nodejs-template - Generate Node.js applications
  • @asyncapi/java-template - Generate Java applications
  • @asyncapi/python-template - Generate Python applications
  • @asyncapi/go-template - Generate Go applications

View all available templates in the template repository.

Template Options

Most templates support configuration options. To see available options:

ag help <template>

For example:

ag help @asyncapi/nodejs-template

Custom Templates

You can create your own templates for specific use cases. See the Template Development Guide for details.

Next Steps

Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub