Generator Templates#
AsyncAPI Generator supports two categories of templates: legacy standalone templates (separate repos, installed via npm) and baked-in templates (shipped directly inside the generator monorepo as of v2.8). This article focuses on the baked-in model, which is the active development path .
Two Template Generations#
Legacy standalone templates are separate GitHub repositories published under @asyncapi/* (e.g., @asyncapi/nodejs-template, @asyncapi/html-template). They are listed in the README and installed from npm at generation time. These repos are being progressively archived; see issue #2210 for the Node.js template successor as an example.
Baked-in templates are developed, versioned, and shipped directly inside the generator repository and exposed through the @asyncapi/generator library. They live under packages/templates/ and are transpiled with the react-sdk, landing in /lib/templates/bakedInTemplates within the published package — so they are not resolved from node_modules at runtime .
Directory Structure#
Baked-in templates follow a strict, opinionated path convention :
packages/templates/{type}/[protocol]/[target]/[stack]
| Segment | Values | Required for |
|---|---|---|
type | docs, clients, sdks, configs | all |
protocol | websocket, kafka, etc. | clients, sdks |
target | javascript, python, java, dart, etc. | all |
stack | quarkus, express, etc. | optional |
Directory names use the plural form (e.g.,
clients), but the metadata type recorded inpackage.jsonand.ageneratorrcuses the singular form (e.g.,client) .
Currently live templates :
core-template-client-kafka-java-quarkuscore-template-client-websocket-dartcore-template-client-websocket-java-quarkuscore-template-client-websocket-javascriptcore-template-client-websocket-python
docs,sdk, andconfigtypes are not yet implemented .
Required Files per Template#
Every template directory must contain :
.ageneratorrc— generator configuration (parameters, hooks, non-renderable files, metadata, conditional generation). Do not add thegeneratorconfig key manually; the build script owns that .package.json— contains the template name. Version is omitted because the template is versioned together with the generator .
The .ageneratorrc metadata block follows the path structure :
metadata:
type: client
protocol: websocket
target: javascript
stack: express # optional
Build Pipeline and Metadata Normalization#
Running npm run build triggers apps/generator/scripts/build-templates.js which:
- Traverses
packages/templates, collecting directories that have bothpackage.jsonand.ageneratorrc. - Derives metadata from the directory path segments via
getTemplateMeta(). - Maps plural path names to singular type values via
normalizeType(). - Writes normalized metadata back to
.ageneratorrcviaupdateAGeneratorRc()— you do not maintain metadata manually. - Updates template
package.jsonnames to enforce thecore-template-<type>-<protocol?>-<target>-<stack?>format . - Transpiles templates with
react-sdk. - Regenerates
apps/generator/lib/templates/BakedInTemplatesList.json— the runtime registry consumed by the generator .
Adding a New Baked-In Template#
- Create the directory under
packages/templates/using the correct path convention . - Add
.ageneratorrc(without thegeneratorkey) andpackage.json. - Run
npm run build— the script handles naming, metadata population, transpilation, and registry update .
Key References#
| Resource | Link |
|---|---|
| Baked-in templates doc | apps/generator/docs/baked-in-templates.md |
| Template registry JSON | apps/generator/lib/templates/BakedInTemplatesList.json |
| Build script | apps/generator/scripts/build-templates.js |
| packages/templates/ directory | packages/templates/ in the monorepo root |
| Legacy templates list | README.md §List of official generator templates |
| Node.js successor issue | #2210 |
| Official docs | asyncapi.com — baked-in templates |