-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs(generator): update latest generator documentation #4359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,21 @@ weight: 75 | |||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Reference API documentation for AsyncAPI Generator library. | ||||||||||||||||||||||||||||||||||||||
| ## Classes | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| <dl> | ||||||||||||||||||||||||||||||||||||||
| <dt><a href="#Generator">Generator</a></dt> | ||||||||||||||||||||||||||||||||||||||
| <dd></dd> | ||||||||||||||||||||||||||||||||||||||
| </dl> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ## Members | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| <dl> | ||||||||||||||||||||||||||||||||||||||
| <dt><a href="#listBakedInTemplates">listBakedInTemplates</a> ⇒ <code>Array.<Object></code></dt> | ||||||||||||||||||||||||||||||||||||||
| <dd><p>List core templates, optionally filter by type, stack, protocol, or target. | ||||||||||||||||||||||||||||||||||||||
| Use name of returned templates as input for the <code>generate</code> method for template generation. Such core templates code is part of the @asyncapi/generator package.</p></dd> | ||||||||||||||||||||||||||||||||||||||
| </dl> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| <a name="Generator"></a> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -494,3 +509,20 @@ const content = await Generator.getTemplateFile('@asyncapi/html-template', 'part | |||||||||||||||||||||||||||||||||||||
| const Generator = require('@asyncapi/generator'); | ||||||||||||||||||||||||||||||||||||||
| const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html', '~/my-templates'); | ||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| <a name="listBakedInTemplates"></a> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ## listBakedInTemplates | ||||||||||||||||||||||||||||||||||||||
| List core templates, optionally filter by type, stack, protocol, or target. | ||||||||||||||||||||||||||||||||||||||
| Use name of returned templates as input for the `generate` method for template generation. Such core templates code is part of the @asyncapi/generator package. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| **Kind**: global variable | ||||||||||||||||||||||||||||||||||||||
| **Returns**: `Array.<Object>` - Array of template objects matching the filter. | ||||||||||||||||||||||||||||||||||||||
| **Params** | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+513
to
+521
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. “Kind” is wrong; document full function signature and return shape This section currently labels the API as a “global variable.” It is a callable function. Also, adding the parameter list to the heading and clarifying the return objects improves usability. Apply this diff: -## listBakedInTemplates
-List core templates, optionally filter by type, stack, protocol, or target.
-Use name of returned templates as input for the `generate` method for template generation. Such core templates code is part of the @asyncapi/generator package.
-
-**Kind**: global variable
-**Returns**: `Array.<Object>` - Array of template objects matching the filter.
+## listBakedInTemplates([filter]) ⇒ `Array.<Object>`
+List baked-in templates, optionally filtered by type, stack, protocol, or target.
+Use the returned template name as the `templateName` when calling the `Generator`. Baked-in templates are bundled with `@asyncapi/generator`.
+
+**Kind**: global function
+**Returns**: `Array.<{ name: string, type: string, protocol?: string, target: string, stack?: string }>` - Template descriptors matching the filter. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~516-~516: There might be a mistake here. (QB_NEW_EN) [grammar] ~517-~517: There might be a mistake here. (QB_NEW_EN) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - [filter] `Object` - Optional filter object. | ||||||||||||||||||||||||||||||||||||||
| - [.type] `string` - Filter by template type (e.g., 'client', 'docs'). | ||||||||||||||||||||||||||||||||||||||
| - [.stack] `string` - Filter by stack (e.g., 'quarkus', 'express'). | ||||||||||||||||||||||||||||||||||||||
| - [.protocol] `string` - Filter by protocol (e.g., 'websocket', 'http'). | ||||||||||||||||||||||||||||||||||||||
| - [.target] `string` - Filter by target language or format (e.g., 'javascript', 'html'). | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,100 @@ | ||||||||||||||||||
| --- | ||||||||||||||||||
| title: "Baked-in Templates" | ||||||||||||||||||
| weight: 55 | ||||||||||||||||||
| --- | ||||||||||||||||||
|
|
||||||||||||||||||
| > This is a new concept introduced in generator version 2.8. The number of templates is limited and solution is still in experimental phase. It is not recommended to use them in production. Instead join us to help to improve them with your use cases and your AsyncAPI documents. | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tighten the experimental note and fix grammar Improve readability; add articles and punctuation. Apply this diff: -> This is a new concept introduced in generator version 2.8. The number of templates is limited and solution is still in experimental phase. It is not recommended to use them in production. Instead join us to help to improve them with your use cases and your AsyncAPI documents.
+> This is a new concept introduced in Generator version 2.8. The number of templates is limited, and the solution is still in the experimental phase. We do not recommend using them in production yet. Instead, please join us and help improve them with your use cases and AsyncAPI documents.📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~6-~6: There might be a mistake here. (QB_NEW_EN) 🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| Baked-in templates are official AsyncAPI templates that are **developed, versioned, and shipped directly inside the `generator` repository and exposed with `@asyncapi/generator` library**. | ||||||||||||||||||
|
|
||||||||||||||||||
| AsyncAPI Generator supports a variety of baked-in template types for generating code, documentation, configs, and SDKs. All templates are managed under the `packages/templates` directory and follow a strict, opinionated directory structure for consistency and ease of maintenance. | ||||||||||||||||||
|
|
||||||||||||||||||
| > List of baked-in templates: https://github.com/asyncapi/generator/blob/master/apps/generator/lib/templates/BakedInTemplatesList.json | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Supported template types | ||||||||||||||||||
|
|
||||||||||||||||||
| Templates are grouped by **type**, which must be one of the following: | ||||||||||||||||||
|
|
||||||||||||||||||
| - `docs` (not yet implemented): Templates that generate documentation | ||||||||||||||||||
| - `client`: Templates that generate clients | ||||||||||||||||||
| - `sdk` (not yet implemented): Template that generate full sdk's | ||||||||||||||||||
| - `config` (not yet implemented): Template that generate configuration files | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+18
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pluralization and capitalization fixes in supported types Fix verb agreement and SDK capitalization. Apply this diff: -- `docs` (not yet implemented): Templates that generate documentation
-- `client`: Templates that generate clients
-- `sdk` (not yet implemented): Template that generate full sdk's
-- `config` (not yet implemented): Template that generate configuration files
+- `docs` (not yet implemented): Templates that generate documentation.
+- `client`: Templates that generate clients.
+- `sdk` (not yet implemented): Templates that generate full SDKs.
+- `config` (not yet implemented): Templates that generate configuration files.📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~18-~18: There might be a mistake here. (QB_NEW_EN) 🤖 Prompt for AI Agents |
||||||||||||||||||
| > **Note:** | ||||||||||||||||||
| > The **directory name is always plural** (e.g., `clients`), but the **type recorded in metadata and package name is singular** (e.g., `client`), except for `docs`. | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Template directory structure | ||||||||||||||||||
|
|
||||||||||||||||||
| ### General structure | ||||||||||||||||||
|
|
||||||||||||||||||
| All template directories must follow this convention: | ||||||||||||||||||
| ``` | ||||||||||||||||||
| packages/templates/{type}/[protocol]/[target]/[stack] | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| - `type`: One of `docs`, `clients`, `sdks`, or `configs`. | ||||||||||||||||||
| - `protocol`: (Only for `clients` and `sdks`) The protocol this template supports, e.g. `websocket`, `http`, `kafka`. | ||||||||||||||||||
| - `target`: The output language, markup, or format, e.g. `javascript`, `python`, `html`, `yaml`. | ||||||||||||||||||
| - `stack`: (Optional, for `clients` and `sdks`) Used for technology stack, e.g. `express`, `quarkus`. | ||||||||||||||||||
|
|
||||||||||||||||||
| #### Type-specific rules | ||||||||||||||||||
|
|
||||||||||||||||||
| - **docs/configs**: | ||||||||||||||||||
| Path must be `type/target` (e.g., `docs/html` or `configs/yaml`). | ||||||||||||||||||
| - **clients/sdks**: | ||||||||||||||||||
| Path must be `type/protocol/target` or `type/protocol/target/stack` (e.g., `clients/websocket/javascript`, `sdks/kafka/java/spring`). | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Required files | ||||||||||||||||||
|
|
||||||||||||||||||
| Every template directory **must include**: | ||||||||||||||||||
| - `.ageneratorrc`: Generator specific configuration, like for example parameters | ||||||||||||||||||
| - `package.json`: It contains template name. Version information should not be provided as it is versioned together with the generator. | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+49
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammar fixes in “Required files” Hyphenate compound adjectives and clarify sentences. Apply this diff: -Every template directory **must include**:
-- `.ageneratorrc`: Generator specific configuration, like for example parameters
-- `package.json`: It contains template name. Version information should not be provided as it is versioned together with the generator.
+Every template directory **must include**:
+- `.ageneratorrc`: Generator-specific configuration (for example, parameters).
+- `package.json`: Contains the template name. Do not include a version; templates are versioned together with the Generator.📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~49-~49: There might be a mistake here. (QB_NEW_EN) [grammar] ~51-~51: There might be a mistake here. (QB_NEW_EN) 🤖 Prompt for AI Agents |
||||||||||||||||||
| ## Metadata and naming conventions | ||||||||||||||||||
|
|
||||||||||||||||||
| Generator build runs a script that normalize metadata for baked-in templates and their naming: | ||||||||||||||||||
| - Adds/updates metadata in `.ageneratorrc` file. You do not have to maintain it manually. | ||||||||||||||||||
| - Validates/updates template name in `package.json` file of given template. The name always starts with `core-template-` prefix. | ||||||||||||||||||
| - Generates JSON file with list of baked in templates and stores the list inside the generator: `apps/generator/lib/templates/BakedInTemplatesList.json` | ||||||||||||||||||
|
|
||||||||||||||||||
| #### Example | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix heading level increment (MD001) Change H4 to H3 to avoid skipping a level. Apply this diff: -#### Example
+### Example📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.17.2)60-60: Heading levels should only increment by one level at a time (MD001, heading-increment) 🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| Example information provided for template stored under `packages/templates/clients/websocket/javascript/express` | ||||||||||||||||||
|
|
||||||||||||||||||
| ```yaml | ||||||||||||||||||
| # .ageneratorrc | ||||||||||||||||||
| metadata: | ||||||||||||||||||
| type: client | ||||||||||||||||||
| protocol: websocket | ||||||||||||||||||
| target: javascript | ||||||||||||||||||
| stack: express | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| Package name format: `core-template-client-websocket-javascript-express` | ||||||||||||||||||
|
|
||||||||||||||||||
| Resulting entry in `apps/generator/lib/templates/BakedInTemplatesList.json`: | ||||||||||||||||||
| ```json | ||||||||||||||||||
| { | ||||||||||||||||||
| "name": "core-template-client-websocket-javascript-express", | ||||||||||||||||||
| "type": "client", | ||||||||||||||||||
| "protocol": "websocket", | ||||||||||||||||||
| "target": "javascript", | ||||||||||||||||||
| "stack": "express" | ||||||||||||||||||
| } | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| ## How to add a new baked-in template | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. Create the directory in `packages/templates` using the correct structure. | ||||||||||||||||||
| - For a docs template: | ||||||||||||||||||
| `packages/templates/docs/html` | ||||||||||||||||||
| - For a clients template: | ||||||||||||||||||
| `packages/templates/clients/websocket/rust` | ||||||||||||||||||
| 1. Add required files: | ||||||||||||||||||
| - `.ageneratorrc` (do not add `generator` config key as it is not needed) | ||||||||||||||||||
| - `package.json` | ||||||||||||||||||
| 1. Run generator's build command: `npm run build` | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Templates exposed through generator | ||||||||||||||||||
|
|
||||||||||||||||||
| Templates that are exposed as part of the generator are transpiled with the `react-sdk` and located in published library under `/lib/templates/bakedInTemplates`. This means that in case of baked-in templates, they are not picked by the generator from `node_modules`. This way the process of generation is faster and more efficient. | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use consistent terminology (“baked-in templates”) and fix grammar in Members description
Switch “core templates” to “baked-in templates” for consistency with the new docs and tighten the phrasing.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents