@asyncapi/generator 1.9.14 → 1.9.16
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.
- package/CODEOWNERS +3 -0
- package/README.md +5 -3
- package/docs/README.md +6 -6
- package/docs/api.md +122 -100
- package/docs/asyncapi-document.md +1 -1
- package/docs/configuration-file.md +2 -2
- package/docs/file-templates.md +1 -1
- package/docs/hooks.md +1 -1
- package/docs/index.md +2 -2
- package/docs/jsdoc2md-handlebars/custom-sig-name.hbs +12 -0
- package/docs/jsdoc2md-handlebars/defaultvalue.hbs +1 -0
- package/docs/jsdoc2md-handlebars/header.hbs +12 -0
- package/docs/jsdoc2md-handlebars/link.hbs +25 -0
- package/docs/jsdoc2md-handlebars/main.hbs +8 -0
- package/docs/jsdoc2md-handlebars/params-table.hbs +9 -0
- package/docs/nunjucks-render-engine.md +1 -1
- package/docs/parser.md +92 -2
- package/docs/react-render-engine.md +2 -2
- package/docs/special-file-names.md +1 -1
- package/docs/template-context.md +1 -1
- package/docs/template-development.md +153 -0
- package/docs/template.md +69 -2
- package/docs/typescript-support.md +1 -1
- package/docs/usage.md +1 -1
- package/docs/versioning.md +1 -1
- package/lib/generator.js +2 -2
- package/package.json +3 -3
- package/.releaserc +0 -10
- package/docs/authoring-templates.md +0 -17
package/CODEOWNERS
CHANGED
package/README.md
CHANGED
|
@@ -64,15 +64,15 @@ Install both packages using [official installer](https://nodejs.org/en/download/
|
|
|
64
64
|
## Using from the command-line interface (CLI)
|
|
65
65
|
|
|
66
66
|
### CLI installation
|
|
67
|
-
Learn to install the AsyncAPI CLI from the [installation guide](installation-guide.md).
|
|
67
|
+
Learn to install the AsyncAPI CLI from the [installation guide](docs/installation-guide.md).
|
|
68
68
|
|
|
69
69
|
### CLI usage
|
|
70
70
|
|
|
71
|
-
Learn more about different ways of using the CLI from the [usage document](usage.md).
|
|
71
|
+
Learn more about different ways of using the CLI from the [usage document](docs/usage.md).
|
|
72
72
|
|
|
73
73
|
## Generator version vs Template version
|
|
74
74
|
|
|
75
|
-
Learn more about versioning from the [versioning document](versioning.md).
|
|
75
|
+
Learn more about versioning from the [versioning document](docs/versioning.md).
|
|
76
76
|
|
|
77
77
|
## How to create a template
|
|
78
78
|
|
|
@@ -109,6 +109,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
109
109
|
</tr>
|
|
110
110
|
<tr>
|
|
111
111
|
<td align="center"><a href="https://github.com/lkmandy"><img src="https://avatars.githubusercontent.com/u/17765231?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Amanda Shafack </b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=lkmandy" title="Documentation">📖</a></td>
|
|
112
|
+
<td align="center"><a href="https://github.com/Florence-Njeri"><img src="https://avatars.githubusercontent.com/u/40742916?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Florence Njeri</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=Florence-Njeri" title="Documentation">📖</a> <a href="https://github.com/asyncapi/generator/pulls?q=is%3Apr+reviewed-by%3AFlorence-Njeri" title="Reviewed Pull Requests">👀</a> <a href="#infra-Florence-Njeri" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-Florence-Njeri" title="Maintenance">🚧</a></td>
|
|
113
|
+
<td align="center"><a href="https://unruffled-goodall-dd424e.netlify.app/"><img src="https://avatars.githubusercontent.com/u/77961530?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pratik Haldankar</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=pratik2315" title="Documentation">📖</a> <a href="https://github.com/asyncapi/generator/pulls?q=is%3Apr+reviewed-by%3Apratik2315" title="Reviewed Pull Requests">👀</a> <a href="#maintenance-pratik2315" title="Maintenance">🚧</a> <a href="#talk-pratik2315" title="Talks">📢</a></td>
|
|
112
114
|
</tr>
|
|
113
115
|
</table>
|
|
114
116
|
|
package/docs/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
Table of Contents
|
|
2
2
|
|
|
3
3
|
- [Introduction](index.md)
|
|
4
|
-
- [AsyncAPI document](asyncapi-document.md)
|
|
5
4
|
- [Installation Guide](installation-guide.md)
|
|
6
5
|
- [Usage](usage.md)
|
|
7
|
-
- [
|
|
8
|
-
- [
|
|
9
|
-
- [
|
|
6
|
+
- [AsyncAPI document](asyncapi-document.md)
|
|
7
|
+
- [Template](template.md)
|
|
8
|
+
- [Parser](parser.md)
|
|
10
9
|
- [Generator version vs template version](versioning.md)
|
|
10
|
+
- [Template Development](template-development.md)
|
|
11
|
+
- [Configuration File](configuration-file.md)
|
|
12
|
+
- [Template context](template-context.md)
|
|
11
13
|
- [React render engine](react-render-engine.md)
|
|
12
14
|
- [Nunjucks render engine](nunjucks-render-engine.md)
|
|
13
|
-
- [Template context](template-context.md)
|
|
14
|
-
- [Parser](parser.md)
|
|
15
15
|
- [Hooks](hooks.md)
|
|
16
16
|
- [File templates](file-templates.md)
|
|
17
17
|
- [TypeScript support](typescript-support.md)
|
package/docs/api.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Library API
|
|
3
|
+
weight: 75
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Reference API documentation for AsyncAPI Generator library.
|
|
7
|
+
|
|
1
8
|
<a name="Generator"></a>
|
|
2
9
|
|
|
3
10
|
## Generator
|
|
@@ -6,49 +13,49 @@
|
|
|
6
13
|
* [Generator](#Generator)
|
|
7
14
|
* [new Generator(templateName, targetDir, options)](#new_Generator_new)
|
|
8
15
|
* _instance_
|
|
9
|
-
* [.templateName](#Generator+templateName) :
|
|
10
|
-
* [.targetDir](#Generator+targetDir) :
|
|
11
|
-
* [.entrypoint](#Generator+entrypoint) :
|
|
12
|
-
* [.noOverwriteGlobs](#Generator+noOverwriteGlobs) :
|
|
13
|
-
* [.disabledHooks](#Generator+disabledHooks) :
|
|
14
|
-
* [.output](#Generator+output) :
|
|
15
|
-
* [.forceWrite](#Generator+forceWrite) :
|
|
16
|
-
* [.debug](#Generator+debug) :
|
|
17
|
-
* [.install](#Generator+install) :
|
|
18
|
-
* [.templateConfig](#Generator+templateConfig) :
|
|
19
|
-
* [.hooks](#Generator+hooks) :
|
|
20
|
-
* [.mapBaseUrlToFolder](#Generator+mapBaseUrlToFolder) :
|
|
21
|
-
* [.templateParams](#Generator+templateParams) :
|
|
22
|
-
* [.originalAsyncAPI](#Generator+originalAsyncAPI) :
|
|
23
|
-
* [.generate(asyncapiDocument)](#Generator+generate) ⇒
|
|
16
|
+
* [.templateName](#Generator+templateName) : `String`
|
|
17
|
+
* [.targetDir](#Generator+targetDir) : `String`
|
|
18
|
+
* [.entrypoint](#Generator+entrypoint) : `String`
|
|
19
|
+
* [.noOverwriteGlobs](#Generator+noOverwriteGlobs) : `Array.<String>`
|
|
20
|
+
* [.disabledHooks](#Generator+disabledHooks) : `Object.<String, (Boolean|String|Array.<String>)>`
|
|
21
|
+
* [.output](#Generator+output) : `String`
|
|
22
|
+
* [.forceWrite](#Generator+forceWrite) : `Boolean`
|
|
23
|
+
* [.debug](#Generator+debug) : `Boolean`
|
|
24
|
+
* [.install](#Generator+install) : `Boolean`
|
|
25
|
+
* [.templateConfig](#Generator+templateConfig) : `Object`
|
|
26
|
+
* [.hooks](#Generator+hooks) : `Object`
|
|
27
|
+
* [.mapBaseUrlToFolder](#Generator+mapBaseUrlToFolder) : `Object`
|
|
28
|
+
* [.templateParams](#Generator+templateParams) : `Object`
|
|
29
|
+
* [.originalAsyncAPI](#Generator+originalAsyncAPI) : `String`
|
|
30
|
+
* [.generate(asyncapiDocument)](#Generator+generate) ⇒ `Promise`
|
|
24
31
|
* [.configureTemplate()](#Generator+configureTemplate)
|
|
25
|
-
* [.generateFromString(asyncapiString, [parserOptions])](#Generator+generateFromString) ⇒
|
|
26
|
-
* [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒
|
|
27
|
-
* [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒
|
|
32
|
+
* [.generateFromString(asyncapiString, [parserOptions])](#Generator+generateFromString) ⇒ `Promise`
|
|
33
|
+
* [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒ `Promise`
|
|
34
|
+
* [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒ `Promise`
|
|
28
35
|
* [.installTemplate([force])](#Generator+installTemplate)
|
|
29
36
|
* _static_
|
|
30
|
-
* [.getTemplateFile(templateName, filePath, [templatesDir])](#Generator.getTemplateFile) ⇒
|
|
37
|
+
* [.getTemplateFile(templateName, filePath, [templatesDir])](#Generator.getTemplateFile) ⇒ `Promise`
|
|
38
|
+
|
|
31
39
|
|
|
32
40
|
<a name="new_Generator_new"></a>
|
|
33
41
|
|
|
34
|
-
### new Generator
|
|
42
|
+
### new Generator
|
|
35
43
|
Instantiates a new Generator object.
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| [options.mapBaseUrlToFolder] | <code>Object.<String, String></code> | | Optional parameter to map schema references from a base url to a local base folder e.g. url=https://schema.example.com/crm/ folder=./test/docs/ . |
|
|
45
|
+
**Params**
|
|
46
|
+
|
|
47
|
+
- templateName `String` - Name of the template to generate.
|
|
48
|
+
- targetDir `String` - Path to the directory where the files will be generated.
|
|
49
|
+
- options `Object`
|
|
50
|
+
- [.templateParams] `String` - Optional parameters to pass to the template. Each template define their own params.
|
|
51
|
+
- [.entrypoint] `String` - Name of the file to use as the entry point for the rendering process. Use in case you want to use only a specific template file. Note: this potentially avoids rendering every file in the template.
|
|
52
|
+
- [.noOverwriteGlobs] `Array.<String>` - List of globs to skip when regenerating the template.
|
|
53
|
+
- [.disabledHooks] `Object.<String, (Boolean|String|Array.<String>)>` - Object with hooks to disable. The key is a hook type. If key has "true" value, then the generator skips all hooks from the given type. If the value associated with a key is a string with the name of a single hook, then the generator skips only this single hook name. If the value associated with a key is an array of strings, then the generator skips only hooks from the array.
|
|
54
|
+
- [.output] `String` ` = 'fs'` - Type of output. Can be either 'fs' (default) or 'string'. Only available when entrypoint is set.
|
|
55
|
+
- [.forceWrite] `Boolean` ` = false` - Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir. Default is set to false.
|
|
56
|
+
- [.install] `Boolean` ` = false` - Install the template and its dependencies, even when the template has already been installed.
|
|
57
|
+
- [.debug] `Boolean` ` = false` - Enable more specific errors in the console. At the moment it only shows specific errors about filters. Keep in mind that as a result errors about template are less descriptive.
|
|
58
|
+
- [.mapBaseUrlToFolder] `Object.<String, String>` - Optional parameter to map schema references from a base url to a local base folder e.g. url=https://schema.example.com/crm/ folder=./test/docs/ .
|
|
52
59
|
|
|
53
60
|
**Example**
|
|
54
61
|
```js
|
|
@@ -64,100 +71,114 @@ const generator = new Generator('@asyncapi/html-template', path.resolve(__dirnam
|
|
|
64
71
|
}
|
|
65
72
|
});
|
|
66
73
|
```
|
|
74
|
+
|
|
67
75
|
<a name="Generator+templateName"></a>
|
|
68
76
|
|
|
69
|
-
|
|
77
|
+
* generator.templateName : `String`** :
|
|
70
78
|
Name of the template to generate.
|
|
71
79
|
|
|
72
|
-
**Kind**: instance property of [
|
|
80
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
81
|
+
|
|
73
82
|
<a name="Generator+targetDir"></a>
|
|
74
83
|
|
|
75
|
-
|
|
84
|
+
* generator.targetDir : `String`** :
|
|
76
85
|
Path to the directory where the files will be generated.
|
|
77
86
|
|
|
78
|
-
**Kind**: instance property of [
|
|
87
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
88
|
+
|
|
79
89
|
<a name="Generator+entrypoint"></a>
|
|
80
90
|
|
|
81
|
-
|
|
91
|
+
* generator.entrypoint : `String`** :
|
|
82
92
|
Name of the file to use as the entry point for the rendering process. Use in case you want to use only a specific template file. Note: this potentially avoids rendering every file in the template.
|
|
83
93
|
|
|
84
|
-
**Kind**: instance property of [
|
|
94
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
95
|
+
|
|
85
96
|
<a name="Generator+noOverwriteGlobs"></a>
|
|
86
97
|
|
|
87
|
-
|
|
98
|
+
* generator.noOverwriteGlobs : `Array.<String>`** :
|
|
88
99
|
List of globs to skip when regenerating the template.
|
|
89
100
|
|
|
90
|
-
**Kind**: instance property of [
|
|
101
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
102
|
+
|
|
91
103
|
<a name="Generator+disabledHooks"></a>
|
|
92
104
|
|
|
93
|
-
|
|
105
|
+
* generator.disabledHooks : `Object.<String, (Boolean|String|Array.<String>)>`** :
|
|
94
106
|
Object with hooks to disable. The key is a hook type. If key has "true" value, then the generator skips all hooks from the given type. If the value associated with a key is a string with the name of a single hook, then the generator skips only this single hook name. If the value associated with a key is an array of strings, then the generator skips only hooks from the array.
|
|
95
107
|
|
|
96
|
-
**Kind**: instance property of [
|
|
108
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
109
|
+
|
|
97
110
|
<a name="Generator+output"></a>
|
|
98
111
|
|
|
99
|
-
|
|
112
|
+
* generator.output : `String`** :
|
|
100
113
|
Type of output. Can be either 'fs' (default) or 'string'. Only available when entrypoint is set.
|
|
101
114
|
|
|
102
|
-
**Kind**: instance property of [
|
|
115
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
116
|
+
|
|
103
117
|
<a name="Generator+forceWrite"></a>
|
|
104
118
|
|
|
105
|
-
|
|
119
|
+
* generator.forceWrite : `Boolean`** :
|
|
106
120
|
Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir. Default is set to false.
|
|
107
121
|
|
|
108
|
-
**Kind**: instance property of [
|
|
122
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
123
|
+
|
|
109
124
|
<a name="Generator+debug"></a>
|
|
110
125
|
|
|
111
|
-
|
|
126
|
+
* generator.debug : `Boolean`** :
|
|
112
127
|
Enable more specific errors in the console. At the moment it only shows specific errors about filters. Keep in mind that as a result errors about template are less descriptive.
|
|
113
128
|
|
|
114
|
-
**Kind**: instance property of [
|
|
129
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
130
|
+
|
|
115
131
|
<a name="Generator+install"></a>
|
|
116
132
|
|
|
117
|
-
|
|
133
|
+
* generator.install : `Boolean`** :
|
|
118
134
|
Install the template and its dependencies, even when the template has already been installed.
|
|
119
135
|
|
|
120
|
-
**Kind**: instance property of [
|
|
136
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
137
|
+
|
|
121
138
|
<a name="Generator+templateConfig"></a>
|
|
122
139
|
|
|
123
|
-
|
|
140
|
+
* generator.templateConfig : `Object`** :
|
|
124
141
|
The template configuration.
|
|
125
142
|
|
|
126
|
-
**Kind**: instance property of [
|
|
143
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
144
|
+
|
|
127
145
|
<a name="Generator+hooks"></a>
|
|
128
146
|
|
|
129
|
-
|
|
147
|
+
* generator.hooks : `Object`** :
|
|
130
148
|
Hooks object with hooks functions grouped by the hook type.
|
|
131
149
|
|
|
132
|
-
**Kind**: instance property of [
|
|
150
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
151
|
+
|
|
133
152
|
<a name="Generator+mapBaseUrlToFolder"></a>
|
|
134
153
|
|
|
135
|
-
|
|
154
|
+
* generator.mapBaseUrlToFolder : `Object`** :
|
|
136
155
|
Maps schema URL to folder.
|
|
137
156
|
|
|
138
|
-
**Kind**: instance property of [
|
|
157
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
158
|
+
|
|
139
159
|
<a name="Generator+templateParams"></a>
|
|
140
160
|
|
|
141
|
-
|
|
161
|
+
* generator.templateParams : `Object`** :
|
|
142
162
|
The template parameters. The structure for this object is based on each individual template.
|
|
143
163
|
|
|
144
|
-
**Kind**: instance property of [
|
|
164
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
165
|
+
|
|
145
166
|
<a name="Generator+originalAsyncAPI"></a>
|
|
146
167
|
|
|
147
|
-
|
|
168
|
+
* generator.originalAsyncAPI : `String`** :
|
|
148
169
|
AsyncAPI string to use as a source.
|
|
149
170
|
|
|
150
|
-
**Kind**: instance property of [
|
|
171
|
+
**Kind**: instance property of [`Generator`](#Generator)
|
|
172
|
+
|
|
151
173
|
<a name="Generator+generate"></a>
|
|
152
174
|
|
|
153
|
-
### generator.generate
|
|
175
|
+
### generator.generate
|
|
154
176
|
Generates files from a given template and an AsyncAPIDocument object.
|
|
155
177
|
|
|
156
|
-
**Kind**: instance method of [
|
|
178
|
+
**Kind**: instance method of [`Generator`](#Generator)
|
|
179
|
+
**Params**
|
|
157
180
|
|
|
158
|
-
|
|
159
|
-
| --- | --- | --- |
|
|
160
|
-
| asyncapiDocument | <code>AsyncAPIDocument</code> | AsyncAPIDocument object to use as source. |
|
|
181
|
+
- asyncapiDocument `AsyncAPIDocument` - AsyncAPIDocument object to use as source.
|
|
161
182
|
|
|
162
183
|
**Example**
|
|
163
184
|
```js
|
|
@@ -177,23 +198,24 @@ try {
|
|
|
177
198
|
console.error(e);
|
|
178
199
|
}
|
|
179
200
|
```
|
|
201
|
+
|
|
180
202
|
<a name="Generator+configureTemplate"></a>
|
|
181
203
|
|
|
182
|
-
|
|
204
|
+
* generator.configureTemplate()** :
|
|
183
205
|
Configure the templates based the desired renderer.
|
|
184
206
|
|
|
185
|
-
**Kind**: instance method of [
|
|
207
|
+
**Kind**: instance method of [`Generator`](#Generator)
|
|
208
|
+
|
|
186
209
|
<a name="Generator+generateFromString"></a>
|
|
187
210
|
|
|
188
|
-
### generator.generateFromString
|
|
211
|
+
### generator.generateFromString
|
|
189
212
|
Generates files from a given template and AsyncAPI string.
|
|
190
213
|
|
|
191
|
-
**Kind**: instance method of [
|
|
214
|
+
**Kind**: instance method of [`Generator`](#Generator)
|
|
215
|
+
**Params**
|
|
192
216
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
| asyncapiString | <code>String</code> | | AsyncAPI string to use as source. |
|
|
196
|
-
| [parserOptions] | <code>Object</code> | <code>{}</code> | AsyncAPI parser options. Check out [@asyncapi/parser](https://www.github.com/asyncapi/parser-js) for more information. |
|
|
217
|
+
- asyncapiString `String` - AsyncAPI string to use as source.
|
|
218
|
+
- [parserOptions] `Object` ` = {}` - AsyncAPI parser options. Check out [@asyncapi/parser](https://www.github.com/asyncapi/parser-js) for more information.
|
|
197
219
|
|
|
198
220
|
**Example**
|
|
199
221
|
```js
|
|
@@ -228,16 +250,16 @@ try {
|
|
|
228
250
|
console.error(e);
|
|
229
251
|
}
|
|
230
252
|
```
|
|
253
|
+
|
|
231
254
|
<a name="Generator+generateFromURL"></a>
|
|
232
255
|
|
|
233
|
-
### generator.generateFromURL
|
|
256
|
+
### generator.generateFromURL
|
|
234
257
|
Generates files from a given template and AsyncAPI file stored on external server.
|
|
235
258
|
|
|
236
|
-
**Kind**: instance method of [
|
|
259
|
+
**Kind**: instance method of [`Generator`](#Generator)
|
|
260
|
+
**Params**
|
|
237
261
|
|
|
238
|
-
|
|
239
|
-
| --- | --- | --- |
|
|
240
|
-
| asyncapiURL | <code>String</code> | Link to AsyncAPI file |
|
|
262
|
+
- asyncapiURL `String` - Link to AsyncAPI file
|
|
241
263
|
|
|
242
264
|
**Example**
|
|
243
265
|
```js
|
|
@@ -257,16 +279,16 @@ try {
|
|
|
257
279
|
console.error(e);
|
|
258
280
|
}
|
|
259
281
|
```
|
|
282
|
+
|
|
260
283
|
<a name="Generator+generateFromFile"></a>
|
|
261
284
|
|
|
262
|
-
### generator.generateFromFile
|
|
285
|
+
### generator.generateFromFile
|
|
263
286
|
Generates files from a given template and AsyncAPI file.
|
|
264
287
|
|
|
265
|
-
**Kind**: instance method of [
|
|
288
|
+
**Kind**: instance method of [`Generator`](#Generator)
|
|
289
|
+
**Params**
|
|
266
290
|
|
|
267
|
-
|
|
268
|
-
| --- | --- | --- |
|
|
269
|
-
| asyncapiFile | <code>String</code> | AsyncAPI file to use as source. |
|
|
291
|
+
- asyncapiFile `String` - AsyncAPI file to use as source.
|
|
270
292
|
|
|
271
293
|
**Example**
|
|
272
294
|
```js
|
|
@@ -286,37 +308,37 @@ try {
|
|
|
286
308
|
console.error(e);
|
|
287
309
|
}
|
|
288
310
|
```
|
|
311
|
+
|
|
289
312
|
<a name="Generator+installTemplate"></a>
|
|
290
313
|
|
|
291
|
-
### generator.installTemplate
|
|
314
|
+
### generator.installTemplate
|
|
292
315
|
Downloads and installs a template and its dependencies
|
|
293
316
|
|
|
294
|
-
**Kind**: instance method of [
|
|
317
|
+
**Kind**: instance method of [`Generator`](#Generator)
|
|
318
|
+
**Params**
|
|
319
|
+
|
|
320
|
+
- [force] `Boolean` ` = false` - Whether to force installation (and skip cache) or not.
|
|
295
321
|
|
|
296
|
-
| Param | Type | Default | Description |
|
|
297
|
-
| --- | --- | --- | --- |
|
|
298
|
-
| [force] | <code>Boolean</code> | <code>false</code> | Whether to force installation (and skip cache) or not. |
|
|
299
322
|
|
|
300
323
|
<a name="Generator.getTemplateFile"></a>
|
|
301
324
|
|
|
302
|
-
### Generator.getTemplateFile
|
|
325
|
+
### Generator.getTemplateFile
|
|
303
326
|
Returns the content of a given template file.
|
|
304
327
|
|
|
305
|
-
**Kind**: static method of [
|
|
328
|
+
**Kind**: static method of [`Generator`](#Generator)
|
|
329
|
+
**Params**
|
|
306
330
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
| filePath | <code>String</code> | | Path to the file to render. Relative to the template directory. |
|
|
311
|
-
| [templatesDir] | <code>String</code> | <code>DEFAULT_TEMPLATES_DIR</code> | Path to the directory where the templates are installed. |
|
|
331
|
+
- templateName `String` - Name of the template to generate.
|
|
332
|
+
- filePath `String` - Path to the file to render. Relative to the template directory.
|
|
333
|
+
- [templatesDir] `String` ` = DEFAULT_TEMPLATES_DIR` - Path to the directory where the templates are installed.
|
|
312
334
|
|
|
313
335
|
**Example**
|
|
314
336
|
```js
|
|
315
|
-
const Generator = require('asyncapi
|
|
337
|
+
const Generator = require('@asyncapi/generator');
|
|
316
338
|
const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html');
|
|
317
339
|
```
|
|
318
340
|
**Example** *(Using a custom `templatesDir`)*
|
|
319
341
|
```js
|
|
320
|
-
const Generator = require('asyncapi
|
|
342
|
+
const Generator = require('@asyncapi/generator');
|
|
321
343
|
const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html', '~/my-templates');
|
|
322
344
|
```
|
|
@@ -84,4 +84,4 @@ In the sample code snippet below, notice how you can access the contents of the
|
|
|
84
84
|
const channels = asyncapi.channels();
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
> To learn about the various instances you can use to access the documents' content, look at the API of the AsyncAPI JavaScript Parser and the structure of [AsyncAPIDocument](https://github.com/asyncapi/parser-js/blob/master/API.md#module_@asyncapi/parser+AsyncAPIDocument)
|
|
87
|
+
> To learn about the various instances you can use to access the documents' content, look at the API of the AsyncAPI JavaScript Parser and the structure of [AsyncAPIDocument](https://github.com/asyncapi/parser-js/blob/master/API.md#module_@asyncapi/parser+AsyncAPIDocument)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Configuration file"
|
|
3
|
-
weight:
|
|
3
|
+
weight: 90
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
The `generator` property from `package.json` file must contain a JSON object that may have the following information:
|
|
@@ -17,7 +17,7 @@ The `generator` property from `package.json` file must contain a JSON object tha
|
|
|
17
17
|
|`conditionalFiles[filePath].subject`| String | The `subject` is a [JMESPath](http://jmespath.org/) query to grab the value you want to apply the condition to. It queries an object with the whole AsyncAPI document and, when specified, the given server. The object looks like this: `{ asyncapi: { ... }, server: { ... } }`. If the template supports `server` parameter, you can access server details like for example protocol this way: `server.protocol`. During validation with `conditionalFiles` only the server that template user selected is available in the specification file. For more information about `server` parameter [read about special parameters](#special-parameters).
|
|
18
18
|
|`conditionalFiles[filePath].validation`| Object | The `validation` is a JSON Schema Draft 07 object. This JSON Schema definition will be applied to the JSON value resulting from the `subject` query. If validation doesn't have errors, the condition is met, and therefore the given file will be rendered. Otherwise, the file is ignored. Check [JSON Schema Validation](https://json-schema.org/draft-07/json-schema-validation.html#rfc.section.6) document for a list of all possible validation keywords.
|
|
19
19
|
|`nonRenderableFiles`| [String] | A list of file paths or [globs](https://en.wikipedia.org/wiki/Glob_(programming)) that must be copied "as-is" to the target directory, i.e., without performing any rendering process. This is useful when you want to copy binary files.
|
|
20
|
-
|`generator`| [String] | A string representing the
|
|
20
|
+
|`generator`| [String] | A string representing the generator version-range the template is compatible with. This value must follow the [semver](https://nodejs.dev/learn/semantic-versioning-using-npm) syntax. E.g., `>=1.0.0`, `>=1.0.0 <=2.0.0`, `~1.0.0`, `^1.0.0`, `1.0.0`, etc. [Read more about semver](https://docs.npmjs.com/about-semantic-versioning).
|
|
21
21
|
|`filters`| [String] | A list of modules containing functions that can be used as Nunjucks filters. In case of external modules, remember they need to be added as a dependency in `package.json` of your template.
|
|
22
22
|
|`hooks`| Object[String, String] or Object[String, Array[String]] | A list of modules containing hooks, except for the ones you keep locally in your template in default location. For each module you must specify the exact name of the hook that should be used in the template. For a single hook you can specify it as a string, for more you must pass an array of strings. In case of external modules, remember they need to be added as a dependency in `package.json` of your template.
|
|
23
23
|
|
package/docs/file-templates.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "File templates"
|
|
3
|
-
weight:
|
|
3
|
+
weight: 140
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
It is possible to generate files for each specific object in your AsyncAPI documentation. For example, you can specify a filename like `$$channel$$.js` to generate a file for each channel defined in your AsyncAPI. The following file-template names and extra variables in them are available:
|
package/docs/hooks.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Hooks"
|
|
3
|
-
weight:
|
|
3
|
+
weight: 130
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
Hooks are functions called by the generator on a specific moment in the generation process. Hooks can be anonymous functions but you can also add function names. These hooks can have arguments provided to them or being expected to return a value.
|
package/docs/index.md
CHANGED
|
@@ -3,7 +3,7 @@ title: "Introduction"
|
|
|
3
3
|
weight: 10
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
The AsyncAPI generator is a tool that generates anything you want using the **[AsyncAPI Document](generator/asyncapi-
|
|
6
|
+
The AsyncAPI generator is a tool that generates anything you want using the **[AsyncAPI Document](generator/asyncapi-document)** and **[Template](generator/template)** that are supplied as inputs to the AsyncAPI CLI. The generator was built with extensibility in mind; you can use the generator to generate anything you want, provided that it can be defined in a template, such as code, diagrams, markdown files, microservices, and applications. A number of [community-maintained templates](https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate) are now available for immediate usage.
|
|
7
7
|
|
|
8
8
|
### Generator use cases
|
|
9
9
|
- Generation of interactive and understandable API documentation
|
|
@@ -50,4 +50,4 @@ graph LR
|
|
|
50
50
|
D --> J[Java Spring Boot]
|
|
51
51
|
D --> K[Anything else]
|
|
52
52
|
```
|
|
53
|
-
**`params`** are template-specific options passed to the `asyncapi generate fromTemplate` CLI command to customize the generated output.
|
|
53
|
+
**`params`** are template-specific options passed to the `asyncapi generate fromTemplate` CLI command to customize the generated output.
|
|
@@ -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,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,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}}
|
package/docs/parser.md
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Parser"
|
|
3
|
-
weight:
|
|
3
|
+
weight: 60
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
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
2
|
title: "React render engine"
|
|
3
|
-
weight:
|
|
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
|
|
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:
|
|
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:
|
package/docs/template-context.md
CHANGED
|
@@ -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:
|
|
3
|
+
weight: 50
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
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
|
+
|
package/docs/usage.md
CHANGED
|
@@ -87,7 +87,7 @@ The generator skips all hooks of the `generate:before` type and `foo`, `bar` hoo
|
|
|
87
87
|
asyncapi generate fromTemplate asyncapi.yaml ~/my-template
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
It creates a symbolic link to the target directory (`~/my-template` in this case).
|
|
90
|
+
It creates a symbolic link to the target directory (`~/my-template` in this case).
|
|
91
91
|
|
|
92
92
|
**Installing the template from a git URL:**
|
|
93
93
|
```bash
|
package/docs/versioning.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Generator version vs template version"
|
|
3
|
-
weight:
|
|
3
|
+
weight: 70
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
The generator tool generates whatever you want, as long as it can be defined in a template based on the [AsyncAPI document](asyncapi-document). On the other hand, a **template** is a file or group of files that specify the kind of output you expect from using the generator's features. For example, you may want to use the [NodeJS template](https://github.com/asyncapi/nodejs-template) to generate boilerplate code for your message-based APIs.
|
package/lib/generator.js
CHANGED
|
@@ -334,11 +334,11 @@ class Generator {
|
|
|
334
334
|
* Returns the content of a given template file.
|
|
335
335
|
*
|
|
336
336
|
* @example
|
|
337
|
-
* const Generator = require('asyncapi
|
|
337
|
+
* const Generator = require('@asyncapi/generator');
|
|
338
338
|
* const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html');
|
|
339
339
|
*
|
|
340
340
|
* @example <caption>Using a custom `templatesDir`</caption>
|
|
341
|
-
* const Generator = require('asyncapi
|
|
341
|
+
* const Generator = require('@asyncapi/generator');
|
|
342
342
|
* const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html', '~/my-templates');
|
|
343
343
|
*
|
|
344
344
|
* @static
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/generator",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.16",
|
|
4
4
|
"description": "The AsyncAPI generator. It can generate documentation, code, anything!",
|
|
5
5
|
"main": "./lib/generator.js",
|
|
6
6
|
"bin": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test:integration": "npm run test:cleanup && jest --testPathPattern=integration --modulePathIgnorePatterns='./__mocks__'",
|
|
19
19
|
"test:cli": "node cli.js ./test/docs/dummy.yml @asyncapi/html-template -o test/output --force-write --debug && test -e test/output/index.html",
|
|
20
20
|
"test:cleanup": "rimraf \"test/temp\"",
|
|
21
|
-
"docs": "jsdoc2md lib/generator.js > docs/api.md",
|
|
21
|
+
"docs": "jsdoc2md --partial docs/jsdoc2md-handlebars/custom-sig-name.hbs docs/jsdoc2md-handlebars/main.hbs docs/jsdoc2md-handlebars/docs.hbs docs/jsdoc2md-handlebars/header.hbs docs/jsdoc2md-handlebars/defaultvalue.hbs docs/jsdoc2md-handlebars/link.hbs docs/jsdoc2md-handlebars/params-table.hbs --files lib/generator.js > docs/api.md",
|
|
22
22
|
"docker:build": "docker build -t asyncapi/generator:latest .",
|
|
23
23
|
"lint": "eslint --max-warnings 0 --config .eslintrc .",
|
|
24
24
|
"lint:tpl:validator": "eslint --fix --config .eslintrc .github/templates-list-validator",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@asyncapi/avro-schema-parser": "^1.1.0",
|
|
51
51
|
"@asyncapi/generator-react-sdk": "^0.2.23",
|
|
52
52
|
"@asyncapi/openapi-schema-parser": "^2.0.1",
|
|
53
|
-
"@asyncapi/parser": "^1.17.
|
|
53
|
+
"@asyncapi/parser": "^1.17.3",
|
|
54
54
|
"@asyncapi/raml-dt-schema-parser": "^2.0.1",
|
|
55
55
|
"@npmcli/arborist": "^2.2.4",
|
|
56
56
|
"ajv": "^6.10.2",
|
package/.releaserc
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Authoring templates"
|
|
3
|
-
weight: 50
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
The AsyncAPI generator has been built with extensibility in mind. The package uses a set of default templates to let you generate documentation and code. However, you can create and use your own templates. In this section, you learn how to create your own one.
|
|
7
|
-
|
|
8
|
-
To work on a template, you need an AsyncAPI specification file that you can use for testing. For this purpose, you can use [this](../test/docs/dummy.yml) dummy file as it's purpose is to cover as many features of AsyncAPI as possible. Do not copy this file to your template but use it directly from this repo like this: `ag https://raw.githubusercontent.com/asyncapi/generator/master/test/docs/dummy.yml ./your-template`
|
|
9
|
-
|
|
10
|
-
> In case you find some features missing or other possible improvements in the dummy file, suggest changes. The goal is to build a file that all templates can use and check their specification features coverage.
|
|
11
|
-
|
|
12
|
-
1. A template is a directory in your file system.
|
|
13
|
-
1. The template can have own dependencies. Just create `package.json` for the template. The generator makes sure to trigger the installation of dependencies.
|
|
14
|
-
1. Templates can be configured. Configuration must be stored in the `package.json` file under custom `generator` property. [Read more about the configuration file](#configuration-file).
|
|
15
|
-
1. The template engine can be either [React](#react) (recommended) or [Nunjucks](#nunjucks) (default). This can be controlled with the `renderer` property in the [template configuration](#template-configuration).
|
|
16
|
-
1. Templates may contain `hooks` that are functions invoked during specific moment of the generation. In the template, they must be stored in the `hooks` directory under the template directory. They can also be stored in other modules and external libraries and configured inside the template [Read more about hooks](#hooks).
|
|
17
|
-
1. There are parameters with special meaning. [Read more about special parameters](#special-parameters).
|