@asyncapi/generator 1.9.13 → 1.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ ---
2
+ title: "Installation guide"
3
+ weight: 20
4
+ ---
5
+
6
+ You can use the generator library to generate whatever you want in your event-driven architecture apps. Find your preferred method below:
7
+ - [AsyncAPI CLI](#asyncapi-cli)
8
+ - [Generator library in Node.js apps](#generator-library-in-nodejs-apps)
9
+
10
+ ## Prerequisites
11
+ Before you install and use the AsyncAPI CLI and the generator library, ensure you meet the prerequisites below, then [install the CLI](#installation).
12
+ 1. Node.js v12.16 and higher
13
+ 2. Npm v6.13.7 and higher
14
+
15
+ To verify the versions of Node and Npm you have, run the following command on your terminal:
16
+ ```
17
+ npm -v
18
+ ```
19
+ ```
20
+ node -v
21
+ ```
22
+
23
+ If you don't have either Node or Npm installed, use the [official node.js installer](https://nodejs.org/en/download/).
24
+
25
+ If you have the correct versions installed, proceed to the CLI installation guide below. Otherwise, upgrading the Npm or Node version is lower than the recommended versions specified above.
26
+
27
+ ## AsyncAPI CLI
28
+ The AsyncAPI CLI tool allows you to do many different things with the [AsyncAPI document](asyncapi-document). You can generate message-based API boilerplate code, documentation, or anything else you need as long as you specify it in your [template](template) or the existing template already supports it. To use the generator via the AsyncAPI CLI, you need to install the AsyncAPI CLI tool.
29
+
30
+ ### Installation
31
+
32
+ #### Install AsyncAPI CLI using NPM
33
+
34
+ The AsyncAPI CLI is a NodeJS project, so the easiest way to install it is by using the following `npm` command:
35
+ ```
36
+ npm install -g @asyncapi/cli
37
+ ```
38
+
39
+ To install a specific version of the generator tool, pass the version during installation:
40
+ ```
41
+ npm install -g @asyncapi/cli@{version}
42
+ ```
43
+
44
+ #### MacOS
45
+ You can install in MacOS by using brew: `brew install asyncapi`.
46
+
47
+ #### Linux
48
+ You can install in Linux by using `dpkg`, a package manager for debian:
49
+ 1. `curl -OL https://github.com/asyncapi/cli/releases/latest/download/asyncapi.deb`
50
+ 2. `sudo dpkg -i asyncapi.deb`
51
+
52
+ #### Other operating systems
53
+ For further installation instructions for different operating systems, read the [AsyncAPI CLI documentation](https://github.com/asyncapi/cli#installation).
54
+
55
+ > **Remember:**
56
+ > Each [community-developed template](https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate) is dependent on a certain version of the generator for it to work correctly. Before you install the generator CLI, check the template's `package.json` for the version of the generator CLI your template is compatible with. Read the [versioning docs](versioning) to learn why it's important to use certain generator versions with your templates.
57
+
58
+ ### Update AsyncAPI CLI
59
+ There are several reasons why you might want to update your generator version:
60
+ * You have the generator tool installed but want to use the latest released features. To upgrade to the latest version, use the command below:
61
+ ```
62
+ npm install -g @asyncapi/cli
63
+ ```
64
+ * If your template isn't compatible with the latest generator version, you can update it to a specific version of the generator. Check the [version you need](https://github.com/asyncapi/cli/releases) and specify the version you want by using the **@** symbol as shown in the command below:
65
+ ```
66
+ npm install -g @asyncapi/cli@{version}
67
+ ```
68
+ > Sometimes you have to force additional npm installation like this: `npm install -g --force @asyncapi/cli`
69
+
70
+ ### Uninstall AsyncAPI CLI
71
+ To uninstall the generator, use the following command:
72
+ ```
73
+ npm uninstall @asyncapi/cli -g
74
+ ```
75
+
76
+ > :memo: **Note:** To use the generator in your CI/CD pipeline to automate whatever you generate for your event-driven architecture apps, install the AsyncAPI CLI in your pipeline. If you are using GitHub Actions, use [Github Actions for Generator](https://github.com/marketplace/actions/generator-for-asyncapi-documents).
77
+
78
+ ## Generator library in Node.js apps
79
+ Use the generator library in your Node.js projects by installing it via the following command: `npm install @asyncapi/generator`.
80
+
81
+ > Don't include the `-g` flag in the installation command above since you're not installing the generator library globally but in your Node.js project.
@@ -0,0 +1,12 @@
1
+ {{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
2
+ {{#if name}}{{#sig~}}
3
+ {{{@depOpen}~}}
4
+ {{{@codeOpen}~}}
5
+ {{#if @prefix}}{{@prefix}} {{/if~}}
6
+ {{@parent~}}
7
+ {{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{escape name}}}{{/if~}}
8
+ {{{@codeClose}~}}
9
+ {{#if @suffix}} {{@suffix}}{{/if~}}
10
+ {{{@depClose}~}}
11
+ {{~/sig}}{{/if}}
12
+ {{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
@@ -0,0 +1 @@
1
+ {{#unless (equal defaultvalue undefined)}}`{{#if equals}} = {{/if}}{{#if (equal type.names.[0] "string")}}{{{json-stringify defaultvalue}}}{{else}}{{{defaultvalue}}}{{/if}}`{{/unless}}
@@ -0,0 +1,12 @@
1
+
2
+ <a name="{{{anchorName}}}"></a>
3
+
4
+ {{#if (equal kind "class")}}
5
+ {{>heading-indent}}{{>custom-sig-name}}
6
+ {{~else~}}
7
+ {{#if params}}
8
+ {{>heading-indent}}{{>custom-sig-name}}
9
+ {{~else~}}
10
+ * {{>sig-name}}** :
11
+ {{/if}}
12
+ {{/if}}
@@ -0,0 +1,25 @@
1
+ {{! usage: link to="namepath" html=true/false caption="optional caption"~}}
2
+
3
+ {{~#if html~}}
4
+ <code>
5
+
6
+ {{~#link to~}}
7
+ {{#if url~}}
8
+ <a href="{{{url}}}">{{#if ../../caption}}{{../../../caption}}{{else}}{{name}}{{/if}}</a>
9
+ {{~else~}}
10
+ {{#if ../../caption}}{{../../../caption}}{{else}}{{name}}{{/if~}}
11
+ {{/if~}}
12
+ {{/link~}}
13
+
14
+ </code>
15
+ {{~else~}}
16
+
17
+ {{#link to~}}
18
+ {{#if url~}}
19
+ [`{{#if ../../caption}}{{{../../../caption}}}{{else}}{{{name}}}{{/if}}`]({{{url}}})
20
+ {{~else~}}
21
+ `{{#if ../../caption}}{{{../../../caption}}}{{else}}{{{name}}}{{/if~}}`
22
+ {{~/if~}}
23
+ {{/link~}}
24
+
25
+ {{/if~}}
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: Library API
3
+ weight: 75
4
+ ---
5
+
6
+ Reference API documentation for AsyncAPI Generator library.
7
+ {{>main-index~}}
8
+ {{>all-docs~}}
@@ -0,0 +1,9 @@
1
+ {{#if params}}
2
+ {{#params}}**Params**
3
+
4
+ {{#each this~}}
5
+ {{indent}}- {{name}}{{#if type}} {{>linked-type-list types=type.names delimiter=" | " }}{{/if}}{{#unless (equal defaultvalue undefined)}} {{>defaultvalue equals=true ~}}{{/unless}}{{#if description}} - {{{inlineLinks description}}}{{/if}}
6
+ {{/each}}
7
+
8
+ {{/params~}}
9
+ {{/if}}
@@ -1,6 +1,6 @@
1
1
  ---
2
- title: "Nunjucks Render Engine"
3
- weight: 70
2
+ title: "Nunjucks render engine"
3
+ weight: 120
4
4
  ---
5
5
 
6
6
  [Nunjucks](https://mozilla.github.io/nunjucks) is the default render engine, however, we strongly recommend adopting the [React](#react) engine.
package/docs/parser.md CHANGED
@@ -1,6 +1,96 @@
1
1
  ---
2
2
  title: "Parser"
3
- weight: 90
3
+ weight: 60
4
4
  ---
5
5
 
6
- >This document is under construction.
6
+ ## Parser
7
+
8
+ The AsyncAPI Parser is a package used to parse and validate the [AsyncAPI documents](asyncapi-document.md) in your Node.js or browser application. These documents can be either in YAML or JSON format.
9
+
10
+ The Parser validates these documents using dedicated schema-supported plugins.
11
+
12
+ Supported schemas:
13
+
14
+ - AsyncAPI schema (no plugin needed)
15
+ - OpenAPI schema
16
+ - JSON schema
17
+ - Avro schema
18
+ - RAML data-type schema
19
+
20
+ The Parser allows the template developer to easily access schemas provided in the above supported formats. This is because the JavaScript parser converts all of them into JSON schema.
21
+
22
+ If the document is valid, the Parser returns an `AsyncAPIDocument instance` with a set of helper functions that enable easier access to the contents of the AsyncAPI document. The parser provides dereferenced output. During the dereference process, the AsyncAPI parser substitutes a reference with a full definition. The dereferenced output is always in JSON format. The parser provides a message listing all errors if a document is invalid. The original AsyncAPI document is part of the [Template Context](template-context.md) as the generator also passes the original AsyncAPI document to the template context.
23
+
24
+ The following AsyncAPI document example has two channels: `channelOne` and `channelTwo`. Each channel has one operation and a single message:
25
+
26
+ ```yaml
27
+ asyncapi: '2.5.0'
28
+ info:
29
+ title: Demo API
30
+ version: '1.0.0'
31
+ channels:
32
+ channelOne:
33
+ publish:
34
+ summary: This is the first sample channel
35
+ operationId: onMessage
36
+ message:
37
+ name: FirstMessage
38
+ payload:
39
+ id:
40
+ type: integer
41
+ minimum: 0
42
+ description: Id of the channel
43
+ sentAt:
44
+ type: string
45
+ format: date-time
46
+ description: Date and time when the message was sent.
47
+ channelTwo:
48
+ publish:
49
+ summary: This is the second sample channel
50
+ operationId: messageRead
51
+ message:
52
+ name: SecondMessage
53
+ payload:
54
+ id:
55
+ type: integer
56
+ minimum: 0
57
+ description: Id of the channel
58
+ sentAt:
59
+ type: string
60
+ format: date-time
61
+ description: Date and time when the message was sent.
62
+ ```
63
+ We can use helper functions provided by the Parser to operate on the above JSON file. For example, we can use the helper method `asyncAPIDocument.channelNames()`, which returns an array of all channel names currently present in the AsyncAPI document. Another example where you can use a helper function is to list out messages present in your JSON file. Instead of fetching a single message one at a time, you can use the function `asyncAPIDocument.allMessages()` that returns the map of all messages in your AsyncAPI document.
64
+
65
+ ```js
66
+ const channelNames = asyncAPIDocument.channelNames();
67
+ const messages = asyncAPIDocument.allMessages();
68
+ ```
69
+
70
+ > The Parser gives you access to a number of these [helper functions](https://github.com/asyncapi/parser-js/blob/master/API.md) that you can implement to access the contents of your AsyncAPI document.
71
+
72
+ ## AsyncAPI document validation process
73
+
74
+ 1. **AsyncAPI document** is fed as an input to the Generator.
75
+ 1. Generator sends the AsyncAPI document to the Parser as **asyncapiString**; the stringified version of the original AsyncAPI document.
76
+ 1. The Parser uses additional plugins such as the OpenAPI, RAML, or Avro schemas to validate custom schemas of message payloads defined in the AsyncAPI document.
77
+ 1. If the AsyncAPI document is invalid, it throws an error based on the encountered failure type. For example, if the AsyncAPI document is not a string nor a JavaScript object, the Parser throws an `invalid-document-type` error.
78
+ Similarly, you may encounter errors such as:
79
+ - `invalid-json`
80
+ - `invalid-yaml`
81
+ - `impossible-to-convert-to-json`
82
+ 1. If the document is valid, the Parser modifies the AsyncAPI document, returns a set of helper functions, and bundles them together into the **asyncapi** variable. These helper functions in the form of an **asyncapi** variable are passed to the **Template Context**.
83
+ 1. The Template Context passes all of these values to the [**Render Engine**](react-render-engine.md) of your choice. Finally, the Render Engine generates whatever output you may have specified in your template. (i.e. code, documentation, diagrams, pdfs, applications, etc.)
84
+
85
+ ```mermaid
86
+ graph TD
87
+ A[AsyncAPI document] --> B
88
+ B[Generator] -->|asyncapiString| C(Parser)
89
+ C --> D{Validation}
90
+ D -->|invalid| B
91
+ D -->|asyncapi -> helper functions| E[Template Context]
92
+ E --> F[Render Engine]
93
+ ```
94
+
95
+ > To learn more about the Parser and access all of its features, check out the AsyncAPI [Parser’s GitHub repository](https://github.com/asyncapi/parser-js).
96
+
@@ -1,6 +1,6 @@
1
1
  ---
2
- title: "React Render Engine"
3
- weight: 60
2
+ title: "React render engine"
3
+ weight: 110
4
4
  ---
5
5
 
6
6
  [React](https://reactjs.org) is the render engine that we strongly suggest you should use for any new templates. The only reason it is not the default render engine is to stay backward compatible.
@@ -31,7 +31,7 @@ export default function({ asyncapi, params, originalAsyncAPI }) {
31
31
  }
32
32
  ```
33
33
 
34
- The exported default function returns a `File` component as a root component which the [Generator](https://github.com/asyncapi/generator) uses to figure out what file should be generated. In our case we overwrite the default functionality of saving the file as `MyTemplate.js` but instead use the filename `asyncapi.md`. It is then specified that we should render `Some text that should render as is\n` within that file. Notice the `\n` character at the end, this is something that is automatically added after the `Text` component.
34
+ The exported default function returns a `File` component as a root component which the generator uses to determine what file should be generated. In our case, we overwrite the default functionality of saving the file as `MyTemplate.js` but instead use the filename `asyncapi.md`. It is then specified that we should render `Some text that should render as is\n` within that file. Notice the `\n` character at the end, which is automatically added after the `Text` component.
35
35
 
36
36
  For further information about components, props etc. see the [Generator React SDK](https://github.com/asyncapi/generator-react-sdk)
37
37
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: "Special file names"
3
- weight: 130
3
+ weight: 160
4
4
  ---
5
5
 
6
6
  We use NPM behind the scenes to download and install the templates. Since NPM will not fetch files like `.gitignore`, you should name them differently. Luckily, the Generator will take care of renaming them back for you. The following is a table of the special file names:
@@ -0,0 +1,41 @@
1
+ ---
2
+ title: "Template context"
3
+ weight: 100
4
+ ---
5
+
6
+ While using the generator tool, you may want dynamic values populated to your templates and rendered in the output. The generator can achieve that using the **template context**.
7
+ The **template context** allows you to access the contents of the [AsyncAPI document](asyncapi-document.md) and inject dynamic values to the template files passed to the asyncAPI CLI during the generation process. The render engine then displays these dynamically assigned values in the output.
8
+
9
+ ## Generation process
10
+ 1. The **Generator** receives **Template** and **params** as input.
11
+ 2. The **Generator** sends to the **Parser** the **asyncapiString** which is a stringified version of the original **AsyncAPI document**.
12
+ 3. The **Parser** validates the format of the **asyncapiString** using OpenAPI, RAML, or Avro schemas.
13
+ 4. If the **asyncapiString** is valid, the **parser** manipulates it, returns a set of helper functions and properties, and bundles them into an **asyncapi** variable. The **asyncapi** variable is an instance of the **AsyncAPI document**. The helper functions and properties make it easier to access the contents of the **AsyncAPI document** in the template.
14
+ 5. The **Generator** then passes the **params**, which are template-specific options used to customize the output, the **Template files**, and the **asyncapi** which collectively make up the **Template Context**.
15
+ 6. The **Template Context** is then passed to the **Render Engine**. The **Render Engine** then injects all the dynamic values from the **Template Context** into the **Template files**.
16
+
17
+ ``` mermaid
18
+ graph LR
19
+ A[Template Context]
20
+ B{Generator}
21
+ C[Parser]
22
+ D[Render Engine]
23
+ E[Template] --> B
24
+ F[Params] --> B
25
+ G[AsyncAPI Document] --> B
26
+ subgraph Generator
27
+ B -->| params | A
28
+ B--> | asyncapiString| C
29
+ B -->| originalAsyncAPI | A
30
+ C --> | asyncapi -> AsyncAPIDocument type | A
31
+ B--> | Template Files | D
32
+ A --> D
33
+ end
34
+ ```
35
+
36
+ ## Template context
37
+ The extra context passed to the render engine during the generation process and made accessible in the templates includes:
38
+
39
+ - **`originalAsyncAPI`** is a stringified version of the original AsyncAPI document that the user passed to the Generator.
40
+ - **`asyncapi`** is a parsed AsyncAPI document with helper functions and properties. You should use it to access document contents e.g `asyncapi.title`.
41
+ - **`params`** is an object with all the parameters passed to the Generator by the user.
@@ -0,0 +1,153 @@
1
+ ---
2
+ title: "Template development"
3
+ weight: 80
4
+ ---
5
+
6
+ ## Minimum template requirements
7
+
8
+ Let's break down the minimum template requirements: the `template` directory and a `package.json` file.
9
+
10
+ > You can also check [Template for Generator Templates](https://github.com/asyncapi/template-for-generator-templates) project to see show-case template based on the AsyncAPI Generator.
11
+
12
+ ### `template` directory
13
+
14
+ The `template` directory stores generated outputs in files. In other words, the generator processes all the files stored in this directory.
15
+
16
+ ```js
17
+ import { File, Text } from "@asyncapi/generator-react-sdk";
18
+
19
+ export default function({ asyncapi, params, originalAsyncAPI }) {
20
+ return (
21
+ <File name="asyncapi.md">
22
+ <Text>My application's markdown file.</Text>
23
+ <Text>App name: **{ asyncapi.info().title() }**</Text>
24
+ </File>
25
+ );
26
+ }
27
+ ```
28
+ ### `package.json` file
29
+
30
+ Before the generation process begins, the generator installs the template into its dependencies. A `package.json` file is necessary to identify the template name.
31
+
32
+ The following block shows an example `package.json` file that points to the [React Render Engine](react-render-engine.md) and necessary dependencies:
33
+
34
+ ```json
35
+ {
36
+ "name": "myTemplate",
37
+ "generator": {
38
+ "renderer": "react"
39
+ },
40
+ "dependencies": {
41
+ "@asyncapi/generator-react-sdk": "^0.2.25"
42
+ }
43
+ }
44
+ ```
45
+
46
+ The above example of a `template/index.js` file shows the generation process result. The user also receives an `asyncapi.md` file with hardcoded and dynamic (application title from the AsyncAPI document) information.
47
+
48
+ Every template must depend on the [`@asyncapi/generator-react-sdk` package](https://github.com/asyncapi/generator-react-sdk), which contains a template file's basic components.
49
+
50
+ ## Additional configuration options
51
+
52
+ You must configure the generator's `package.json` file to contain JSON objects with the required parameters for template configuration, such as:
53
+
54
+ |Name|Type|Description|
55
+ |---|---|---|
56
+ |`renderer`| String | Its value can be either `react` or `nunjucks` (default).
57
+ |`supportedProtocols`| [String] | A list with all the protocols this template supports.
58
+ |`parameters`| Object[String, Object] | An object with all the parameters that can be passed when generating the template. When using the command line, it's done by indicating `--param name=value` or `-p name=value`.
59
+ |`parameters[param].description`| String | A user-friendly description about the parameter.
60
+ |`parameters[param].default`| Any | Default value of the parameter if not specified. Shouldn't be used for mandatory `required=true` parameters.
61
+ |`parameters[param].required`| Boolean | Whether the parameter is required or not.
62
+
63
+ The above table lists some configuration options that help the generator achieve a specific set of tasks throughout the generation process. The `generator` property from 'package.json' contains all the configuration information. To learn more about template configuration and various supported parameters, read the [generator configuration file](configuration-file.md).
64
+
65
+ > Whenever you make a change to the package.json, make sure you perform an update by running `npm install`; this command synchronizes with the `package-lock.json` and validates the file.
66
+
67
+ ### `package.json` configuration options
68
+
69
+ The following examples show some advanced configurations that we can use in our `package.json` file:
70
+
71
+ ```json
72
+ {
73
+ "name": "myTemplate",
74
+ "generator": {
75
+ "renderer": "react",
76
+ "supportedProtocols": "mqtt"
77
+ },
78
+ "dependencies": {
79
+ "@asyncapi/generator-react-sdk": "^0.2.25"
80
+ }
81
+ }
82
+ ```
83
+ The above `package.json` file has a newly added configuration called `supportedProtocols` which is set to `mqtt`. This configuration displays all the protocols that this template supports. You can have multiple supported protocols in our template.
84
+
85
+ For example, if you want to generate an output using the above template, you need to have an AsyncAPI document with servers that use `mqtt` to generate your desired output. If your AsyncAPI document has server connections with `kafka`, the generation process will be terminated since the only supported protocol mentioned is `mqtt`.
86
+
87
+ ### Accessing template parameters
88
+
89
+ Additionally, we can also have a configuration called `parameters`, which is an object with all the parameters that can be passed when generating the template:
90
+
91
+ ```json
92
+ {
93
+ "name": "myTemplate",
94
+ "generator": {
95
+ "renderer": "react",
96
+ "supportedProtocols": "mqtt",
97
+ "parameters": {
98
+ "version": {
99
+ "description": "Overrides application version under `info.version` in the AsyncAPI document.",
100
+ "required": false
101
+ }
102
+ }
103
+ },
104
+ "dependencies": {
105
+ "@asyncapi/generator-react-sdk": "^0.2.25"
106
+ }
107
+ }
108
+ ```
109
+
110
+ The default version of your application is always fetched from your AsyncAPI document. The above configuration helps the template user override the existing version with a new one on the command line.
111
+
112
+ The changes done in the template will be as follows:
113
+
114
+ Original:
115
+
116
+ ```js
117
+ <Text>App name: **{ asyncapi.info().title() }**</Text>
118
+ ```
119
+
120
+ Newer:
121
+
122
+ ```js
123
+ <Text>App name: **{ asyncapi.info().title() }**</Text>
124
+ <Text>Version is: **{params.version || asyncapi.info.version()}**</Text>
125
+ ```
126
+
127
+ Now that you have added all the configuration options, you can start the generation process using the generator CLI. You can pass these parameters via the CLI: `--param name=value or -p name=value`.
128
+ The above configuration helps template users override the existing version with a new version on the command line. (Example: `-p version=2.0.0`)
129
+
130
+ ## Hooks
131
+
132
+ [Hooks](hooks.md) enable templates to perform multiple tasks. You can add Hooks to your template as fractions of code. In the template, you must store it in the `hooks` directory under the template directory. You can also store it in other modules and external libraries or configure it inside the template. The generation process can perform multiple actions.
133
+
134
+ **Templates** can perform multiple actions _before_ or _after_ the generation process with the help of **hooks**.
135
+
136
+ Hooks help you change the specification version with the new `version` that you can pass before the generation process even begins:
137
+
138
+ ```js
139
+ module.exports = {
140
+ 'generate:before': ({ asyncapi, templateParams = {} }) => {
141
+ const version = templateParams.version || asyncapi.info().version();
142
+ asyncapi._json.info.version = version;
143
+ }
144
+ };
145
+ ```
146
+ This can be an even better alternative to overriding the `version` parameter we discussed in the previous section. A markdown document will be generated, and the AsyncAPI document passed to the generator will be returned with the overwritten version.
147
+
148
+ The updated template looks like the following:
149
+
150
+ ```js
151
+ <Text>App name: **{ asyncapi.info().title() }**</Text>
152
+ <Text>Version: **{asyncapi.info.version()}**</Text>
153
+ ```
package/docs/template.md CHANGED
@@ -1,6 +1,73 @@
1
1
  ---
2
2
  title: "Template"
3
- weight: 40
3
+ weight: 50
4
4
  ---
5
5
 
6
- >This document is under construction.
6
+ ## Template
7
+
8
+ A template is a project that specifies the generation process output by using the AsyncAPI generator and an [AsyncAPI document](asyncapi-file.md). These files describe the generation results depending on the AsyncAPI document's content.
9
+
10
+ Examples outputs:
11
+
12
+ - Code
13
+ - Documentation
14
+ - Markdown diagrams
15
+ - Python and Java applications
16
+
17
+ A template is an independent Node.js project unrelated to the `generator` repository. AsyncAPI templates are managed, released, and published separately. You can also create templates and manage templates on your own.
18
+
19
+ The generator uses the official [Arborist](https://www.npmjs.com/package/@npmcli/arborist) NPM library. (This means templates do not have to be published to package managers to use them.) Arborist helps the generator fetch the template's source code and use it for the generation process.
20
+
21
+ You can store template projects on a local drive or as a `git` repository during the development process.
22
+
23
+ ## Template generation process
24
+
25
+ 1. Template is provided as input to the **Generator**.
26
+ 2. **asyncapi** is the original AsyncAPI document injected into your template file by default.
27
+ 3. **params** are the parameters you pass to the generator CLI. Later, you can also pass these **params** further to other components.
28
+ 4. The generator passes both the original **asyncapi**, the original AsyncAPI document, and the **params** to the **Template Context**.
29
+ 5. Concurrently, the generator passes **Template files** to the **Render engine** as well. AsyncAPI uses two render engines — _react_ and _nunjucks_.
30
+ 6. Once the Render Engine receives both the Template Files and the Template Context, it injects all the dynamic values into your react or nunjucks engine, based on the Template Files using the Template Context.
31
+ 7. The render engine generates whatever output you may have specified in your template. (i.e. code, documentation, diagrams, pdfs, applications, etc.)
32
+
33
+ ```mermaid
34
+ graph LR
35
+ A[Template Context]
36
+ B{Generator}
37
+ D[Render Engine]
38
+ F[Template] --> B
39
+ subgraph Generator Library
40
+ B --> | asyncapi | A
41
+ B--> | params | A
42
+ A --> D
43
+ B --> | Template Files | D
44
+ end
45
+ ```
46
+
47
+ ## Generator `templates` list
48
+
49
+ AsyncAPI has a list of available templates to enhance your generation process. Templates are stored as repositories on AsyncAPI's official GitHub profile.
50
+
51
+ <!-- templates list is validated with GitHub Actions do not remove list markers -->
52
+ <!-- TEMPLATES-LIST:START -->
53
+
54
+ Template Name | Description | Source code
55
+ ---|---|---
56
+ `@asyncapi/nodejs-template` | Generates Node.js service that uses Hermes package | [Nodej.s template](https://github.com/asyncapi/nodejs-template)
57
+ `@asyncapi/nodejs-ws-template` | Generates Node.js service that supports WebSocket protocol only | [Node.js WebSocket template](https://github.com/asyncapi/nodejs-ws-template)
58
+ `@asyncapi/java-template` | Generates Java JMS application | [Java template](https://github.com/asyncapi/java-template)
59
+ `@asyncapi/java-spring-template` | Generates Java Spring service | [Java spring template](https://github.com/asyncapi/java-spring-template)
60
+ `@asyncapi/java-spring-cloud-stream-template` | Generates Java Spring Cloud Stream service | [Java spring cloud stream template](https://github.com/asyncapi/java-spring-cloud-stream-template)
61
+ `@asyncapi/python-paho-template` | Generates Python service that uses Paho library | [Python paho template](https://github.com/asyncapi/python-paho-template)
62
+ `@asyncapi/html-template` | Generates HTML documentation site | [HTML template](https://github.com/asyncapi/html-template)
63
+ `@asyncapi/markdown-template` | Generates documentation in Markdown file | [Markdown template](https://github.com/asyncapi/markdown-template)
64
+ `@asyncapi/ts-nats-template` | Generates TypeScript NATS client | [TypeScript/Node.js NATS template](https://github.com/asyncapi/ts-nats-template/)
65
+ `@asyncapi/go-watermill-template` | Generates Go client using Watermill | [GO watermill template](https://github.com/asyncapi/go-watermill-template)
66
+ `@asyncapi/dotnet-nats-template` | Generates .NET C# client using NATS | [.NET C# NATS template](https://github.com/asyncapi/dotnet-nats-template)
67
+
68
+ <!-- TEMPLATES-LIST:END -->
69
+
70
+ > Some of these templates are maintained by various third-party organizations. The README file usually contains this information and more, such as configuration options the user can pass to the template, usage, technical requirements, etc.
71
+
72
+ > Check out all our community [generator templates](https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate)
73
+
@@ -1,6 +1,6 @@
1
1
  ---
2
- title: "TypeScript Support"
3
- weight: 120
2
+ title: "TypeScript support"
3
+ weight: 150
4
4
  ---
5
5
 
6
6
  The AsyncAPI generator has TypeScript support for [hooks](#hooks) and Nunjucks's [filters](#filters). Assumptions: